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 highlights when the cursor moves or a user presses <esc> #1

Open
akinsho opened this issue Aug 20, 2021 · 1 comment
Open

Clear highlights when the cursor moves or a user presses <esc> #1

akinsho opened this issue Aug 20, 2021 · 1 comment

Comments

@akinsho
Copy link

akinsho commented Aug 20, 2021

Hi 👋🏿

This is a really great idea 👍🏿 thanks for making the plugin.

I just started using it and noticed though that after triggering one of the mappings the highlights persist in the buffer and never seem to get wiped till I manually run :nohlsearch I wonder if there could be an option to clear the highlight automatically once the cursor moves or if a user presses esc etc.

@ironhouzi
Copy link
Owner

Hi and thank you so much for wanting to participate and contribute ideas.

I have taken your suggestion into some consideration, and I must admit that it sounds like a good idea. I am however not sure how to implement such behavior in a meaningful way. Personally I have a mapping to quickly toggle highlight:

vim.api.nvim_set_keymap(
  'n',
  '<leader>3',
  ':lua vim.o.hlsearch = not vim.o.hlsearch<CR>',
  { noremap = true, silent = true }
)

In general I often lean towards plugins doing as little as possible, so I leave it to the end user to define additional behavior outside the core functionality. However, I am always open to trying out new things and challenge my preconceived notions.

I am open to implementing this behavior in a separate branch to give myself some time with the new behavior and see if I really like it.

I think I like the latter of your two suggestions more, as I prefer explicit over implicit if I'm not 100% sure that the implicit behavior carries out something I'd manually do 99% of the time. That will just entail a key map:

vim.api.nvim_set_keymap(
  'n',
  '<esc>',
  ':lua vim.b.stim_set = false; vim.go.hlsearch = false<cr>',
  { silent = true }
)

Not sure if I have to set stim_set = false, but it does work.

I will try this new mapping out for some time and if I like it I might include it in the project, either in code or in documentation.
Please try it out and provide feedback.

Thanks again for the great suggestion.

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