How to define a custom RGB background colour in VIM? - vim

Is it possible to define a custom RGB colour for the background colour of VIM?
At the moment I use set background=dark in my .vimrc which assigns #5D5D5D for the background colour. However, I would prefer to have #3F3F3F for my background colour.

Normally your terminal will support only 256 colors, and they are numbered. If you want to use a particular color but don't know the number, the script gui2term.py will help you to find the most approximate one. Or you can just pick one from a table like this one.
If you are designing or modifying for your own color scheme for Vim, you can also use gui2term.py to translate those colors to the numbers.
Once you get the color number you'd like to use, you can edit your color scheme file. changing (or adding) the ctermbg value for the Normal and NonText group may be enough. E.g.:
highlight Normal guifg=#e0e0e0 guibg=#242424 gui=NONE ctermfg=254 ctermbg=235 cterm=NONE
highlight NonText guifg=#99968b guibg=#242424 gui=NONE ctermfg=246 ctermbg=235 cterm=NONE
There is a nice HTML Vim color scheme editor. You can try this to figure out which part uses which group and if you like, edit the colors visually (and run gui2term.py against the result file to make it support color terminals).

Related

Vim disable SpecialKey highlighting

I use set list lcs=tab:\❘\ to display tab indenting, and subtly set the color to be slightly lighter than my background. However, CursorLine seems to highlight these in white, which is unwanted. What can I do so that the color does not highlight, but stays the same?
Unfortunately, there's nothing you can do. Vim will use the foreground color of CursorLine, or Normal if the former isn't defined. It currently doesn't "mix" the color definitions from SpecialKey and CursorLine. You could suggest changing this behavior on the vim_dev mailing list.
I find a solution here and it works for me
:highlight MyTabSpace guifg=darkgrey ctermfg=darkgrey
:match MyTabSpace /\t\| /

How to change the folded part color on Vim

I fold some of the functions on my C code. When I fold them, the color becomes gray. Is there any way to change the color of folded part to another color?
You can use the :highlight setting. For instance, to set the background to red, add this to your .vimrc:
highlight Folded ctermbg=red
You can view a list of supported colour names by running :source $VIMRUNTIME/syntax/colortest.vim. ctermbg updates the console background; ctermfg updates the console foreground; and guibg & guifg update gvim's background and foreground colours. If you're changing gvim's settings, you can use whatever hex code you like (you don't have to restrict yourself to supported colours).
Type :verbose hi it will describe you all the highlighting groups and where they are defined. There is probably one describing the Fold but I don't know the group name by heart.

Changing background colors

Okay, I'm rather new to vim. I couldn't figure out how to change background colors. I'm editing my vimrc file to set these colors, but I couldn't find anything for background colors.
I'm using a color scheme and I just need to know how I could override it or what is to look for so I can change it in my colors/theme.vim file. I need to change two background colors. I point to them in the image attached.
As it turns out the big blue section is controlled by highlight NonText
I added my .vimrc file to this:
highlight NonText ctermfg=59 ctermbg=0 cterm=NONE guifg=#414e58 guibg=#232c31 gui=NONE
and that gave me exactly what I wanted.
VIM has some color scheme, which store under /usr/share/vim/vimcurrent/colors, and it named as desert.vim for example.
you can simply add one line in your vimrc file, which should be locate in your $HOME, if there is NOT, you can create one, and add:
colorscheme desert
also some command you can use to set the background color like:
set background=light
or
set background=dark
I think for SSH, light is better:) If you use X windows, I suggest to use bensday.vim, it can be download from web

How to change the color of highlighted misspelled word?

In the theme I'm using for vim, the strings are shown in red color but the problem is I have spellcheck on and the misspelled words are also shown in red color.
This makes it hard to see what is the mistake until you go to that word and delete any character.
I want to make the highlightation of the misspelled word in somewhat lighter then it currently. Say #ff2929.
You can use the hi (short for :help highlight) command in your ~/.vimrc. The general structure is:
hi SpellBad ctermfg=015 ctermbg=000 cterm=none guifg=#FFFFFF guibg=#000000 gui=none
The cterm is for terminal vim and the gui is for gVim. The fg stands for foreground and is the color of the letters and the bg stands for background and is the color behind the letters.
Terminal colors can be 0-15 for standard terminal colors (8 normal and 8 bright) or 0-255 for terms supporting 256 colors, like xterm-256colors. The gui colors are in hexadecimal format. xterm-color-table is a useful reference for both 256 and hexadecimal colors. The final option can be used to specify bold, italic, or none (neither).
In your case, it might be simplest to set the foreground to black to make the letters stand out. First, find a word that's mispelled with :set spell and then typing asdflkjasldf or something. Then type :hi SpellBad ctermfg=000 guifg=#000 and see if that's a solution you like. If not, use the xterm-color-table or another color reference to find a color you do like.
Try this:
:hi SpellBad guibg=#ff2929 ctermbg=224
guibg is for GUI
ctermbg is for TERM
I found the following to halfway work for a more complex example involving colorscheme, but it is sensitive to the order of .vimrc commands. I tested with Cygwin/mintty and Git Bash, vim 8.0, with similar results. I edited a markdown file with "misspelled" words in headings and paragraphs, so an additional factor is the auto-formatting that vim is doing for markdown. If the .vimrc order is spell, colorscheme, and then hi (trying to use white text on red background), the result for misspelled words is white foreground on black background (image below), regardless of whether in markdown heading or paragraph. This is OK but I'd prefer to have the background for misspelled words be more eye-catching, which is why I specified red background.
However, if the order is spell, hi, and colorscheme, the result is OK in paragraphs but undesired pink on red in headers (image below). This is actually the original behavior without hi, which makes sense because the colorscheme is probably stepping on the hi settings. Based on other testing, the relative position of hi and colorscheme is what is important.
I think I'm going to go with the first option because at least the highlights seem to be in all content, but it would be nice if the red background is used. The following is my .vimrc lines for the first case. Any guidance to fix this would be appreciated.
" Turn on spell-checker
set spell
" Color scheme
" To pick from available list do:
" :colorscheme _space_ Tab
" Reasonable options seem to be: koehler, murphy, elford
colorscheme koehler
" Using the colorscheme with spellchecking results in highlights with
" pink text on red background, which is hard to read, so change the highlight color.
" Color table: https://github.com/guns/xterm-color-table.vim
" Use white text on red background for misspelled words.
hi SpellBad ctermfg=015 ctermbg=009 cterm=bold guibg=#ff0000 guifg=#000000 gui=bold

VIM initial settings: change background color for line number on the left side?

I use _vimrc to configure my vim 7.2 (windows) default settings. One setting "set number" will display line numbers on the left side. My vim background color is white (I cannot find setting for this. Maybe the default is white. Anyway I accept this setting).
I would like the background color for line numbers to be Grey or dimmed color. What is the command I can put in my _vimrc to configure this default setting?
highlight LineNr ctermfg=grey ctermbg=white
To make the line number column transparent (the same color as the main background) you can try setting this in your .vimrc:
highlight clear LineNr
You can also clear the so-called sign column (used by gitgutter, etc) as well:
highlight clear SignColumn
This way, no matter what color scheme you use, both columns' background will be compatible.
In my _vimrc, here is the setting:
highlight LineNr guibg=grey
or
hi LineNr guibg=grey
I don't need to set fore-color, the default is yellow and it is OK for me.
guibg and guifg are for vims which are not in terminal. For terminal you use ctermfg ctermbg. Usually in GUI vims you have more colors support and you simply want to avoid the background.
So I usually use this:
highlight LineNr guibg=NONE

Resources