Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: changing/deleting up to the end of a "block"

Tags:

vim

editor

When you have a block of text delimitated by brackets or quotes, you can use

ci"
da(

and so on to change that block of text. But is there a way to change or delete from the cursor to the end of that block (in the way cw does it for words)?

like image 219
static_rtti Avatar asked Nov 16 '11 13:11

static_rtti


2 Answers

Use ct) to “correct till closing parenthesis”.

Vim motions with t, f, T and F are very, very useful. :help t, :help f.

Update: If there are nested parentheses where you are:

  • vi)o`` will select till closing parenthese (will select inside parentheses, then switch to other end of the selection and move it to where you were (``)
  • vi)`` will select till opening parenthese (same mechanism, but without needing o)

The first one works only because when you are doing vi) a cursor jump is remembered, and `` goes to previous cursor location. It seems that o in visual mode does not affect this.

like image 59
Benoit Avatar answered Sep 26 '22 01:09

Benoit


Benoit's answer of using t f T and F is the best way that I know of. When it comes to deleting to the end of a parenthesised block you can use ]). This will take into account any nested parenthesis. There is also a corresponding [(, ]} and [{.

like image 21
Greg Sexton Avatar answered Sep 25 '22 01:09

Greg Sexton