XVimProject / XVim

Xcode plugin for Vim keybindings
MIT License
5.16k stars 596 forks source link

How to cancel search highlight #540

Open josh-nz opened 10 years ago

josh-nz commented 10 years ago

I have set hlsearch on because I like the behaviour of it. I used it today in xvim for the first time and it works great, but I'm unable to find a way to 'cancel' or reset the search such that when I'm done, my search results are no longer highlighted. I've tried the various methods suggested here:

http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting

but so far the only way I've found is by running :set nohlsearch which then disables it so that subsequent searches are not highlighted.

Is there some other way I can cancel the highlighting, or will I need to bind some keys to turn hlsearch on and off to achieve this, (which will be annoying)?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

JugglerShu commented 10 years ago

Unfortunately there is no way other than set nohls.

:noh is not supporeted now.

josh-nz commented 10 years ago

Ok, thanks for the reply.

zeux commented 10 years ago

Here's a simple patch for this issue:

diff --git a/XVim/XVimExCommand.m b/XVim/XVimExCommand.m
index 0dce310..a2f2d58 100644
--- a/XVim/XVimExCommand.m
+++ b/XVim/XVimExCommand.m
@@ -1014,6 +1014,12 @@ - (void)ncounterpart:(XVimExArg*)args inWindow:(XVimWindow*)window{
     [NSApp sendAction:@selector(jumpToNextCounterpart:) to:nil from:self];
 }

+- (void)nohlsearch:(XVimExArg*)args inWindow:(XVimWindow*)window{
+    NSTextView* view = [window sourceView];
+    [view setNeedsUpdateFoundRanges:YES];
+    [view xvim_clearHighlightText];
+}
+
 - (void)nissue:(XVimExArg*)args inWindow:(XVimWindow*)window{
     [NSApp sendAction:@selector(jumpToNextIssue:) to:nil from:self];
 }
keith commented 9 years ago

In vim I use :let @/="" to clear the search. This would be a great option for XVim, but I could see this requiring some work.