Take the 2-minute tour ×

I'm sure there used to be a plugin for this kinda stuff, but now that I need it, I can't seem to find it (naturally). So I'll just ask nice and simple ... what is the easiest way to select between brackets, or quotes, or ... generally a list of matching characters ?

   write ( *, '(a)' ) 'Computed solution coefficients:'

For example, here I'd like to select (a), or Computed solution coefficients:

I'm not interested in multiline, just cases which lay on one line.

share|improve this question
add comment

7 Answers

up vote 116 down vote accepted

Use whatever navigation key you want to get inside the parentheses, then you can use either yi( or yi) to copy everything within the matching parens. This also works with square brackets (e.g. yi]) and curly braces. In addition to y, you can also delete or change text (e.g. ci), di]).

edit: I tried this with double and single-quotes and it appears to work there as well. For your data, I do:


Move cursor to the C, then type yi'. Move the cursor to a blank line, hit p, and get

Computed solution coefficients:

edit: as CMS noted, this works for visual mode selection as well - just use vi), vi}, vi', etc.

share|improve this answer
Doesn't work with separated words. –  ldigas Jun 30 '09 at 6:02
I'm generally looking for a way to select everything between predefined matching chars (normally only single and double quotes, and brackets of all kinds). –  ldigas Jun 30 '09 at 6:03
What do you mean by separated words? I tried it on "[x, y, z]" and it picked out "x, y, z" –  Tim Whitcomb Jun 30 '09 at 6:04
I updated the question - the "Computed ..." part in bold. –  ldigas Jun 30 '09 at 6:08
Disregard the last comment - found what the problem was. Works like a charm :-) –  ldigas Jun 30 '09 at 6:47
show 4 more comments

To select between the single quotes I usually do a vi' (select inner single quotes).

Inside a parenthesis block, I use vib (select inner block)

Inside a curly braces block you can use viB (capital B)

To make the selections "inclusive" (select also the quotes, parenthesis or braces) you can use a instead of i.

You can read more about the Text object selections on the manual.

share|improve this answer
thanks for that tip, I have been searching and asking for something similar and wasn't satisfied with my results. Awesome. –  alfredodeza Nov 18 '10 at 13:38
this tip is very simple and easy to commit inside my brain and muscle memory. thanks. –  Ghazaly Nov 27 '10 at 4:22
Thanks for the link to the docs. –  thorncp Mar 19 '12 at 21:59
You're welcome @thorncp. –  CMS Mar 19 '12 at 22:02
add comment

This method of selection is in built and well covered in the vim help. It covers xml tags and more

:help text-objects

share|improve this answer
:help text-objects gets closer to the useful stuff... you could at least mention some of the common ones, like a" and a( when in visual mode. –  Stobor Jun 30 '09 at 6:22
(Also, +1 because despite being a long-time vim user, I didn't know about these!) –  Stobor Jun 30 '09 at 6:23
@Stobor . Cheers fixed that reference –  michael Jun 30 '09 at 9:39
add comment

For selecting within single quotes use vi' For selecting within parans use vi(

share|improve this answer
Note: ci' or ci( for changing instead of visually selecting. But it does exactly what I wanted. Thanks :) –  Norris May 6 '13 at 10:22
add comment

arrows or hjkl to get to one of the bracketing expressions, then v to select visual (i.e. selecting) mode, then % to jump to the other bracket...

share|improve this answer
(doesn't do quotes, unfortunately, though...) –  Stobor Jun 30 '09 at 6:09
add comment

Write a vim function in .vimrc using the searchpair builting function.

searchpair({start}, {middle}, {end} [, {flags} [, {skip}
			[, {stopline} [, {timeout}]]]])
	Search for the match of a nested start-end pair.  This can be
	used to find the "endif" that matches an "if", while other
	if/endif pairs in between are ignored.


share|improve this answer
add comment

A simple keymap in vim would solve this issue. map viq F”lvf”hh This above command maps viq to the keys to search between quotes. Replace " with any character and create your keymaps. Stick this in vimrc during startup and you should be able to use it everytime.

share|improve this answer
there is a standard vim command for this, no need of keymap –  Adriana Jan 23 '12 at 15:08
add comment

Your Answer


