Skip to content
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

Clear hlsearch on Insert #80

Closed
tscheffert opened this issue May 21, 2015 · 2 comments
Closed

Clear hlsearch on Insert #80

tscheffert opened this issue May 21, 2015 · 2 comments

Comments

@tscheffert
Copy link

Love the plugin. Discovered the plugin in a few days ago and have been loving it. Missing one feature I'd like though, exiting hlsearch when pressing insert. In the same way

let g:insearch#auto_nohlsearch = 1

turns off hlsearch after cursor move.

Here is what I have in my .vimrc to achieve the desired effect.

augroup NoHlOnInsert
    au!

    " Exit hlsearch when entering insert as well
    autocmd InsertEnter * :set nohlsearch

    " Reenable it so that future searchs do hlsearch
    autocmd InsertLeave * :set hlsearch
augroup END

Question is three-fold:

  • Is there a better way to do this? Is integrating with incsearch.vim for this sort of thing possible already? I looked through the help doc and tried a few of the autocmd User integration points but couldn't get it working. I feel like I'm stepping on toes doing it this way.
  • Do you see potential in this as a feature for insearch.vim? I'm imaging something like g:incsearch#auto_nohlsearch_on_insert or something.
  • If we arrive at a better way of doing it that integrates with incsearch.vim as is, does it warrant mention in the docs?
@haya14busa
Copy link
Owner

Thanks for the report @tscheffe

Is there a better way to do this?

It should not manipulate user-defined option.

Do you see potential in this as a feature for insearch.vim?

I also tried to clear highlight on insert enter but there are some problem, so I removed the feature in the past.
However, I implement it with saving user configuration getting inspired by your code ✨ Thanks 👍

I merged this feature into dev branch https://github.com/haya14busa/incsearch.vim/tree/dev,
so could you please trying this branch?

@haya14busa
Copy link
Owner

Hi, @tscheffe

I'm sorry but I disable this feature which clear hlsearch on InsertEnter and instead,
I implemented another feature which clear highlight on InsertLeave and first CursorMoved.

The reason why I change this feature is

  1. (implementation & convention) Modifying user-defined option, &hlsearch, is bad idea and I should avoid to do it as much as possible.
  2. (usefulness) IMO, it's useful to retain highlight in insert mode because I can see highlight while editing target text by cgn
  3. (implementation) I came up with a way to deal with feedkeys() in Insert mode in /のあとすぐにコマンドラインに入ると<Plug>(incsearch-nohlsearch)と表示される #82. So it's not necessary to turn off highlight on InsertEnter and remove autocmd! to call feedkeys()

So, I close this issue but thank you for the good request ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants