64
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 ...
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 :...
39
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 ...
26
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-...
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) ...
15
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
...
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.
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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>
...
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.
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 :...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
7
votes
Accepted
How to search for lines matching current line in vim
Here's how I'd do it:
Yank the line (into the unnamed register), without including the newline at the end: 0y$
Initiate a very nomagic search: /\V
Add the yanked line: <c-r>"
Fire off the ...
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\{-}...
7
votes
How to search for lines matching current line in vim
The existing answers all fail if your line contains certain items that are interpreted as a part of a pattern. The \V point gets most of the way there but still messes up with the backslash.
Try this ...
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,...
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>
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
highlight × 259syntax-highlighting × 60
search × 37
vimrc × 24
neovim × 23
colorscheme × 21
vimscript × 19
regular-expression × 14
color × 11
highlighting × 9
autocmd × 8
folding × 8
terminal × 7
spell-checking × 7
key-bindings × 5
command-line × 5
gvim × 5
conceal × 5
vimdiff × 4
whitespace × 4
delimiter-matching × 4
cursorline × 4
cursor-movement × 3
cursor-motions × 3
plugin-system × 3