Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using vim's f command over multiple lines

Tags:

vim

Anyone knows how to quickly find the next occurrence of a character (like the f command) but multi-line? I.e. to quickly jump to the next occurrence of some character in a file?

like image 561
Koko Avatar asked Oct 13 '10 15:10

Koko


2 Answers

Isn't that what "/" does?

If you're looking for the next "x" then do /x while in command mode.

Then you can hit "n" to advance to the next x, and then the next x, etc.

There are lots of vim cheat sheets out there with all kinds of tips.

like image 167
Peter Recore Avatar answered Oct 07 '22 02:10

Peter Recore


There's an example of redefining f to ignore case in the 'eval.txt' help file.

:h eval.txt 

(search for "ignore case" a couple times)

We can modify that to do what you want. Add the following function to your ~/.vimrc file or better yet, create a plugin file: ~/.vim/plugin/find-char.vim (create the directories if you do not already have them).

function FindChar()     let c = nr2char( getchar() )     let match = search('\V' . c) endfunction 

Then, in your ~/.vimrc add the following line:

nmap f :call FindChar()<CR> 

Now, f should work like you want it to.

BTW, this was tested with Vim 7.2 on Ubuntu 10.04.

like image 30
Curt Nelson Avatar answered Oct 07 '22 01:10

Curt Nelson