How to underline (rather than highlight) the current line in vim? - 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

Related

No cursor in vim

UPDATE 16-03-01:
I changed the highlight option to make text dark green, as you can see in the picture. Notice the cursor is on one of the parenthesis, making them both orange, but there's no cursor:
EDIT (SOLVED):
I just deleted the .vimrc file entirely and now the cursor is back so there was some typo or problem in there that messed with it.
ORIGINAL:
I don't have any cursor, box or line in vim. I'm using vim through the latest version of cmder. I'm new to vim but I couldn't find anyone else with a similar problem.
You can set cursorline using
set cursorline
in your ~/.vimrc file. But this looks clumsy with a long line
and you can remedied by highlighting cursorline
highlight CursorLine cterm=NONE ctermbg=NONE ctermfg=darkgreen
You can select your own colour, here I have used darkgreen.
where cterm is terminal colour, set to NONE
ctermbg back ground color of terminal. also set to NONE here
Please add the following to your ~/.vimrc
set nocompatible
set mouse=a
set cursorline
In a short, the behavior of VIM is configured by the ~/.vimrc file, you should add configurations in it for yourself.

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.

Highlighting the current line number in vim

Is there a way to highlight only the current line number (in the left hand coloumn) in vim, without highlighting the background of the current line? Ideally, I would Like to make the current line number bold.
There are two groups that determine highlighting of line displayed when &cursorline option is active: CursorLine and CursorLineNR. First is used to highlight the whole line, second for the line number. So to achieve what you want you must
Clear the highlighting of CursorLine: just hi clear CursorLine after any :colorscheme and set background= call.
hi clear CursorLine
augroup CLClear
autocmd! ColorScheme * hi clear CursorLine
augroup END
Set the highlighting of CursorLineNR if it is not set in your colorscheme:
hi CursorLineNR cterm=bold
augroup CLNRSet
autocmd! ColorScheme * hi CursorLineNR cterm=bold
augroup END
(better to check whether it is already set in the colorscheme, maybe it will look better in that case).
You can join both autocommands in one of course.
CursorLineNR has been added relatively recently around version 7.3.488.
You want to look at
:se cursorline
and perhaps even/also
:se cursorcolumn
This is what worked for me:
highlight CursorLine cterm=NONE ctermbg=NONE ctermfg=NONE guibg=NONE guifg=NONE
set cursorline
I'm just using this in my .vimrc after having set the color scheme. Of course you could also set a specific background color but setting all of them to NONE just highlights the line number (i.e. makes it brighter).
I guess you could just use :hi CursorLine cterm=NONE but I just wanted to make sure I'm making everything transparent (gvim included).
With CursorLineNR I was then able to set the foreground and background colors of the highlighted number.
I'm only writing this because for me it worked without any autocommands and it may be what most people require.
You can set cursorline to highlight only the numbers
'cursorlineopt' 'culopt' string (default: "number,line")
local to window
{not available when compiled without the +syntax
feature}
Comma separated list of settings for how 'cursorline' is displayed.
Valid values:
"line" Highlight the text line of the cursor with
CursorLine hl-CursorLine.
"screenline" Highlight only the screen line of the cursor with
CursorLine hl-CursorLine.
"number" Highlight the line number of the cursor with
CursorLineNr hl-CursorLineNr.
And to override your colorscheme use autocmd
So, the following works:
set cursorline
set cursorlineopt=number
autocmd ColorScheme * highlight CursorLineNr cterm=bold term=bold gui=bold
This worked for me to highlight the line number and not the rest of the line:
highlight CursorLineNr cterm=NONE ctermbg=15 ctermfg=8 gui=NONE guibg=#ffffff guifg=#d70000
The help for highlight-groups does not mention an exclusive "number of current line" syntax group, so the official answer might be no.
You may want to take a look in the cursorline option which highlights the entire line, if it helps.

Change color of cursor in gvim

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.

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