Grwlf
Grwlf

Reputation: 956

Why can't I change vim syntax highlighting via local vimrc file?

I am trying to customize vim highlighting by placing additional instructions into local config $project/.lvimrc, which is managed by the https://github.com/embear/vim-localvimrc plugin.

Unfortunately, it seems that commands like

syntax match Operator "\<MYOP\>"

located in .lvimrc are ignored silently by vim. Typing the command in the command line works as expected. Other commands from .lvimrc also work. So what may stop vim from interpreting local highlighting correctly?

Upvotes: 2

Views: 630

Answers (2)

Grwlf
Grwlf

Reputation: 956

That was because https://github.com/embear/vim-localvimrc plugin launches local files in a sandbox by default. Syntax commands are not allowed in a sandbox (at least in my setup), so the exception was raised. For some reason, Vim handles such exceptions silently.

In my case, the following modifications formed a solution:

  1. Disable sandboxes for localvimrc by adding let g:localvimrc_sandbox = 0 to master .vimrc file
  2. Add set conceallevel=2 to the localvimrc

Upvotes: 2

mMontu
mMontu

Reputation: 9273

It could be a problem with the loading order, i.e., your .lvimrc is loaded, then the filetype syntax is loaded and overwrites the .lvimrc syntax commands. You could check that by including echom statements on both files.

Also notice that the local vimrc is not the standard way of customizing syntax highlight. From Vim FAQ 24.11:

You should not modify the syntax files supplied with Vim to add your
extensions. When you install the next version of Vim, you will lose your
changes. Instead you should create a file under the ~/.vim/after/syntax
directory with the same name as the original syntax file and add your
additions to this file.

For more information, read 

    |mysyntaxfile-add|
    |'runtimepath'|

Upvotes: 0

Related Questions