71

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 search by jumping to the next/previous match and re-highlighting. Using :let @/="", on the other hand, causes the message E25: No previous regular expression and ...


51

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 such as nnoremap <Leader><space> :noh<cr> in your .vimrc. Since my leader is Space, this allows me to clear highlighting simply by tapping ...


42

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 Pmenu ctermbg=gray guibg=gray For Gvim you only need the guibg part (ctermbg is used when Vim is run in a terminal), but I find it useful to always define both. ...


40

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 just use a pipe-like character. Tmux uses │ (U+2502) by default while Vim uses | (U+007C). If you want the same separator in Vim, you can simply use the same ...


34

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 :help nohls *'hlsearch'* *'hls'* *'nohlsearch'* *'nohls'* 'hlsearch' 'hls' boolean (default off) global {not in Vi} ...


33

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 pressed or a fresh search is performed) Clear highlight on pressing ESC nnoremap <esc> :noh<return><esc> Clear highlight on pressing ...


22

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-cterm sounds promising so tab over to it and hit Enter Hmm, cterm={attr-list} and See above for the description of attr-list That last "attr-list" is highlighted ...


16

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 Die Blinkënmatchen: highlight matches nnoremap <silent> n n:call HLNext(0.1)<cr> nnoremap <silent> N N:call HLNext(0.1)<cr> function! ...


16

From :h :nohlsearch :noh :nohlsearch :noh[lsearch] Stop the highlighting for the 'hlsearch' option. It is automatically turned back on when using a search command, or setting the 'hlsearch' option. This command doesn't ...


15

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 remove all existing highlighting. set background=light hi clear if exists("syntax_on") syntax reset endif let colors_name = "peachpuff" hi Normal guibg=PeachPuff ...


15

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) substitute it with "bar" Bonus: To have . repeat the search and the change, use a c to do everything in one command: /foo<CR> cgnbar<Esc> ... -...


13

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 term should be highlighted using the Error highlight rules. (see also this). Here's a pdf sample printed from my vimrc, using :syntax match Error "Plug": If the ...


12

: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 And if we go to :help hl-SpecialKey we read: SpecialKey Meta and special keys listed with ":map", also for text used to show unprintable ...


12

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 the line numbers. Explanations are in the script's comments. matchlines.vim function! s:get_match_lines(line) abort let lines = [] " Loop until `%` ...


11

Playing with the Cursor highlight group is a waste of time because the cursor color is handled by your terminal emulator, not by Vim.


11

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 the CursorMoved and InsertEnter autocommands.


11

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 NeoVim behave almost exactly as I requested in my question. I did not find something equivalent for regular Vim, but I didn't look for it very energetically.


11

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 search command, show where the pattern, as it was typed so far, matches. The matched string is highlighted. If the pattern is invalid or not found, ...


10

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 ctermfg=yellow :hi Low ctermfg=green It seems the order is crucial here. If the Low or Medium matches come after Critical, it gets subsumed by the looser ...


10

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 edit your colorscheme, you can put those highlight definitions in plugin/myhighlights.vim: function! MyHighlights() highlight ... highlight ... ...


10

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 for using this: :exec '/' . getline('.') which parses the strings '/' and what is returned from getline() together and executes that as a vim command. or /&...


10

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 these in your vimrc, but your color file is really the proper place for it. cterm is for terminal vim gui is for gVim The full set of options are cterm ctermbg ...


10

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 mode highlighting I had to also add this: :highlight Visual cterm=reverse ctermbg=NONE


10

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

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 :help c_CTRL-R_CTRL-W.


9

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 :echohl and saved to the message list (reference src/eval.c functions ex_echohl and ex_execute), which is how you get any color on a saved message. The actual ...


9

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> Originally <C-l> redraw the screen, with this mapping you first clear the highlighting and then redraw the screen.


8

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 will not be highlighted ^ start of the line \s* leading whitespace .\+ ...


8

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 call with the warning message as the argument. As you see, the key is the echon command, which is similar to an echo except it does not add a newline at the end....


7

Based on Rich's answer here with some differences: It will highlight the match current indefinitely, I found the blinking annoying, and there's a small 0.1s delay before any other keypress is registered. It incorporates the answer from How can I get ‘n’ to go forward even if I started searching with ‘?’ or ‘#’? You can clear the highlighting with <C-l&...


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