Change color of cursor in gvim - vim

I want to change the color of the cursor pending on the current mode.
Here is my code so far (.gvimrc).
set gcr=n:blinkon0
set gcr=i:blinkon0
highlight Cursor guifg=white guibg=red
highlight iCursor guifg=white guibg=green
Right now the cursor is gray, nothing changes.
Running highlight Cursor guifg=white guibg=red manually works, but not the line below.
I want the color green in insert mode and red in every other mode.

I got some help from the vim irc # freenode.
Here is the solution.
au InsertLeave * hi Cursor guibg=red
au InsertEnter * hi Cursor guibg=green

You have to actually specify the highlight group in the gcr setting. You also need to put them together, your second "i:" one overrides the first. It also overrides all your defaults, so even combining them doesn't cover the other modes, or the different shapes in modes like operator pending... check out the documentation. Try just altering the default to set your iCursor group on insert mode.
set gcr=n-v:block-Cursor/lCursor,c:block-iCursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-iCursor/lCursor,r-cr:hor20-iCursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
This is based on the defaults, except i, ci, r, cr, and c (insert, replace, and command line) all use your iCursor group.

Related

Highlighting the 70th character of a current line in Vim

I like to keep a strict 70 character margin whenever possible. To help with this, I want to configure vim so that the 70th character of the current line is highlighted. I understand that
set cursorline
can be used to highlight the current line. I, however, would like just the
very end of the line (the 70th character) to be highlighted. How would I go about accomplishing this?
Edit: cursorcolumn isn't what I'm looking for. I just want a single character (the 70th one on the current line).
Edit 2: perhaps a picture will help.
You can use colorcolumn to set a "right margin" bar.
This did not exist before Vim 7.3, so it is wisest to only enable it if the feature is available.
if exists('&colorcolumn')
set colorcolumn=70
endif
I prefer that this only be shown in insert mode, so I use this:
if exists('&colorcolumn')
autocmd InsertEnter * set colorcolumn=80
autocmd InsertLeave * set colorcolumn=""
endif
That will set the option when you switch to insert mode, and turn it off when you leave insert mode.
:call matchadd('Todo', '\%70c')
and if you don't want to count one tab as a single character, but you want to take into account all the spaces it takes:
:call matchadd('Todo', '\%70v')
You can use any other highlight group (for example to change color) listed by :hi instead of Todo.
:autocmd CursorMoved * exe 'match IncSearch /\%70v\%' . line(".") . 'l./'
The highlight color will be determined by your color scheme.
You can change IncSearch to any of the highlight groups, which can be found by typing:
:hi
If you are using VIM 7.3 you can set the color of a certain column with:
set colorcolumn=70

How to underline (rather than highlight) the current line in vim?

I believe it's possible to get an underline under the current line, rather than a highlight.
This adds the highlight in my .vimrc:
set cursorline
This is what I've tried adding to get an underline:
:highlight CursorLine gui=underline cterm=underline
But it appears to make no difference.
I'm using vim 7.4.629 on Centos 6.7 through putty, if that helps.
try :hi clear CursorLine to clear the current cusorline hl, then :hi CursorLine gui=underline cterm=underline
The color of underline is same as your ctermfg or guifg. You can either live with your "colorful" underline, or add cterm/guifg to make the underlined text and the underline same color.
:set cursorline
was the best solution for me, you can combine it with removing the cursorLine as the answer above mentions
For me it works best to highlight the cursor line only in Insert mode. To do so, I use the action snippet to activate cursor underlining (full line) whenever Insert mode is activated and later deactivating it upon leaving the mode.
au InsertEnter * set cul
au InsertLeave * set nocul

Set visibility and/or color of listchars or conceal cchar in vim when cursorline is highlighting a line

I know that I can use set list listchars=... to show NonText and SpecialKey characters in order to highlight different kinds of, well non-text characters. In general this is straight forward and works. But it has a visual side effect which disturbes me - while "hovering" the cursor over a line when the cursorline is set to on listchars are highlighted in a different color. The problem was already mentioned in this thread and there does not seem to be a solution to work around the behaviour.
As a consquence I started to play with the conceal feature, which gives me mixed results. set concealcursor=n||v||i||c lets me control in which modes concealed characters are visible. I want to be able to see concealed characters always so I set up the following:
function! ConcealNonText()
set conceallevel=1
set concealcursor=nvic
syntax match NonText / / conceal cchar=ยท
endfunction
augroup ConcealNonText
autocmd!
autocmd VimEnter * call ConcealNonText()
augroup END
As a result it highlights all spaces which are alway visible no matter which mode I'm currently in. But again there's a disturbing side effect - when I mark lines in visual mode or highlight a line with my cursorline the highlighting area gets interrupted where concealed characters are found. Just see the screenshots:
Visual mode with selected area:
Normal mode with cursorline:
So I thought let's try set concealcursor=ic. This results in uninterrupted highlighted areas, but then the characters are hidden.
So is there a somewhere and somehow a solution around to the thread I mentioned in the beginning of this post or is there any way to make the cursorline and visual select areas uninterrupted when using set concealcursor=nvic?
I believe you have 'cursorline' set. The CursorLine highlight group defines the highlights for the same. Either you set nocursorline, (which can speed line movements) or change the CursorLine highlight groups fg colors.

In Vim can you stop the color change of white space characters with 'set cursorline' on?

In this Vim screenshot you can see that when moving the cursor over a line it changes the normal color of the whitespace characters (shown on the left) from grey to black. Can I stop this and leave them showing grey always, regardless of cursor position?
I've tried setting these in the colour scheme but no luck:
hi SpecialKey guibg=bg guifg=#CCCCCC gui=none
hi NonText guibg=bg guifg=#CCCCCC gui=none
You can use :match to highlight the tabs.
:match NonText '^\s\+'
That seems to override the cursor line. It would be better of course to use matchadd() but it seems to be overriden by the cursor line. There might be a way to make it work
Following lines in .vimrc fixed the problem for me.
au VimEnter * call matchadd('SpecialKey', '^\s\+', -1)
au VimEnter * call matchadd('SpecialKey', '\s\+$', -1)
It overrides other styles application for tabs and trailing spaces inside a cursor line.
Yes you can. From :help listchars (at the end):
The "NonText" highlighting will be used for "eol", "extends" and
"precedes". "SpecialKey" for "nbsp", "tab" and "trail".
With this knowledge you can modify your color scheme accordingly or add a call to highlight in your vimrc.
I believe you have 'cursorline' set. The CursorLine highlight group defines the highlights for the same. Either you set nocursorline, (which can speed line movements) or change the CursorLine highlight groups fg colors.

Vim: Different line-number color in the different modes

I've just started using Vim and I find myself being confused on which mode I'm currently in. I was wondering if it's possible to change the line number color (which I have displayed by default) in the different modes (command, visual, and insert) so that I can easily identify it.
Vim has an option called showmode that will put a message on the last line if you are not in normal mode. See :help 'showmode' for more info.
If you really want to change the background of the number column while in insert mode, you could do something like the following:
autocmd InsertEnter * highlight LineNr ctermbg=red guibg=red
autocmd InsertLeave * highlight LineNr ctermbg=black guibg=black
Note that this method will break if you are bad and use C-c to exit insert mode instead of <Esc> or <C-[.
Relevant :help tags: autocmd, autocmd-events, highlight, highlight-groups

Resources