72 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 ...
user avatar
  • 8,072
53 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 ...
user avatar
52 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 ...
user avatar
  • 13.8k
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 ...
user avatar
  • 33.1k
38 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 :...
user avatar
  • 16.8k
35 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 ...
user avatar
  • 701
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-...
user avatar
  • 18.4k
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 ...
user avatar
  • 28.3k
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 ...
user avatar
  • 1,866
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 ...
user avatar
16 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) ...
user avatar
  • 15.2k
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 ...
user avatar
  • 9,340
13 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 ...
user avatar
13 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 ...
user avatar
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 ...
user avatar
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.
user avatar
  • 33.1k
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 ...
user avatar
  • 6,380
12 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 ...
user avatar
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 ...
user avatar
  • 23.9k
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 ...
user avatar
  • 7,466
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 ...
user avatar
  • 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 ...
user avatar
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 ...
user avatar
  • 17k
10 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 :...
user avatar
  • 8,072
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.
user avatar
  • 23.9k
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 :...
user avatar
  • 28.3k
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 ...
user avatar
  • 33.1k
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> ...
user avatar
  • 46.5k
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 ...
user avatar
  • 2,868
8 votes
Accepted

How to disable search highlight automatically after searching?

I recently wrote a small plugin that seems to do exactly what you want. It works by remapping search-related normal mode commands /?nN*#g*g# and <CR> in command-line mode, and installing a ...
user avatar
  • 33.1k

Only top scored, non community-wiki answers of a minimum length are eligible