73
votes
Accepted
How can I clear word highlighting in the current document (e.g. such as after searching for a word)?
As an alternative to :noh, I like to do :let @/="" mapped to a keyboard shortcut.
The difference is that :noh leaves the search term in the search register, so n and N in normal mode resume the ...
- 8,282
58
votes
Accepted
Is there any way to change the popup menu color?
You can use the following highlight groups:
Pmenu – normal item
PmenuSel – selected item
PmenuSbar – scrollbar
PmenuThumb – thumb of the scrollbar
For example to set a grey background:
:highlight ...
- 59.7k
53
votes
How can I clear word highlighting in the current document (e.g. such as after searching for a word)?
Simply type
:noh<cr>
(Where <cr> symbolizes a carriage return, i.e. Enter.) The full non-abbreviated version of this command is :nohlsearch.
For convenience, you can have a mapping ...
- 14.4k
42
votes
Accepted
Can the split separator in vim be less than a full column wide?
You are wrong about tmux. Like every terminal-based program — including Vim — it only draws stuff inside cells. This means that Vim and tmux both use the same method to draw vertical borders: they ...
- 36k
42
votes
How to automatically turn off "hlsearch" after I'm done searching?
There is a much more convenient way. Rather than using
:set nohlsearch
which actually turns the hlsearch setting off, use
:nohls
This will only turn hlsearch off until you search again. From :...
- 17.1k
37
votes
How can I clear word highlighting in the current document (e.g. such as after searching for a word)?
Disable search highlighting permanently
Matches won't be highlighted whenever you do a search using /
:set nohlsearch
Clear highlight until next search
:noh
or :nohlsearch (clears until n or N is ...
- 721
25
votes
Accepted
How to set value of cterm to both bold and underline?
Vim has excellent help files.
I had no idea what the answer was to this question but I found it in one minute:
:h cterm (don't hit Enter yet)
Tab for auto-completion to see some choices
highlight-...
- 19k
17
votes
Accepted
Set cursor colour different when on a highlighted word
I use this snippet from Damian Conway's fantastic talk, More Instantly Better Vim (at 4m 59s). It causes the entire highlight to blink briefly when you leap between search results.
" Damian Conway's ...
- 30.1k
17
votes
Accepted
Visual select current search result
You can use the gn motion for that, it selects the next searched element.
You can use it like so:
/foo<CR>
gn -> select the next "foo"
sbar<Esc> -> (optional) ...
- 15.6k
16
votes
Accepted
What is the functional difference between :nohlsearch and :set nohlsearch?
From :h :nohlsearch
:noh :nohlsearch
:noh[lsearch] Stop the highlighting for the 'hlsearch' option. It
is ...
- 1,926
16
votes
Accepted
Why do custom highlights in my vimrc get cleared or reset to default?
The problem is that many (all?) colorschemes will clear all highlights with highlight clear before setting their own colours. For example from /usr/share/vim/vim74/colors/peachpuff.vim:
" First ...
- 59.7k
14
votes
Accepted
How to dim characters from :set list
:help 'listchars' mentions:
The "NonText" highlighting will be used for "eol", "extends" and
"precedes". "SpecialKey" for "nbsp", "space", "tab" and "trail".
hl-NonText hl-SpecialKey
...
- 59.7k
14
votes
How to automatically turn off "hlsearch" after I'm done searching?
vim-cool is a simple plugin that does just this.
Vim-cool disables search highlighting when you are done searching and
re-enables it when you search again.
It works without remapping by using ...
- 241
13
votes
Accepted
To print with search results highlighted
Try something like this:
:syntax match Error "yourterm"
or (to ignore case and match "Yourterm", "YOURTERM", "yourTerm" etc.):
:syntax match Error "\cyourterm"
... and print with hardcopy - the ...
- 9,500
13
votes
How do I restore visual mode selection highlighting?
I had this issue as well because I had switched to the "evening" color scheme in my ~/.vimrc file so that my comments were easier to read on a dark background:
:colorscheme evening
To restore visual ...
- 231
12
votes
How to search for lines matching current line in vim
Especially for mapping purposes, I find using getline() more elegant than doing the yanking yourself. Calling getline() with a string '.' returns the line under the cursor. There are two good options ...
- 958
12
votes
Accepted
Why is `:highlight Cursor ...` ignored?
Playing with the Cursor highlight group is a waste of time because the cursor color is handled by your terminal emulator, not by Vim.
- 36k
12
votes
Accepted
How can I highlight matching "%" names (e.g. if/end, for/end) defined by matchit.vim on selection?
I thought this idea was interesting, so I gave it a shot. It will be particularly useful in dense files, such as HTML.
The following script simply lets matchit.vim do what it does while recording ...
- 6,570
11
votes
Accepted
`echon` for `echomsg`
This is not currently possible in Vim.
Internally, :echomsg is implemented as :execute, except that when invoked as :echomsg the result of execution is displayed with the attribute of the last :...
- 8,282
11
votes
Accepted
Auto Highlighting identical lines text
The following match sets seem to work for (A):
:syn match Low /\v(.+)\n(\1\n)/
:syn match Medium /\v(.+)\n(\1\n){2,4}/
:syn match Critical /\v(.+)\n(\1\n){5,}/
:hi Critical ctermfg=red
:hi Medium ...
- 24.4k
11
votes
Accepted
Change color of misspelled words in vim-lexical
The repository says it uses Vim's spellcheck, so you should be able edit your color file's SpellBad highlighting to do this. Something like:
hi SpellBad ctermfg=red guifg=red
You could also put ...
- 7,626
11
votes
Accepted
Is there an incsearch for the replace command?
After a bit of searching, I found this NeoVim issue, which in turn was closed by this PR, which brought me to the inccommand setting. Adding this to my config file:
set inccommand=nosplit
makes ...
- 341
11
votes
Accepted
Echo highlighted warning in one line
This should work:
function! EchoWarning(msg)
echohl WarningMsg
echo "Warning"
echohl None
echon ': ' a:msg
endfunction
call EchoWarning('test')
This defined a simple function that you can ...
- 9,159
11
votes
Enable incremental search and highlight while typing a search term?
This is done by setting just two options: set is hls (incremental search and highlight all matches).
Make sure you've also read the appropriate help topics, excerpted below: :h 'is'
While typing a ...
- 19.2k
10
votes
Accepted
How to color comments after a defined column
Try a contained syntax region:
syn match TooLong contained containedin=pythonComment /\%50c.*/
hi link TooLong Error
Instead of 50, use 80 or 72 or whichever column you prefer.
- 24.4k
10
votes
Accepted
How to highlight/match (but not search!) the word under cursor
For a quick solution, try this:
:nnoremap <F5> :match StatusLineTerm /<C-R><C-W>/<CR>
This uses Ctrl-RCtrl-W to insert the word under the cursor into the command line. See :...
- 30.1k
9
votes
Accepted
Modify vimdiff highlighting
You have a few questions, some explicit and some implicit. I'll try to answer them in order:
What Do These Commands Do?
You're running two commands:
highlight DiffChange cterm=none ctermfg=fg ...
- 1,233
9
votes
Accepted
Where do custom highlighting rules belong?
First question
Highlight definitions belong to your colorscheme. The fact that they are loaded for every buffer, no matter what their language, shouldn't be a problem at all.
If you don't want to ...
- 36k
9
votes
Accepted
How to clear previous search highlight in vim?
You can look in the doc at :h nohl:
When there is a previous search pattern, highlight all its matches.
A useful mapping is the following:
nnoremap <C-l> :nohl<CR><C-L>
...
- 48.1k
8
votes
Auto Highlighting identical lines text
As a starting point, here's a search pattern that matches duplicate lines (ignoring changes in leading whitespace):
\zs marks start of the pattern. Everything before here ...
- 2,898
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
highlight × 249syntax-highlighting × 58
search × 35
vimrc × 24
neovim × 20
colorscheme × 20
vimscript × 18
regular-expression × 14
color × 11
highlighting × 9
folding × 8
terminal × 7
autocmd × 7
spell-checking × 7
command-line × 6
key-bindings × 5
gvim × 5
conceal × 5
whitespace × 4
delimiter-matching × 4
cursorline × 4
cursor-movement × 3
cursor-motions × 3
plugin-system × 3
statusline × 3