Reputation: 22777
Suppose I want to use this colorscheme: https://github.com/NLKNguyen/papercolor-theme
I copied the PaperColor.vim file into .vim/colors and made my .vimrc:
syntax on
colorscheme PaperColor
background=light
Now, I want to use this syntax highlighting for haskell files: https://github.com/raichoo/haskell-vim/tree/master/syntax
There are two syntax highlighting files. Which one am I supposed to use, and where do it put them?
Thanks!
Do I put it in ./vim/syntax and vim auto-loads all files in ./vim/syntax folder?
It seems like to load haskell.vim automatically. But doesn't load cabal.vim. Wondering if it only loads haskell.vim when I open .hs files? I'm trying to make it like that. Can vim load multiple syntax files at once?
Upvotes: 4
Views: 1697
Reputation: 172738
TL;DR: Everything's (mostly) fine. There's a difference between colorschemes and syntax scripts.
Most filetypes (like python
) in Vim come with a syntax that defines highlight groups (see them via :highlight python<C-d>
). These particular groups (e.g. pythonFunction
) are then linked to a set of default groups (:help highlight-groups
, e.g. Identifier
). A colorscheme then provides combinations of foreground / background color and/or formatting like bold and italic (separately for terminals, color terminals, and/or GVIM) for the default groups.
highlight group → default group → color + style
pythonFunction
→ Identifier
→ term=underline ctermfg=3 guifg=DarkCyan
So, for a set of beautifully matching colors that please your personal taste, you choose a colorscheme. For you, that would be colorscheme PaperColor
. Note that the background
needs to be set before choosing the color (and you've missed the :set
command):
syntax on
set background=light
colorscheme PaperColor
The syntax scripts know how to parse a certain syntax (for you: both haskell and cabal; what gets activated depends on filetype detection, which usually does the right thing, but you could also manually override it (:setlocal syntax=cabal
); I think the former is for Haskell source code while cabal is a package definition). They basically recognize certain syntax elements, and link them to generic highlight groups (like Statement
, String
, Comment
, and so on). Now how these are then colored (e.g. bold green) is determined by your chosen colorscheme.
As you can see, colorschemes and syntax scripts each have a distinct role, and play together. While the former is a global personal choice, the latter is activated based on the detected filetype, which is different for each buffer.
Upvotes: 2