-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to make Esc clear search highlight? #2719
Comments
|
I'm assuming that the above should be put in dotspacemacs/config (at least, putting it into dotspacemacs/init results in an error because evil-search-highlight-persist-map is not defined yet). However, it does not work in terminal or GUI mode - using emacs-mac-port at least. I verified that replacing "ESC" with "C-k" works (as in, ctrl+k clears the highlight), so the code is being executed but does not work... |
Maybe try:
|
This does not work either. Before I load the file, when I press Escape I see ESC prompt in the command bar - as if it's waiting for a second key in the chord. Using |
I'm out of ideas -- I didn't test it -- just proposed it :( |
@zeux Try |
@person808 Interesting. So before I open any file after I open a file P.S. All of this is in the default setup - the only changes to .spacemacs are the addition of define-key. |
Hmm, even if I execute define-key after I open a file via |
Okay, this seems to work (when executed as part of dotspacemacs/config):
This overrides 'evil-force-normal-state but I can still exit out of insert mode using Esc - probably because the map is only active when normal mode is on... |
Be careful, I think this might screw with some of the operators in evil mode, but I can't be sure. Just to be safe you may want to write a function which calls evil-force-normal-state as well as evil-search-highlight-persist-remove-all and bind that to escape in normal mode just to make sure you don't clobber some important functionality. |
Any way I can globally change highlight results to turn off after searching with / and hitting RET? And is there a key binding to toggle last search result highlighting (in vim: :set hls! )? |
Exclude |
@ndan to be honest - I forgot what this was about. Haven't used Spacemacs in a while but recently I've re-installed it. It appears the behaviour is the same with or without I'm using search now and it seems ok. One thing which isn't the same (when compared with Vim usage), is that I cannot figure out how to toggle highlighting of all matches of last search result. Any ideas? Thanks! |
@justin-calleja (evil-ex-search-activate-highlight evil-ex-search-pattern) This highlights the previous search pattern. When it's called from the |
@duianto I'm not sure what you're suggesting. If it's too much customisation (e.g. writing Lisp code) - I'm afraid that'll have to wait until I learn more ^^; btw, in case it's not clear what the desired effect is, I recorded this: Cheers |
Sorry for being unclear. Here's some code that you can put into your (defun toggle-search-pattern-highlight ()
"Toggle the previous search patterns highlight On or Off."
(interactive)
(if (evil-ex-hl-active-p 'evil-ex-search)
(evil-ex-nohighlight)
(evil-ex-search-activate-highlight evil-ex-search-pattern)))
(global-set-key (kbd "<f8>") 'toggle-search-pattern-highlight) To make it work, first save the
Now the Any corrections/improvements are welcome, if someone knows of a better way to accomplish this. |
Thanks @duianto :) Unfortunately... it's not working for me ^^; Here's my (defun dotspacemacs/user-config ()
"Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
(defun toggle-search-pattern-highlight ()
"Toggle the previous search patterns highlight On or Off."
(interactive)
(if (evil-ex-hl-active-p 'evil-ex-search)
(evil-ex-nohighlight)
(evil-ex-search-activate-highlight evil-ex-search-pattern)))
(global-set-key (kbd "<f8>") 'toggle-search-pattern-highlight)
) I've restarted Emacs - tried searching - and then hitting F8 (or fn + F8, or SPC + F8). Maybe I have some config getting in the way of this working. Would it be possible to make the key combination the following 2 characters inside quotes: "`/" ? Neither of these are really important though - so if you're busy don't worry about it. |
Your right, it only works on the develop branch, not on the master branch, I should have tested both. |
@duianto no problem my friend. Thanks! |
Update:Unfortunately I haven't been able to get it to work 😞 The master branch uses another |
It doesn't matter what |
@duianto don't worry - thanks anyway. I'll stop replying with "thanks msgs" here - using Gitter :) @robbyoconnor and |
Sorry for reviving a 3 year-old issue but as I struggled to have ;; This section should already exist in your .spacemacs file
(defun dotspacemacs/user-config ()
(defun custom-evil-force-normal-state ()
"Delegate to evil-force-normal-state but also clear search highlighting"
(interactive)
(evil-force-normal-state)
(spacemacs/evil-search-clear-highlight)
)
(define-key evil-normal-state-map (kbd "<escape>") 'custom-evil-force-normal-state)
) Basically we define There may be cleaner/more efficient ways of achieving this, but at least this seems to work for me 😄 |
Appease my muscle memory for how to toggle search highlighting on and off. It turns out I've used that F2 key mapping for ":nohls" for so long I miss it when it's gone. Tested this solution and it works great. I may not need all that belt-and-suspenders stuff for defining the key binding. Polish that up later. Credit: syl20bnr/spacemacs#2719 (comment)
(advice-add 'evil-force-normal-state :before #'evil-ex-nohighlight) |
My understanding is that the official way to clear is 'SPC s c'. Which is verbose.
In all Vim-like editors (including Vim, ViEmu, Sublime Text + Vintageous and XCode + XVim) that I use or used in the past, it's either the default or you can set up Esc in normal mode to clear search highlight.
In Vim you can do it using this map (http://www.viemu.com/blog/2009/06/16/a-vim-and-viemu-mapping-you-really-cant-miss-never-type-noh-again/):
By now it's impossible for me to switch to anything else. Not to mention that dismissing highlight is frequent and Esc is way easier to hit than 'SPC s c' (or ':noh<cr>').
So, is there a way I can set up the same behavior for spacemacs?
The text was updated successfully, but these errors were encountered: