3

In my init.vim I have the following command:

nnoremap <Leader>s :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name")
  \ . "> fg<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg")
  \ . "> bg<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"bg") . ">"<CR>

For some reason though, the syntax shows up like this:

enter image description here

As you can see, the second line has no highlighting whatsoever. This happens every time I try to do something like this, and I don't know why. If I write the following:

nnoremap <Leader>s 
  \ :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name")  
  \ . "> fg<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg")
  \ . "> bg<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"bg") . ">"<CR>

It shows up like this:

enter image description here

Which is mostly correct, but if you look closely, the . in the first line has no highlighting, so it is still broken. How can I fix this?

More info:

  • I'm using Neovim 0.4.4-1.
  • This is all the text on my init.vim, the rest has been commented out.
  • Probably doesn't matter, but my terminal is kitty 0.18.3-1.
  • I've checked to see if there was any whitespace at the end of the lines, there is none.
user31224
  • 33
  • 2

1 Answers1

2

How can I fix this?

Stop bullying the syntax highlighter ;-)

:h g:vimsyn_noerror Vim script is a difficult language to highlight correctly.

Put your code into a dedicated function instead.

Matt
  • 20,685
  • 1
  • 11
  • 24