标签云

微信群

扫码加入我们

WeChat QR Code

I search for "nurple" in a file.I found it, great.But now, every occurrence of "nurple" is rendered in sick black on yellow.Forever.Forever, that is, until I search for something I know won't be found, such as "asdhfalsdflajdflakjdf" simply so it clears the previous search highlighting.Can't I just hit a magic key to kill the highlights when I'm done searching?


possible duplicate of Vim clear last search highlighting

2019年04月22日12分27秒

/<mash keyboard>

1970年01月01日00分07秒

Definitely a duplicate of stackoverflow.com/questions/657447/… and should be closed to direct people there

2019年04月22日12分27秒

BenCreasy why would one call an older post a duplicate of a newer one?

2019年04月22日12分27秒

Ruslan that one has nearly 10 times as many upvotes and they're both pretty old ('08 and '09)

2019年04月22日12分27秒

Oooh, that's a goodie.I've been using /<ENTER> which works as long as there's no in my files.I must modify my vimrc NOW!

2019年04月22日12分27秒

This is great, cured a lot of my headaches!I think ,it's better to use the full command in vimrc (:nohlsearch) to avoid conflicts in future.

2019年04月22日12分27秒

<leader>c :nohl<CR> is a better option, I think.

2019年04月22日12分27秒

trillions - ctrl-l will only work if you start vim after editing .vimrc as shown.

2019年04月22日12分27秒

Thats what I had been looking foreven after 6 years. May be too late. :)

2019年04月22日12分27秒

Fear not, the highlighting returns with the next search. The command should probably be named clearhighlight.

2019年04月22日12分27秒

Four years late, but thanks.This is good stuff.

2019年04月22日12分27秒

kmarks2 see you next leap year, I guess?

2019年04月22日12分27秒

Just clarifying steamer25's comment.:set nohlsearch turns off search highlighting completely :nohlsearch or :noh will clear the current highlight, but leave you in hlsearch mode for the next search.

2019年04月22日12分27秒

Doing this in front of someone who knew Vim better than I did is how I learned about :nohls.

2019年04月22日12分27秒

That's gross! It adds lkjasdf to your search history.

2019年04月22日12分27秒

then make :noh faster for you: nnoremap <leader>h :noh<cr>

2019年04月22日12分27秒

Can't you just program vim to never include lkjasdf in the search history? Though, no, wait, that would be more of an Emacs solution...

2019年04月22日12分27秒

i came to the same conclusion, years ago, thanks mate

2019年04月22日12分27秒

Why is this not higher rated, this is simpler and more intuitive than a lot of the methods above.

2019年04月22日12分27秒

Love this! Thanks!

2019年04月22日12分27秒

Two questions: 1. why is the 2nd <Esc> necessary in the replacement? 2. do you know how to (temporarily) disable the escape bell for this?

2019年04月22日12分27秒

This can also be accomplished with the "invhlsearch" setting.

2019年04月22日12分27秒

I like this, but I think your i mapping would be better with gi instead of a. Either that or <C-o>:set hls!<CR>.

2019年04月22日12分27秒

but F12 is my yakuake key :(

2019年04月22日12分27秒

On a side note, it's weird that one has to :noh to turn off search highlighting while instead of :hlsearch one has to set hlsearch to turn it on again. (I guess I should't be surprised at vim "weirdiness"...)

2019年04月22日12分27秒

map <leader>c :nohl<CR> would be what you need in vimrc.

2019年04月22日12分27秒

nnoremap <silent> <C-l> :let /=""<CR>

2019年04月22日12分27秒