Setting Vim cursorline colors? - vim

I have tried to look at other answers here on SO and Google but none of them seem to be changing my cursor settings. I am wanting to have a background of yellow with foreground of white bold but can't get it with the settings that I have seen around the web. I am using MacVim mvim in iTerm2.

Most likely you are interested in these three highlighting groups: Cursor, CursorColumn and CursorLine. The names are self explanatory.
For example to change just the cursor color:
:highlight Cursor ctermfg=White ctermbg=Yellow cterm=bold guifg=white guibg=yellow gui=bold
To do the same for column cursor:
:highlight CursorColumn ctermfg=White ctermbg=Yellow cterm=bold guifg=white guibg=yellow gui=bold
If you also need to highlight the current line, use CursorLine.

If you wants to keep it enable always put the below things in your .vimrc or .gvimrc file
for cursorline
set cursorline
autocmd InsertEnter * highlight CursorLine guibg=#000050 guifg=fg
autocmd InsertLeave * highlight CursorLine guibg=#004000 guifg=fg
for cursor column
set cursorcolumn
autocmd InsertEnter * highlight CursorColumn ctermfg=White ctermbg=Yellow cterm=bold guifg=white guibg=yellow gui=bold
autocmd InsertLeave * highlight CursorColumn ctermfg=Black ctermbg=Yellow cterm=bold guifg=Black guibg=yellow gui=NONE
You can change the colors in your wish

Related

How do I allow syntax highlighting to override the color scheme in Vim?

I am currently using the following lines from this answer in my .vimrc to fix my colorscheme when using vimdiff:
highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red
This works great for ordinary text file diffs. Unfortunately, when this is enabled and I diff two java files, the lines that are added (in the diff) lose their syntax highlighting.
Is there a way to make syntax highlighting run after the lines above, so that I can git reasonable diff highlighting while preserving syntax highlighting?

Linux VIM : Omnicppcomplete + supertab use bash color theme

I use vim with omnicppcomplete and supertab for programming. The dropdown window, which shows possible completions is like pink. How can i change the color for example to my personal bash color theme?
Open your colorscheme.
Find the lines that start with hi Pmenu*.
Edit them to your liking.
If there's no such line in your colorscheme, add the lines below and change the colors to what you want:
hi Pmenu cterm=none ctermfg=White ctermbg=Black
hi PmenuSel cterm=none ctermfg=Black ctermbg=DarkGreen
hi PmenuSbar cterm=none ctermfg=none ctermbg=Green
hi PmenuThumb cterm=none ctermfg=DarkGreen ctermbg=DarkGreen
See :help :highlight for more.

MatchParen and cursorcolumn conflict

Vim is not showing the matching brackets on the same column when I do in _vimrc
:set cursorline
:set cursorcolumn
Actually I have in my _vimrc
:set cursorline
:set cursorcolumn
:highlight CursorLine term=underline guibg=#fffcd0 cterm=underline
:highlight CursorColumn term=underline guibg=#e1ffd5 cterm=underline
Then the matching bracket on the same column does not highlight.
I tried below playing with guibg and guifg with Black and Cyan and gui=inverse as:
:highlight MatchParen guibg=somecolors guifg=othercolor gui=inverse
But nothing works.
I need the highlighted current column as #e1ffd5 and current line as #fffcd0, and
the matching brackets highlighted.
I need the both. How can I?
Normally if you do not turn on cursorline and cursorcolumn then there will be no problem, vim will show every matching paren normally, like:
image01.
All the problems will take place if you turn on cursorline and cursorcolumn. The matching paren highlight on the same column at the other end will be vanished, like:
image02.
Finally I tried
:highlight MatchParen guibg=Black guifg=Cyan gui=inverse
But this also is not very perfect. Paren on the other side will fade into white, which I never want.
I want everything perfectly, better saying a mixture of picture 1 and 2 both.
I tried but I could not.
Setting ctermfg and/or guifg to NONE gets you what you want.
hi CursorColumn cterm=NONE ctermbg=236 ctermfg=NONE gui=NONE guibg=#2d2d2d guifg=NONE
hi CursorLine cterm=NONE ctermbg=236 ctermfg=NONE gui=NONE guibg=#2d2d2d guifg=NONE
With the cterm settings I found the following.
First I found that the following command made the matching paren disappear.
:hi MatchParen cterm=NONE ctermfg=black ctermbg=white
While my cursor was on these pren, I switched over to next vertical split, and saw that the colors of the matching peren were reversed.
That led me to the solution with the following command.
:hi MatchParen cterm=reverse
or
:hi MatchParen cterm=reverse ctermfg=<your color> ctermbg=<your color>
I think the color you are looking for is
(steelblue and black) or (black and steelblue)
My setting and I didn't change :hi cursorcolumn.
:hi MatchParen cterm=reverse ctermfg=NONE ctermbg=NONE

How do I change my Vim highlight line to not be an underline?

In some colorschemes the current line highlighting changes background, in others, like Desert, the current line is underlined.
I want to change the current line highlighting in Desert to use a different background color instead of underlining. How can I do that?
My .vimrc:
set cursorline
highlight Cursorline cterm=bold
Update: .vimrc that solves the issue
colorscheme desert
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40
color desert
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40
desert is your colorscheme.(should come first)
put it in your ~/.vimrc
This works better (in every terminal) for me.
:hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white
It is setting of color for terminal: background color - ctermbg, and text color - ctermfg. For using in graphical window, add parameters guibg=darkred guifg=white
You can highlight the corresponding column as well, using the command:
:set cursorcolumn
It is useful to toggle highlighting on and off by pressing one key in the editor. Add these line to your vimrc:
:nnoremap H :set cursorline! cursorcolumn!<CR>
typing 'H' will toggle highlighting on and off (Map it to another key if you want)
You can find more info in the article:
http://vim.wikia.com/wiki/Highlight_current_line
for a style similar to the one you get in gvim in the terminal, preserving the syntax highlight:
" first thing is entering vim mode, not plain vi
set nocompatible
" force 256 colors on the terminal
set t_Co=256
" load the color scheme before anything
colorscheme darkblue " or desert... or anything
" the syntax cmd is when the colorscheme gets parsed, i think..
syntax on
" might not be on by default, this enable the cursor line feature
set cursorline
" set the prefered colours, pick one line here only.
" dark grey, better you can get if you don't support 256 colours
hi CursorLine cterm=NONE ctermbg=8 ctermfg=NONE
" light grey, no 256 colors
hi CursorLine cterm=NONE ctermbg=7 ctermfg=NONE
" dark redish
hi CursorLine cterm=NONE ctermbg=52 ctermfg=NONE
" dark bluish
hi CursorLine cterm=NONE ctermbg=17 ctermfg=NONE
" very light grey
hi CursorLine cterm=NONE ctermbg=254 ctermfg=NONE
" yelowish
hi CursorLine cterm=NONE ctermbg=229 ctermfg=NONE
" almost black
hi CursorLine cterm=NONE ctermbg=234 ctermfg=NONE
If you want to turn the underline on use either one of:
:hi CursorLine cterm=underline
:hi CursorLine gui=underline
Otherwise use one of those:
:hi CursorLine cterm=none
:hi CursorLine gui=none
I had a similar problem setting cursorline highlight, but mine was due to the mksession command that I was using to save the session information during vim exit. This session is then automatically restored during program startup, if it's run without any file arguments.
If anyone has .vimrc setup like this, you can add the following to .vimrc to set cursorline highlight correctly:-
function s:SetCursorLine()
set cursorline
hi cursorline cterm=none ctermbg=darkblue ctermfg=white
endfunction
autocmd VimEnter * call s:SetCursorLine()
A bit of explanation as to why this works. Along with various buffer and window information, mksession saves the current colorscheme name. This is restored during program startup through session restoration. However, since the session restoration is typically done after .vimrc has been run (typically using a function invoked through 'autocmd VimEnter *'), the cursorline highlight setting in .vimrc is reset by the default for the restored colorscheme.
The above function, invoked through the autocmd, will be run after all the initialization is complete and therefore successfully sets the cursorline highlight.
HTH.
You must add .vimrc end line:
highlight lineNr term=bold cterm=NONE ctermbg=none ctermfg=none gui=bold
set cursorline
highlight CursorLine term=bold cterm=NONE ctermbg=none ctermfg=none gui=bold
highlight CursorLineNr term=bold cterm=none ctermbg=none ctermfg=yellow gui=bold

Change GVim Color Scheme to be Like Command Line Vim

Is it possible to make the color scheme of GVim to exactly match the one in the command line version Vim? I like the colors of Vim more than the white-backgrounded GVim, but I still want to use GVim because the shift key doesn't map well on the command line version.
Yes, it is possible to make gvim exactly match terminal Vim. (It's not always possible to go the other way, though, gvim allows more colors so you can't always make terminal vim match if you're using gvim as your base.)
Colors are controlled with the ':highlight' command ( http://vimdoc.sourceforge.net/htmldoc/syntax.html#:highlight ) , which allows you to specify colors for gvim (guifg and guibg) differently from colors for terminal vim (ctermfg and ctermbg). All you have to do is make sure that the colors you assign to guifg and guibg are the same as you assign to ctermfg and ctermbg. Here's a script that might get you going:
http://vim.wikia.com/wiki/Xterm256_color_names_for_console_Vim
Note: the ':colorscheme' command fits in with the ':highlight' command by running the commands in a "colorscheme" file found in Vim's '/colors' directory. The colorscheme file itself will be mostly composed of highlight commands that set colors for all the different elements in the colorscheme. It's worth reading the help to see how all this fits together. Also, if you go to the Vim site you will find a bazillion scripts that are devoted to changing your colorscheme. Most of these are geared towards gvim, but many try to be friendly to both gvim and terminal vim. You can start here:
http://www.vim.org/scripts/script_search_results.php?keywords=&script_type=color+scheme&order_by=rating&direction=descending&search=search Just find one you like and plop the file in your /colors directory.
Alternatively, take a look at samples here:
http://vimcolorschemetest.googlecode.com/svn/html/index-pl.html
:colors koehler or :colors torte will set a not-too-horrible color scheme with a black background. I'm not sure what the command-line colors look like, though, so it may not match what you were looking for.
If you like that, add it to a file named .vimrc or _vimrc in your home directory. Otherwise, it'll change back next time you open gVim.
This gets gvim pretty close to default vim on my green text on black console.
hi clear
set background=dark
if exists("syntax_on")
syntax reset
endif
hi Normal ctermfg=green guifg=green guibg=black
hi SpecialKey term=bold ctermfg=4
hi NonText term=bold cterm=bold ctermfg=4
hi Directory term=bold ctermfg=4
hi ErrorMsg term=standout cterm=bold ctermfg=7 ctermbg=1
hi IncSearch term=reverse cterm=reverse
hi Search term=reverse ctermfg=0 ctermbg=3
hi MoreMsg term=bold ctermfg=2
hi ModeMsg term=bold cterm=bold
hi LineNr term=underline ctermfg=3
hi Question term=standout ctermfg=2
hi StatusLine term=bold,reverse cterm=bold,reverse
hi StatusLineNC term=reverse cterm=reverse
hi VertSplit term=reverse cterm=reverse
hi Title term=bold ctermfg=5
hi Visual term=reverse cterm=reverse
hi WarningMsg term=standout ctermfg=1
hi WildMenu term=standout ctermfg=0 ctermbg=3
hi Folded term=standout ctermfg=4 ctermbg=7
hi FoldColumn term=standout ctermfg=4 ctermbg=7
hi DiffAdd term=bold ctermbg=1
hi DiffChange term=bold ctermbg=5
hi DiffDelete term=bold cterm=bold ctermfg=4 ctermbg=6
hi DiffText term=reverse cterm=bold ctermbg=1
hi SignColumn term=standout ctermfg=4 ctermbg=7
hi SpellBad term=reverse ctermbg=1
hi SpellCap term=reverse ctermbg=4
hi SpellRare term=reverse ctermbg=5
hi SpellLocal term=underline ctermbg=6
hi Pmenu ctermbg=5
hi PmenuSel ctermbg=7
hi PmenuSbar ctermbg=7
hi PmenuThumb cterm=reverse
hi TabLine term=underline cterm=underline ctermfg=0 ctermbg=7
hi TabLineSel term=bold cterm=bold
hi TabLineFill term=reverse cterm=reverse
hi CursorColumn term=reverse ctermbg=7
hi CursorLine term=underline cterm=underline gui=underline guibg=black
hi MatchParen term=reverse ctermbg=6
hi Comment term=bold ctermfg=4
hi Constant term=underline ctermfg=1 guifg=red
hi Special term=bold ctermfg=3
hi Identifier term=underline ctermfg=6
hi Statement term=bold ctermfg=3 guifg=darkyellow
hi PreProc term=underline ctermfg=5 guifg=magenta
hi Type term=underline ctermfg=2
hi Underlined term=underline cterm=underline ctermfg=5
hi Ignore cterm=bold ctermfg=7
hi Error term=reverse cterm=bold ctermfg=7 ctermbg=1
hi Todo term=standout ctermfg=0 ctermbg=3

Resources