1

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?

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?

  • Next time, please try to keep your question focused by asking a single question. Answer ended up going too long... But hopefully it'll be useful to you! – filbranden Feb 13 at 6:48
1

How to use different colorscheme and syntax highlighting in vim?

Colorscheme and syntax highlighting are complementary in Vim, so you typically use one of each.

The colorscheme will define what color is applied to each type of element (such as Keyword, Identifier, String, Number, etc.)

While the syntax highlighting (for a specific filetype, typically a programming language) will define how to identify those elements for that language (for example, with a list of reserved words or regular expressions to delimit the specific items.)

Suppose I want to use [papercolor] colorscheme. I copied the PaperColor.vim file into .vim/colors and made my .vimrc: [...]

That's one possible way to install it, but I really recommend using a plugin manager instead! Read on.

Now, I want to use this syntax highlighting for haskell files:

So here you'll see more the value of a plugin manager! Since technically you're supposed to copy all the *.vim files from every subdirectory into the corresponding subdirectory of ~/.vim, but that quickly becomes pretty messy if you want to install many plugins. (Manually unpacking them means all the files would mix together!)

I really recommend using vim-plug, since it works great on Vim 7, Vim 8, Neovim, etc. Vim 8 and Neovim support "native" plugins but you need to manually handle the docs, so you benefit from using vim-plug on them too.

See the README file for installation instructions (you just need to download one file), then update your ~/.vimrc to list the two plugins you're interested on:

call plug#begin('~/.vim/plugged')
Plug 'NLKNguyen/papercolor-theme'
Plug 'raichoo/haskell-vim'
call plug#end()

Then start Vim and run the :PlugInstall command. Done!


If you use a plugin manager, you don't need to care about the other details... But in case you want to understand how it works, here it goes:

There are two syntax highlighting files. Which one am I supposed to use, and where do it put them?

They are for different filetypes and they're loaded when a specific filetype is set.

Do I put it in ./vim/syntax and vim auto-loads all files in ./vim/syntax folder?

Yes, Vim will load a file named xyz.vim whenever filetype is set to xyz.

So if you open a buffer, type some text and then use a command such as :setf haskell it will load haskell.vim from ~/.vim/syntax.

(See :help 'filetype' and :help :setf for more details.)

It seems like to load haskell.vim automatically. But doesn't load cabal.vim.

That will be used for files of type cabal, so using :setf cabal will use that syntax highlighting configuration. (i don't know much about Haskell and Cabal but I imagine they're related files, with somewhat different syntax and distinct file extensions.)

Wondering if it only loads haskell.vim when I open *.hs files? I'm trying to make it like that.

The default Vim configuration already ships commands that will set up the correct filetype (haskell, cabal) for common extensions such as *.hs.

The haskell-vim plugin also ships a ftdetect/haskell.vim script that configures it for additional extensions, with the following commands:

au BufRead,BufNewFile *.hsc set filetype=haskell
au BufRead,BufNewFile *.bpk set filetype=haskell
au BufRead,BufNewFile *.hsig set filetype=haskell

As you can see, that's how plugins attach syntax (and indent, key mappings, etc.) for specific file types.

Can vim load multiple syntax files at once?

Yes, but that's quite unusual...

Here's an example from :help 'filetype':

    When a dot appears in the value then this separates two filetype
    names.  Example:
        /* vim: set filetype=c.doxygen : */ 
    This will use the "c" filetype first, then the "doxygen" filetype.
1

To use colorscheme:

  1. put it into .vim/colors/PaperColor.vim
  2. run `:color PaperColor
  3. run :set background=light to make it use light background
  4. if it works, persist settings in your .vimrc
color PaperColor
set background=light

To use haskell syntax from mentioned package without following installation instructions given on repo readme :) :

  1. put it into /vim/syntax/haskell.vim (from the repo folder /syntax/)
  2. now there is also file type detection located in repo's /ftdetect/ folder (https://github.com/raichoo/haskell-vim/tree/master/ftdetect), get haskell.vim from there and put it into your local .vim/ftdetect/haskell.vim. File type detection makes vim load haskell syntax automatically (simplified explanation)

But I really suggest to use installation method described in a README file. Either using pathogen or manually. (or using any package manager)

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.