azabiong / vim-highlighter

Highlight words and expressions
MIT License
237 stars 11 forks source link

Feature request: replacement #21

Open elkarouh opened 1 year ago

elkarouh commented 1 year ago

Hi, I recently switched from emacs to vi and I miss some functionality from this emacs package https://github.com/wolray/symbol-overlay When the cursor is on a highlighted word, pressing the r key will prompt you for a replacement. This is very handy when programming. Another question: in the emacs plugin, when the cursor is on a highlighted word, a specific mode is entered and pressing n or p will bring you to the next or previous highlighted word. Is it possible in vi to have the same functionality? Thanks for the great work 👍

azabiong commented 1 year ago

Thanks for your interest in this plugin. As for replacement, I mainly use the language server plugin function which supports scope based replacement. Sometimes, I use the following mapping in normal mode to replace the word under the cursor:

nn <leader>r  "ryiw:%s/\V<C-R>r\C//gc<Left><Left><Left>

To navigate through the selected text, you can use the * key to select a pattern, then use the n and N keys.

elkarouh commented 1 year ago

Thank you for responding. What you propose are work-arounds. My question essentially boils down to : is it possible to enter a minor mode in which the major mode key bindings are overridden. In normal circumstances, i want r to perform single letter replacement, but when the cursor is on a highlighted word, i want to be prompted for replacement of all occurrences of the word.

jqhr commented 1 year ago

I need this feature too. Because some text with "-" or other non keyword can not distinguish by , so I offten use visual mode to highlight those text. Until now, I have not find any better way to replace those text.

azabiong commented 1 year ago

Alright, then I will try highlighting when replacing, and let's see if it's convenient. Thanks.

jqhr commented 1 year ago

Thx

azabiong commented 6 months ago

The plugin can now select the correct highlight at the cursor position when multiple highlights overlap. We can easily check this using the latest version of the HiErase function. So, it looks like the plugin is now ready to accept input for this new feature! 😄 Separately, I discovered a very powerful plugin for the replacement function: https://github.com/nvim-pack/nvim-spectre And also, I found a very interesting video about refactoring: https://www.youtube.com/watch?v=oQB8lYUZtrY