16

What files do I need to create? What should be inside these files? Is there a default colorscheme file somewhere that I can use and change color values accordingly?

15

Colorscheme locations

First, Vim looks in its runtime folders for a colors directory. Here is where all the colorschemes should be stored (:help 'runtimepath')

This means you will need one file that lives in the ~/.vim/colors folder. Default colorschemes are located in $VIMRUNTIME/colors, where $VIMRUNTIME is usually /usr/share/vim/vim74 or the /usr/local/share/vim/vim74 directories, depending on how Vim is installed (substitute vim74 for vim73 for Vim version 7.3)

Now to get to the fun part.

Creating a colorscheme

To get started with creating your own colorscheme, I highly suggest taking a look at the default colorschemes and experiment with modifying them.

So copy the default colorscheme from $VIMRUNTIME/colors folder to your ~/.vim/colors folder. Name it something that distinguishes itself from the default colorscheme name. So if you copied the desert colorscheme that comes with Vim by default, name the file as default_mod.vim or something to that effect. Open up the colorscheme file and change the let g:colors_name to also distinguish itself from the default colorscheme file. By convention, this should be the same as the colorscheme file name.

In the colorscheme, all you have to do is give the colors for ctermbg, ctermfg, guibg, guifg (for terminal background, terminal foreground, gui background, gui foreground colors respectively) for the different built in highlight groups. To check out the list of highlight groups you can modify, check out :help highlight-default. Optionally, you can also use the cterm and gui attributes to specify that you want a highlight group to be bold or italic.

For example, this will set a green color for a String:

highlight String ctermbg=NONE ctermfg=107 guibg=NONE guifg=#95B47B

You can also use highlight links to link a highlight group to another group. This is useful if you want two highlight groups to be the same colors.

For instance, you could link the diffAdded highlight group to the String highlight group defined above:

highlight link diffAdded String

  • If I just copy one of the colorscheme.vim files and then put it in separate folder will I be able to reuse it on my other machines? E.g. if I put it in a repo on github will I be able to just clone it or enable it in one of the plugin managers? – dkns Mar 30 '15 at 8:49
  • @dkns, Yep, exactly. For instance, you can name your colorscheme as "dkns_colorscheme.vim", put it in a colors/ directory and then push it up to Github. If you have a plugin manager installed, cloning this repo will make the colorscheme available to Vim. – akshay Mar 30 '15 at 8:51
  • Another question. Not sure if I should post it here as a comment or ask another general question. How can I find color values for cterm? I'd like to have this theme look the same on gui and terminal but I don't know how to convert hex values to cterm values. – dkns Apr 1 '15 at 15:48
  • 1
    @dkns Since the terminal colors are largely dependent on the color palette used in the terminal emulator, this is pretty difficult to do. When I was creating my colorscheme, I found it helpful to display what each of the 256 colors looks like. I use this small script in my bin folder. You can just use a color picker to then choose the colors to ensure the same gui and cterm colors. I would go from cterm->gui and not the other way around since there are more colors in the gui vim. Hope that helps. – akshay Apr 2 '15 at 19:16
7

Check out sites like Vivify and Villustrator. They basically let you graphically create or tweak a scheme and then download the necessary files.

0

There are some tools to make this automatic:

  • vivify: quite complex, you have to manually select each color for each single highlight group.
  • vimcolors.org: very simple and easy. Just choose some colors and it will automatically generate the scheme for you.
0

Another great tool is RNB by romainl which uses ERB. ERB (Embedded RuBy) is a feature of Ruby that enables you to generate some text from templates.

So the usage of this tool is pretty straight forward: First you need to define different variables corresponding to the nomenclature of your colorscheme and of course to its actual content (How the colors should look, which groups you want to use, etc) it is pretty straight forward because the author wrote a lot of comments to help you. Then all you need to do is to give your customized template to erb and the tool will generate the right files.

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.