I use gvim and the color scheme which I use is called 'slate'. I mostly just code in python, html and css and I like slate's syntax coloring except for a few syntax colors. Is it possible for me to change a few of the syntax colors? For example, it colors all html tags blue, is it possible if I can change it to, say, red?


There are two abstractions for syntax coloring in Vim. First, the syntax plugin provides definitions for the various syntax elements (e.g. an HTML tag name -> htmlTagName), and links them to generic highlight groups (e.g. Statement). A colorscheme then provides the actual attributes and colors for those (which can depend on whether you use GVIM or a terminal).

If you don't like the color / formatting of a particular highlight group, you'd basically create your own customized fork of the colorscheme. Copy the existing colors/schemename.vim to ~/.vim/colors/newscheme.vim, and use the new name in your .vimrc via the :colorscheme newscheme command.

On the other hand, if you're fine with the general colors, and just think that a particular syntax element should use a different group, you can override the default assignment. In this example:

:syntax link htmlTagName Constant
  • Do you know whether there is a way to modify an existing colorscheme without copying the whole original file? I currently use slate, and I just don't like the white background for PreProc.
    – steffen
    Apr 30 '21 at 7:51
  • 1
    @steffen You can tweak a colorscheme with individual :hi commands after the :color command (e.g. in your ~/.vimrc). E.g. color slate followed by hi PreProc guibg=NONE. Apr 30 '21 at 8:21
  • 1
    @steffen Alternatively (for cleaner separation / larger changes, or if you dynamically change colorschemes during Vim use), you can write a wrapper scheme (in ~/.vim/colors/myslate.vim), where you :runtime colors/slate.vim and then append the :hi commands. Apr 30 '21 at 8:24

gvim has files (eg. slate.vim) in a colors directory wherever it is installed. Where that is OS dependent. You could change them in there and it will change for all users.

You can override by putting a colors file (on Linux) in .vim/colors in your home directory. Not sure what to call the directory in windows. This looks like a pretty comprehensive tutorial: http://andrewradev.com/2011/08/06/making-vim-pretty-with-custom-colors/

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.