Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 23, 2020 07:24 pm GMT

Making a Vim colorscheme

This post is edited from my original blog post. Find it, and other posts by me on kewbi.sh/blog.

Introduction

In the middle of getting back to school and trying to redesign my website, I've also been spending quite a bit of time in Vim. Since installing Manjaro a couple weeks ago, I've decided to experiment with only programming in Vim.

With spending 100% of my writing and editing time in Vim also came a slight obsession with customizing things. Looking up random settings to put into my .vimrc was quite fun - I've managed to do most of what I usually rely on in VSCode anyhow. The Vim wiki really does happen to have everything.

One of these tweaking points was the colourscheme. (Or colorscheme, according to my vimrc. I use both terms interchangeably out of habit from American / Canadian English, so please make sure you've spelled things correctly.) I could have just spent two minutes scrolling through default colourschemes, but I didn't like any of the inbuilt ones. Coming from VSCode, I thought it'd be nice to have the same colourscheme, so I popped vim-code-dark into my plugins and went about my merry day.

However, I wasn't quite happy with the colours - it was a bit too colourful for my taste, since the rest of my setup was relatively monochrome anyway. So - I spent some time researching how to change colourschemes. There are a bunch of internet tutorials for building a basic colourscheme, and even a generator for that, but I didn't find much about how to tweak an existing one.

Finding a colourscheme

After watching several people flip through the endless catelog of vimcolors, I'd probably suggest finding a colourscheme that you like 90% and tweaking that last 10% yourself. Or if you're planning on just monochroming something, a scheme that has your preferred range of saturation and colour. It'll save you time in customizing and also in finding schemes.

How colourschemes work

Note: most of this is from reverse engineering vim-code-dark, so probably take this with a grain of salt or two.

From my trawling of several Vim colourscheme repos, I've kind of figured out that Vim takes colorschemes from whatever colors/ folder your plugin or colourscheme is installed in. I'm not entirely sure how Vim-Plug works, but whatever I edited inside .vim/plugged/vim-code-dark/colors happened to show up in my colourscheme, so I assume this is controlled via Vim-Plug and whatever you reference inside your .vimrc.

Vim also has a bunch of terms regarding the colours that are used for highlighting and styling.

  • guifg and guibg: the foreground (text) and background (background of interface) colours for gVim (the GUI version of Vim).
  • gui: the text style, which obviously isn't a colour, but it fits in here.
  • ctermfg, ctermbg, cterm: the same as the gui equivalents, but for the terminal.
  • cterm256: which seems to be cterm but for 256 colour terminals.

Vim does highlighting and colours with highlighting groups, which are all in :help syntax.txt:, under naming conventions. Here, the syntax is something like:

highlight groupname key=value

However, most of this is usually already filled in with whatever colourscheme, so you don't have to worry too much about this.

Another interesting note is that these ctermfg and cterm256fg (and the others as well) can be aliased, and the entire process made a lot easier with function aliases and things. While going through vim-code-dark, I noticed they were using a custom function, which provides shorthand for assigning fore and background colours. If you're interested, it might look a little like this implementation.

Editing colours

Most colourschemes usually have a bunch of colour definitions, with a long list of let statements somewhere, so go look for those. In vim-code-dark, I had to edit the cterm256 definitions. The guifg parts get set with hexadecimal codes, it seems, but the rest of the colours seem to be from the 256 terminal colour chart. You can see the list on this cheat sheet.

What I did here was essentially look up each colour, copy-paste its hex code into Google's colour picker, then choose an appropriately saturated grey. (And yes, the whole colourscheme is grey. I might want to add some colour pastels but for now it works fine. Not on dotfiles yet - I need to set those up properly as well.)

The default color definition bit looked something like:

let s:cdLeftDark = {'gui': '#252526', 'cterm': s:cterm01, 'cterm256': '235'}

and I just edited the cterm256 mapping. (Don't use gVim, but if you're using gVim it's the same, only editing the hex code.)

Some other schemes I looked at while trying to figure things out just used a bunch of definitions without variables - here, you can probably just do a :%s/whatever/whatever2/g.

Right now, it looks something like:

My Vim at the moment
My Vim at the moment.

Conclusion

I'm still going to tweak some of the colours later, but for now, I think that this grey theme's pretty nice. For markdown and writing there aren't a lot of random colours jostling for attention, and when editing proper code it's half decent too.

Anyhow, back to tweaking my .vimrc (and definitely not spending too much time doing that).


Original Link: https://dev.to/kewbish/making-a-vim-colorscheme-2dm1

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To