How to turn off Vim search highlighting - vim

i have a pre-configured .vimrc file under ~/ ,after searching a term through '/' key,all items matched are highlighted,but after i find the need position and hit enter,the highlighted terms are still highlited... it's very disappointing since when i issue --c/"--,the screen is mashed with highlightings.which setting controls search highlighting facility?thanks!

You can issue :nohl to turn off highlighting until the next search. I would recommend mapping that to a key.
:map <F4> :nohl<CR>
If you want to turn off highlighting forever, use :se nohlsearch in your .vimrc

If you type ":nohls<enter>" it will turn off the search highlighting. (The next time you do a search, it will be highlighted, this is not a permanent setting. It is useful for turning off the highlighting for the current search.)
Not sure if that's what you're looking for.

Vim clear last search highlighting

Related

Can I prevent a search in one window from falling through to all windows

I have search highlighting turned on for Vim. If I have a terminal mode Vim split into different windows (displaying different files) and do a search in one, the search falls through to all the open windows and buffers and all occurrences of the search term are highlighted in all windows. Is it possible to restrict this to only the currently active window, with each window and buffer having its own effective search and highlighting?
What about making match group and highlight it. For example
:highlight TEST ctermbg=grey guibg=grey
:match TEST /TODO/
The example creates match group TEST and highlight it with terminal background and gui background set to grey. This is just the idea, you can come up with many clever tricks around it.
:match has limitation, so you might like to read :help :match
Another alternative to highlighting could be the quickfix list. If you use vimgrep /pattern/ % where % is the current buffer, then only search results from that buffer will appear in the quicklist. :cnext to jump through if you don't have Tim Pope unimpaired plugin.
Drew Neil explains this really well in his screencast.
Or the Location List, such as::
nnoremap <leader>* :lvim /<c-r>=expand("<cword>")<cr>/ %<cr>:lopen<cr>

Make Vim highlight all search results while typing the search and turn off highlighting when I do anything else

I would like my Vim to highlight all search results as I am typing my search, i.e. not just the next search result (as in incsearch), but all of them (as in hlsearch but at the same time as I am typing). I would also like to turn off search highlighting as soon as I do anything else than search. Is this possible?
It sounds like you want haya14busa/incsearch.vim. The biggest thing it does is highlighting every result as you are searching, which you can see in this gif:
There are other things it does too. For example, it can be configured to turn of highlighting when you are done searching, and it can also provide useful mappings for other search related features, like
n
N
*
#
g*
g#
You can install it with Neobundle/Vundle/vim-plug by doing
NeoBundle 'haya14busa/incsearch.vim'
Plugin 'haya14busa/incsearch.vim'
Plug 'haya14busa/incsearch.vim'
or with pathogen by doing:
git clone https://github.com/haya14busa/incsearch.vim ~/.vim/bundle/incsearch.vim
You could try the vim-cool plugin, which was mentioned in a similar question:
Vim-cool disables search highlighting when you are done searching and
re-enables it when you search again.
Vim-cool re-enables search highlighting when the cursor is on a word
that matches the last search pattern.
Vim-cool is cool.

How to highlight search words in vim permanently?

I want to highlight the search keyword in Vim. Mainly I use vim to debug the logs.
I always have to use :se hlsearch to highlight the search keyword.
So, I want the solution that it should set command permanently, and I should not use the command always when vim starts.
Set the command in .vimrc.
Use the following commands:
Open ~/.vimrc file (or create it if it didn't exist).
Add set hlsearch in the file.
Save the file.
Now your search will always be highlighted in vim.
For single time use, just use :set hlsearch in vim, which will be in effect for that instance only.
If you want to highlight multiple searches (in parallel, with different colors), check out my Mark plugin; it also allows to persist the highlightings across Vim sessions through the viminfo file; cp. :help mark-persistence.
For those wanting to visually keep highlighted their search:
:syn match stupid "ctrl + /"
:hi stupid ctermbg=Red guibg=Red
Explanation:
The first line add your regex to a syntax type called "stupid" (note that ctrl + / means you must press ctrl+R then / to get the content of the search registry).
The second line gives a red color to the "stupid" syntax regex.
My SelX plugin allows you to highlight and search for many different things at once on a per-tab basis, with different colours. The highlight config can be saved to a vim session
https://www.vim.org/scripts/script.php?script_id=5875

Cycling and/or highlighting through a vim selection

The feature I am thinking of is kind of inspired by a feature that I really like about sublime text.
In sublime text, if you select a sequence of characters, it automatically puts a little box around it (to distinguish it from the word that you just highlighted). For me, this is very helpful because I can see and find specific things of the code much faster.
It would be awesome to have something similar to my vim environment. It does not have to be exactly the same as the one in sublime though, but it would be awesome if it were as similar as possible plus the additional feature to easy cycling through similar words.
Currently, what I am doing is highlight the work I want and then manually typing it to the search command /. It would be much better if I can just highlight it in visual mode and then automatically highlight similar words on the current screen with a different colour from the highlighting in visual mode and then have a quick key short cut to cycling through them, if I wished to do that.
I am not sure if a there exists a plugin or something that already does that, but that would cool! Ideally, I would want to to know as many details of the commands/changes to the vimrc file, so that I have the most control over this feature and be able to customize it as I wish.
You can get the highlighting you are looking for by enabling the hlsearch option:
:set hlsearch
It will highlight every occurrence of the last search pattern and thus work after all the following commands (and their relatives):
/foo<CR>
?bar<CR>
:s/fizz/buzz/g
*
#
You can use n to jump to the next occurrence in the direction of your search and N to do the same in the opposite direction.
To highlight every occurrence of the current word "without" moving the cursor, you can simply do:
*N
or:
*``
to jump to the next occurrence and jump back immediately.
Doing the same for visually selected text is a bit trickier but still possible…
either via a lightweight plugin like visualstar or The Search Party,
or with a tiny bit of crude vimscript in your ~/.vimrc:
" this function cleans up the search pattern
function! GetVisualSelection()
let old_reg = #v
normal! gv"vy
let raw_search = #v
let #v = old_reg
return substitute(escape(raw_search, '\/.*$^~[]'), "\n", '\\n', "g")
endfunction
" map * and # in visual mode so that they do the same as *N and #N in normal mode
xnoremap * :<C-u>/<C-r>=GetVisualSelection()<CR><CR>N
xnoremap # :<C-u>?<C-r>=GetVisualSelection()<CR><CR>N
My SearchHighlighting plugin changes the * command so that it just toggles the highlighting for the current word, without the movement to the next match (for which you can press n, or pass a count). This also works in visual mode, using the selection. I find this very handy for highlighting all matches.
There's also a mode that automatically highlights the current word / selection, like what many IDEs offer.
Other plugins
If you want more permanent highlighting, separate from searching, the Mark plugin offers that.
To get an orientation about the number of matches (without highlighting them), I have the SearchPosition plugin.

Emacs style highlighting for inc-search in vim

I realize that this question has been posed before on this forum, but I didn't find an answer so here goes..
In Vim, is there a way to enable on-the-fly highlighting for all matches when searching?
If I enable incsearch and type "/something" it will highlight the first match only. If I enable hlsearch and type "/something", nothing happens until I press enter (it only highlights the previous search).
In emacs the first match will be highlighted, and (after a slight delay) all other matches on the screen are highlighted in a different color, giving almost instant feedback when scanning for matches in a piece of code.
use the n-search feature of easy-motion , it does exactly what you need(look in the gif demo)
BONUS: it also dims down the background for you that really makes searching easy
https://github.com/Lokaltog/vim-easymotion#n-character-search-motion
You can do this with the incsearch.vim plugin:
You need to first install the plugin and bind <Over>(incsearch-...).
You are looking for :set incsearch together with hlsearch. However all hits will have the same color.

Resources