I'm trying to implement a search function that finds a pattern and jumps to it without overriding the current searched for & highlighted pattern.
Specifically, I want to be able to type out the pattern and jump to it just like how
? are implemented in neovim; where when I start typing it immediately starts highlighting & jumping in real time. The only difference is that after jumping, I want to keep the previous highlighted/searched for pattern.
I took a look at several pages including this, but the problem is that these solutions only seem to work with pre-specified patterns, whereas in my case I want to type out the pattern via
One solution may be to write a function that stores current pattern, calls
? and after jumping replaces the pattern.
function! ForwardJumpToPattern() let search_original_content=@/ normal! / let @/=search_original_content endfunction
But the problem is that I can't figure out how to call
? from inside a function.