43

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 ...


31

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 ...


29

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 ...


24

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} ...


18

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 ...


15

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

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. ...


14

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

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! ...


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

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 ...


11

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 ...


11

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 `%` ...


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

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

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.


9

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 ... ...


9

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 /&...


9

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.


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 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 ...


8

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


8

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

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


8

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.


7

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 ctermbg=Red gui=none guifg=fg guibg=Red highlight Normal term=none cterm=none ctermfg=White ctermbg=Black gui=none guifg=White guibg=Black Both of these commands ...


7

: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 ...


7

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\{-}\ze"/\=add(words, submatch(0))/gn let dic = {} let uniq_words = uniq(sort(copy(words))) for i in range(len(uniq_words)) if uniq_words[i] != ...


7

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 cursorMoved autocommand.


7

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 on line 1, and anchor it at the first a. Perhaps like this: :call matchadd('Error', '\%1l[^a]\zsa')


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