0

When I edit a shell script with syntax highlighting enabled in vim, the moment I type opening " or ${ the editor immediately re-highlights the rest of the file as if it is a part of the string or variable name. Then when I type the closing " or } it re-highlights again. This leads to a lot of flashing.

Is it possible to disable this global live re-highlighting? For example, is there an option not to change any highlighting until I leave the insert mode? Or perhaps change the highlighting only for the lines that are affected by the new insert and keep the highlighting for the rest of lines until I end the edit?

1

This unfortunately isn't possible. In theory, syntax highlighting could add assertions to the definitions that say "only match this if the cursor is not inside", but as this would make regular expressions more cumbersome (and potentially also much slower), it isn't done.

You only can completely disable / enable syntax highlighting when entering / leaving insert mode, but that would create even more flashing (and potentially cause slowdown as the whole buffer would need to be re-parsed).

The only practical advice I can offer is to use an autoclose plugin (the automatically append closing characters Wiki page describes some simple setups and a list of plugins) that automatically closes any opened parenthesis and thereby mostly avoids the issue.

| improve this answer | |
  • Hm, does it mean that Vim does a full syntax highlighting on each keystroke without a delay? Other editors typically do highlighting after a delay not to re-highlight when the user writes the text and it is possible at least to set this delay via preferences. – Igor Bukanov Feb 1 '19 at 16:00
  • Yes, the syntax may adapt after each keystroke; and this is done synchronously. The scope that is considered is set by :syn sync – Ingo Karkat Feb 1 '19 at 22:28

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.