vim searches

vim is a very powerful editor once you can remember a few command combinations.

The basic search is invoked with / (or ? if you want to go backwards).

Of late I have been using the character find command f (especially in visual mode, vf[char] is extremely useful as would yf[char].

For the uninitiated these select until the next character (or with y copy [yank] into the default buffer).

Yesterday I found in the help files the * and # commands.

* is search forward for the word under the current cursor (# is the backwards version).

Another useful option is t which searches for a character but stops one character before. So yt) will copy upto the next closing bracket or y2t) will copy til the second following bracket!

This is also useful for extracting the contents of a parameter list:


Enter visual mode, back one word go to matching brace, back one word then delete (and copy into default buffer).

This is a lightweight refactoring in itself.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s