azabiong / vim-highlighter

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

Can't highlight a single character #7

Closed JS-Zheng closed 2 years ago

JS-Zheng commented 2 years ago

vim-highlighter version: 0e19263 vim version: 8.2.4700

When entering to the visual mode and selecting a single character, :HiSet will generate empty pattern (i.e., \V) , causing Vim highlights all characters.

azabiong commented 2 years ago

Hi Jason, Thank you for finding this error and opening the issue. I think now the new version 1.39.9 will solve this problem.

JS-Zheng commented 2 years ago

Hi Azabiong, thanks for creating such a useful plug in! It helps me fight many annoying logs. But this issue still exists, the highlight of the single-character cannot work properly.

I think this issue is caused by the following statement in s:GetVisualLine() function:

  if l:left == l:right | return '' | endif

Therefore, I open a pull request #8, for your reference only, to try to solve this issue and this approach can introduce new multi-line highlight feature, by the way.

IMHO, both features (i.e., multi-line, single-char highlight) are very useful. However, some existing features (e.g., HiFind, HiErase) may be affected and still need further verification.

vim-highlight-single-char-demo
azabiong commented 2 years ago

Hi Jason, Thank you very much for your update! It's looks very good! 👍 Could you please upload this text block or send it to me so I can check it?

azabiong commented 2 years ago

And yes, as you noted, support for multiline highlighting is not ready yet. However it's in the future upgrade list.

JS-Zheng commented 2 years ago

My pleasure 😀 That Apache log is adapt from elastic/example project.

azabiong commented 2 years ago

Thank you, I downloaded it. Now, how should I reproduce it or which char should I select?

JS-Zheng commented 2 years ago

Reproduce:

You can choose any single character and not limited to the question mark (i.e., ?). IMHO, you don't need to download that example log, and you can open any text file for testing :)

azabiong commented 2 years ago

Thank you, I'm using 1.39.9, but I couldn't reproduce 1.39.8 symptom... 😅 What should I do...

JS-Zheng commented 2 years ago

Could you highlight a single character in 1.39.9?

In my test (following above reproduce steps):

azabiong commented 2 years ago

Yes, I can highlight single characters in 1.39.9 using v and moving cursor to right l and f enter.

azabiong commented 2 years ago

It seems that v1.39.8 \V was the root cause. If so, I think 1.39.9 will fix that. What do you think?

JS-Zheng commented 2 years ago

What's your 'selection' (i.e., 'sel') setting in Vim? My sel value is 'inclusive', so I don't need to moving cursor left/right after using v.

I guess it may be the problem in s:GetVisualLine():

...
if l:left == l:right | return '' | endif    <----- **this line doesn't consider &selection**
if l:right > 0                                     
  let l:right -= &selection == 'inclusive' ? 1 : 2 
endif   
...                                           
azabiong commented 2 years ago

Wow, you find the issue very quickly! 👍 My selection setting is exclusive, and it shows the difference, as you mentioned!

JS-Zheng commented 2 years ago

My pleasure 😀, very glad to improve this awesome project!

azabiong commented 2 years ago

I think now v1.40 will resolve the issue. It seems to select unicode characters correctly too 😁 I added your name to Credits section h: Hi-Credits

JS-Zheng commented 2 years ago

It works well! Thanks! 😆

azabiong commented 2 years ago

Hi Jason, now Jump to Highlights feature is supported, and I think it can be useful when you analyze logs 😄

JS-Zheng commented 2 years ago

Wow! Great feature and efficient development You're so thoughtful, thanks 😆

JS-Zheng commented 2 years ago

Hi @azabiong, some advices matchadd() doesn't uses 'magic', 'smartcase' and 'ignorecase' options, however, search() uses them. This difference may result in the Jump to Highlights feature jump to a wrong word (e.g., when 'ignorecase' on), which is not highlighted.

azabiong commented 2 years ago

Oh! thanks for the good points! 👍 I'll test and update it right away.

JS-Zheng commented 2 years ago

IMHO, you can disable ignorecase temporarily, for example:

" save ignorecase value
try
    " disable ignorecase
    " do something
catch
    " do something
finally
    " restore ignorecase
endtry

Hope it helps 😉

azabiong commented 2 years ago

Thank you so much! 😄

azabiong commented 2 years ago

Alternatively, it seems straightforward to pass the case-sensitive option '\C' with the pattern to the search() function, like search('\C' . pattern). Now v1.50.2 supports this, thank you! 😄

JS-Zheng commented 2 years ago

It's a better and concise solution, good job! 😆