Take the 2-minute tour ×

Is there a way to jump to a fixed string in VIM without affecting the search history?

Say I want to use the key ;f to jump to the next function, and ;s to the next section.

I can do this:

nmap ;f /function<CR>
nmap ;s /section<CR> 

These work fine, but they overwrite the last search pattern. I want to jump nut keep the old search string.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You can call vim function search()

nmap ;f :call search('function')<CR>
nmap ;s :call search('section')<CR> 
share|improve this answer
Also depending on your language you might want to look at ]]. See :h ]] for more information. –  Peter Rincker Jul 19 '12 at 13:14
add comment

kev's answer is simple and fine; for a more advanced approach, you can use my CountJump plugin. With it, you can define mappings that jump backward / forward to the [count]'th occurrence of function, beep when there are no more matches, etc.

share|improve this answer
That's a good plugin. –  Ayman Jul 19 '12 at 12:41
add comment

Your Answer


