5

When I hit / in vim and search for $ it highlights all eols. But when I try to match them with syntax match it does not seem to work.

function! ConcealNonText()
    set conceallevel=1
    set concealcursor=v
    syntax match NonText /$/ conceal cchar=¶
endfunction

augroup ConcealNonText
    autocmd!
    autocmd VimEnter * call ConcealNonText()
augroup END

Any hints how I could match it in order to display eols as concealed chars? I know I could use set list listchars but that has some visual side effects in my opinion.

Community
  • 1
  • 1
Saucier
  • 4,200
  • 1
  • 25
  • 46

2 Answers2

1

Looks like your requirement is to show in place of the eol. Although the code you have given maybe a possible solution, but it surely is not an ideal one. Vim provides a much simpler way of achieving what you wish. What you really need to do is lookup :h listchars.

Following is an example of what you should put in your vimrc to achieve what you desire :

set list
set listchars+=eol:¶

Once you put this, vim will show the character for the eol character.

Dhruva Sagar
  • 7,089
  • 1
  • 25
  • 34
  • Thanks, but I know that already, see OP and the link provided which describes the problem with listchars. – Saucier Mar 28 '13 at 12:33
0

to do what you want, you can do matchadd() to match all end of lines. Matchadd will return an id that will help you delete that given match when you want.

:call matchadd("NonText", "$")

See :he matchadd() for more informations on how to use it.

HTH

zmo
  • 24,463
  • 4
  • 54
  • 90
  • As far as I know ```conceal``` can only be applied to ```syntax match```. So I guess it wouldn't work as expected? – Saucier Apr 16 '13 at 16:07
  • No, but you'd better use `set listchars+=eol:¶` with the matchadd, then you'll have all line endings with the `¶` character, but using a match, instead of the syntax, for the color. That's actually an option I'm considering for my own configuration, as I also regret having my eol character loosing its coloration attributes when under the cursorline. – zmo Apr 16 '13 at 22:13