Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs
67 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 ...
Martin Tournoij's user avatar
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 :...
DJMcMayhem's user avatar
  • 17.6k
28 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-...
B Layer's user avatar
  • 19.9k
18 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) ...
nobe4's user avatar
  • 16.1k
14 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.
romainl's user avatar
  • 41k
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 ...
Jon Parise's user avatar
13 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 ...
Tommy A's user avatar
  • 6,780
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 ...
Integrator's user avatar
13 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 ...
Matt's user avatar
  • 20.8k
12 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 ...
Tumbler41's user avatar
  • 7,756
12 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 ...
kikito's user avatar
  • 361
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 ...
Karl Yngve Lervåg's user avatar
10 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> ...
statox's user avatar
  • 50k
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.
muru's user avatar
  • 24.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 :...
Rich's user avatar
  • 32.1k
10 votes
Accepted

How to show illegal whitespace (such as unbreakable space) in source code?

List & Listchars 'list' is a boolean option that, when set, instructs vim to display whitespace characters. And it is completely customizable using 'listchars'. For example, to show non-breaking ...
D. Ben Knoble's user avatar
  • 26.4k
10 votes

How to get the highlight group of the word under the cursor in Neovim with Treesitter installed?

Neovim v0.9 The following commands are now available built-in, which do what you want :Inspect " prints as nicely formatted text :Inspect! " prints as a lua table The ...
wardw's user avatar
  • 230
9 votes
Accepted

Automatically highlight all occurrences of the selected text in visual mode

TL;DR: Combine * and # with hlsearch You could highlight by using match and <cword> via an autocommand on an event like CursorHold. But I’m going to show an alternative method. * searches ...
D. Ben Knoble's user avatar
  • 26.4k
9 votes
Accepted

How to highlight cursor line number without cursor line?

You need these three lines: hi CursorLineNr guifg=#af00af set cursorline set cursorlineopt=number The last line removes the highlighting of the cursor line even if cursorline is set and only ...
Jürgen Krämer's user avatar
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 ...
romainl's user avatar
  • 41k
7 votes
Accepted

Automatically call matchadd() in every new window without producing duplicate entries

If I understand correctly, you have the highlight applied to all windows, and not deleted. So, you have two scenarios: A highlight is already active and you open a new window. As the window is opened,...
Luc Hermitte's user avatar
  • 17.4k
7 votes
Accepted

Highlight words with no other occurence in file

The following code defines the command :UniqueWords which tries to do what you want: command! UniqueWords call UniqueWords() function! UniqueWords() abort let words = [] silent! %s/"\zs\w\{-}...
saginaw's user avatar
  • 6,796
7 votes

How can I clear word highlighting in the current document (e.g. such as after searching for a word)?

/asdfasdf This has the advantage that you do not have to type it exaclty. The disadvantage is, that there is a about 1:68719476736 chance in a 4096 byte file that this does not work and your cursor ...
12431234123412341234123's user avatar
7 votes

How to automatically turn off "hlsearch" after I'm done searching?

I have found it more intuitive to remap the Ctrl-L repaint to include :nohls: nnoremap <C-L> :nohls<cr><C-L>
DanG's user avatar
  • 71
7 votes

Is there anything like matchaddpos() but stick the highlight with the character instead of grid?

You can't do that with matchadpos(). This is a known problem with Vim highlighting, and it isn't likely to be solved any time soon. The best you can do is to use matcadd() with a regexp that matches ...
Sato Katsura's user avatar
  • 4,009
7 votes
Accepted

How to highlight a search range?

A If you just want to quickly confirm the validity of the range (and it isn't too long), you can use the built-in :print or :number: :/<head/,/\/head>/print B Another idea would be (mis-)...
Ingo Karkat's user avatar
  • 17.9k
7 votes

Turn off syntax highlighting for TODO items

B Layer's solution works. Another option: Since TODOs are often in comments, if you want the TODO to end up having the same highlighting as regular comments, you can do: :hi link Todo Comment
Barrett's user avatar
  • 71
7 votes

How to highlight/match (but not search!) the word under cursor

Here's how you do this automatically after keeping your cursor still for a short time: :au CursorHold * :exec 'match Search /\V\<' . expand('<cword>') . '\>/' By default, this will ...
thakis's user avatar
  • 261
7 votes
Accepted

How to know which highlighting group is used for the background of a word?

I have the following in my vimrc: command SynID echo synIDattr(synID(line("."), col("."), 1), "name") Move the cursor to the word you are interested in and then execute :SynID. The spell checker ...
Ralf's user avatar
  • 9,237
7 votes
Accepted

IDE-like inline diff highlighting in Vim

You can do this with the vim-gitgutter plugin. If you're not using git, then Signify has a similar feature. After installing vim-gitgutter, you can switch the highlighting on and off with the ...
Rich's user avatar
  • 32.1k

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