mlsamuelson.com

Select text/code inside braces, brackets, quotes, etc. in Vim

Let's use the following code as an example...

if ($is_true) {
  $value['mes|sage'] = 'Excellent spare ribs, Martha!';
  $value['type'] = 'compliment';
}

And let's say our cursor is that pipe between the two s's in 'message,' above.

Press v to enter visual mode, and then follow that with one of the following

i{

to select text all code within the curly braces. In this case, that's the two $value assignment lines.

i'

will select the word "message," as it is inside 's.

This form of selection also works with (, " and <. Also using p for paragraph, s for sentence, and t for text within html or xml tags.

Substitute i (inner) in the command with a (ambient) to cast a wider net. Personally, though, I find inner selection the most helpful.

No comments

Add your comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

User login