Find previous character preceding in vim

Viewed 53

To find the next character in vim I can do:

f ( # to find the next (

How would I do the same to find the previous ( or charater (without using the % )?

3 Answers

you can find the previous ( (in the same line) by pressing F( similarly, you may want to know t, T,,, ;

Do :h F, T.... to see details.

Note that although F( does what you ask for, you might be more interested in [(, which moves back to the most recent unmatched paren. In other words, in the string ( foo ( bar ) baz ), the cursor would move from the r to the 2nd paren, and from the z to the first.

If, rather than simply going to the paren, you're interested in operating on the contents inside the () in some way, you could use Vim "text objects" -- i( and a( refer to the contents "in" and "around" the parentheses. These can be used with any Vim verb, for instance:

ci( change in parens

da( delete around parens

Likewise there are also i[/a[ and it/at for brackets and "tags," (like HTML tags) respectively, and many others as well.

Finally, if you're interested in merely changing the parens to some other kind of delimiter, or in getting rid of them, then take a look at the Vim Surround plugin.

Related