Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - delete until (inclusive) character in multiple lines

Tags:

vim

vi

I have this code:

def foo(c: Char) = c match {
    case 'a': 'B'
}

My cursor is on the space after =. I want to delete everything until, including, the }. How can I do that?

Can I do the same where the cursor is anywhere on the first line? Anywhere in the block (and place the cursor after the =)?

like image 520
IttayD Avatar asked Nov 13 '13 12:11

IttayD


People also ask

How do I delete a specific character in Vim?

Yes, use the "till" motion. means delete until a ". There is also the "find" motion, which deletes up to and including the character.

How do I delete a range of lines in Vim?

Press ESC to go to Normal mode. Place the cursor on the line you need to delete. Press dd . This will delete the current line.


1 Answers

d/}/e

does the job.

d/} deletes until the } but adding the /e flag moves the cursor on the last char of the match, effectively deleting everything between the cursor and the }, inclusive.

Using visual selection works too, in a slightly more intuitive way:

v/}<CR>d
like image 177
romainl Avatar answered Sep 22 '22 19:09

romainl