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.
1
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.