incsearch.vim icon indicating copy to clipboard operation
incsearch.vim copied to clipboard

Help with folding behavior improvments

Open lyndhurst opened this issue 3 years ago • 0 comments

Hi, I have been tinkering with your many incsearch plugins for a while trying to make them play nice with folding, and I have a few questions, observations if you can find the time to help me improve my configuration.

Reading issue #44, I have ended up adding 'zv' after all my 'incsearch-nohl-*' mappings, and it did improve the behavior, but I was not satisfied leaving all the buffer unfolded after navigating through the search matches. I finally added zx, and it got a little better to my taste (e.g. map n <Plug>(incsearch-nohl-n)zx ), now only the matches I jump to are unfolded, but my original fold view is still lost.

This leads me to <Over>(incsearch-*) mappings. For those, adding zv, or zx does not seem to have any effect, which makes sense as, to my understanding, the cursor is not actually moving to the matches. Unfortunately, this makes these very useful (to me) mappings much less useable.

What could make incsearch behave the way I would expect would be to unfold everything with a zn when starting a search, and restore original folding with zN when exiting the search, and, if the cursor moves to a folded match, add a zv to show it. This way, the <Over>* mappings will be useable, the folding restored, and the chosen match visible.

Following that idea, adding a zn to the incsearch mappings is easy, e.g. map / zn<Plug>(incsearch-forward). What is much trickier is to trigger the zN and zv on pressing <Cr>. The only lead I found for that could be the autocmd part of the help file and the IncSearchLeave or IncSearchExecute triggers.

As I am not familiar with vim script beyond hacking away at the config file, I would appreciate your input as to know if what I am trying to achieve is at all possible.

Thanks for taking the time.

lyndhurst avatar Jul 20 '21 13:07 lyndhurst