VIM Restore last search pattern

After typing '/' or '?' for begin the search, just use up-down arrow to bring the search buffer line by line.


You can probably do it by hand by saving and restoring the "/ register. However, a better way is to just move your code into a function; returning from a function automatically restores it. To quote the VIM documentation:

                                                                                                                              *function-search-undo*
The last used search pattern and the redo command "." will not be changed by the function. This also implies that the effect of |:nohlsearch| is undone when the function returns.

This would look something like this in your .vimrc:

function! Ayman_NextSection
    /?section /
endfunction
nmap ]] call Ayman_NextSection()<CR>

Hope that helps.

Tags:

Vim