How to select between brackets (or quotes or ...) in Vim?
Solution 1:
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, or :help text-objects
within vim.
Solution 2:
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]
).
I tried this with double and single-quotes and it appears to work there as well. For your data, I do:
write (*, '(a)') 'Computed solution coefficients:'
Move cursor to the C
, then type yi'
. Move the cursor to a blank line, hit p
, and get
Computed solution coefficients:
As CMS noted, this works for visual mode selection as well - just use vi)
, vi}
, vi'
, etc.