vimvim-syntax-highlightingmodeline

Vim bash syntax highlighting with modeline


According to much online documentation (e.g.), I should be able to enable bash syntax highlighting via modelines by adding a line like:

# vim:let g:is_bash=1:set filetype=sh:

And in .vimrc:

filetype plugin indent on
syntax on
set modeline
set modelines=4

Unfortunately, when I add those lines I receive an error message:

"packer/shunit2/include.sh" 85L, 2749C
Error detected while processing modelines:
line   85:
E518: Unknown option: let 

Where line 85 is of course the modeline from above. (And it is the last line in the file.)

Why does this not work despite so many pages suggesting that it should, and what does the error message mean, and how can I change this setup so that my bash scripts open with correct bash syntax highlighting?


Solution

  • No, that answer is wrong. You cannot define variables in a modeline, only (certain) options can be set there (for security reasons).

    To achieve bash syntax highlighting, you have the following options: