azabiong / vim-highlighter

Highlight words and expressions
MIT License
226 stars 9 forks source link

Feature request: highlight a large visual selection (possibly on multiple lines) #22

Closed dubrayn closed 1 year ago

dubrayn commented 1 year ago

Hello, this plugin is very nice. I use it to show some parts of code to students / coworkers. One thing is missing IMHO: the possibility to highlight EXACTLY the current visual selection.

For example, for the given buffer content:

test0 test1 test2
test3 test4

If I select (in visual mode) the first test occurence of the first line, the command :<C-U>Hi +x<cr> will highlight the three occurences of test of the first line. I would like to highlight only the first occurence of the first line.

If I select (in visual mode) both lines, no single command will allow me to highlight both lines.

If I select (in visual mode) some part of both lines, no command will allow me to highlight this exact selection.

Maybe am I missing some magic trick ?

Thanks anyway for the nice plugin.

azabiong commented 1 year ago

Hi, thanks for using this plugin and suggesting very useful features. I think it would be great if these things are gradually supported.

As for the first function, I think we can implement it like coloring a specific location with a marker pen. Regarding multi-line visual mode highlighting, I'm looking for a nice way to easily turn it on and off with a rectangular shape.

I will try to support the first feature first and let you know when there is an update. Thanks.

azabiong commented 1 year ago

Hi, There are some updates on this. Position-based highlighting using visual-block mode selection is now supported.

Positional Highlight

Would you like to try it?  It's quite a different type, but I think it can be useful sometimes.

As for multi-line highlighting, I'm not quite sure whether it should be positional or pattern-based highlighting. I guess I need to find out more.

dubrayn commented 1 year ago

Hi, thanks for the new version.

There seems to be a bug with it when I use the command :Hi +x%<cr> in normal mode, after having made a visual selection :

Error detected while processing function highlighter#Command[25]..<SNR>81_SetHighlight[25]..<SNR>81_GetVisualBlock:                                                                                     
line   13:
E951: \% value too large

This error is not present on commit c2412c1 of vim-highlighter.

Let me know if I can help with the debug.

azabiong commented 1 year ago

Thank you for checking this! I found that this happens when the selection mode is inclusive. Now, there is an update. I think it should work now.

dubrayn commented 1 year ago

It works with a visual block now but not with a visual line (S+v).

azabiong commented 1 year ago

Yes, right. Would you please try the fixed version 1.57.3 ?

dubrayn commented 1 year ago

I do not see any version more recent than 34837cb and this version has the error.

azabiong commented 1 year ago

Thank you for checking it. That's the 1.57.3. On my side, there is no more E951 error in both inclusive and exclusive selection mode. Are you still getting the error message? Or only one line is selected?

dubrayn commented 1 year ago

I have the message if :

  1. one or more lines are selected in 'visual line' mode, then
  2. I go back to normal mode, then
  3. I use :Hi +x%<cr>.

If only one line was selected in 'visual line' mode, the highlighting is fine (but there is the annoying error message). If more than one line was selected, I see the message and no highlighting is done (as expected from your explanation "Regarding multi-line visual mode highlighting, I'm looking for a nice way to easily turn it on and off with a rectangular shape.").

azabiong commented 1 year ago

Thanks for your update. I am trying to reproduce this issue, but it's not easy... Would please try :Hi command to check the version, and may I ask what version of vim are you using?

dubrayn commented 1 year ago

:Hi returns Highlighter version 1.57.3, and I am using Neovim v0.10.0-dev-380+gc855eee91.

azabiong commented 1 year ago

Thank you! I will try it.

azabiong commented 1 year ago

I found it! I'm sure 1.57.4 will fix the problem this time. The point was whether the current mode was case sensitive or not when the set ic option is enabled. The new version now uses the option independent '==#' operator instead of '=='.

dubrayn commented 1 year ago

I confirm that the error message is gone. Thanks a lot for the fix !

azabiong commented 1 year ago

Great! Thanks for confirming that it works.

azabiong commented 1 year ago

Hi, there is a nice update to this feature!

The plugin now uses new APIs from Neovim and Vim that supports buffer-associated highlights. The highlight positions are now managed smoothly when editing text. Multiline highlighting is now also supported.

New version →  Positional Highlight

It looks like all requested features are now implemented. I hope you like this update! Thanks.

dubrayn commented 1 year ago

It works nicely, thanks.

azabiong commented 1 year ago

Thank you for your confirmation! Then it seems that all three features you mentioned are implemented. Can I close the issue? And if you don't mind, I'd like to add your name to the credits section of the help file for this great feature. :h Hi-Credit So, may I ask your name?

dubrayn commented 1 year ago

Hello, you can close the issue, thanks again. You can use my name for the credits if you want (not sure that I helped in any constructive way) : N. Dubray

azabiong commented 1 year ago

Nice! I think this feature is very special and enabled highlighter's original function properly. Thank you for your great feature suggestion and help in resolving the problem quickly. I added your name to the credits section. :h Hi-Credits Thank you!