Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select between brackets (or quotes or ...) in Vim?

People also ask

How do I switch between brackets in vim?

You can easily use the % key to jump to a matching opening or closing parenthesis, bracket or curly brace. You can also set the option showmatch . The cursor will briefly jump to the matching bracket, wen you insert one.

How do I add a bracket in Vim?

Explanation. If you want to put the word under the cursor in to brackets this is viwc()<Esc>P . viw will v isually select all charactrs i n a w ord. c() will c change the selection and by dropping you into insert mode, where you type the characters ( ) .


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.


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.


This method of selection is built-in and well covered in the Vim help. It covers XML tags and more.

See :help text-objects.


For selecting within single quotes use vi'.

For selecting within parenthesis use vi(.