Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete enclosing braces in Vim?

Tags:

vim

I have the following text:

Monkeys eat {bananas}.

My cursor is in the middle of the word banana:

Monkeys eat {bana|nas}.

Here the | symbol denotes the cursor's position.

How can I delete the braces from there?

I can change bananas to apples with a simple ci}apples, so perhaps I could use a similar trick just to get rid of the { and } characters?

Also, can I do this even in this case, which is actually what I really need to do?

networks {
    local
    is|p
}

(The simplified example above was just to introduce the concept.)

like image 252
Robottinosino Avatar asked Aug 11 '12 21:08

Robottinosino


People also ask

How do I delete a vim bracket?

Now, your compiler (or lint) might tell you that the round brackets in Line 2 is redundant (in this case it is!) You wish to remove the brackets and you might use a combination of the d , x or w command in vim, or even go into INSERT mode and use backspace.

How do I find 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?

lh-brackets simply binds ( to surround the selection with the brackets. Unlike surround it doesn't follow the vim usual keybinding philosophy as does. Instead less keys are required.


1 Answers

Using Tim Pope's excellent surround.vim plugin (which I highly recommend), you would do ds{ for delete surrounding {

I understand that adding another plugin isn't always the ideal solution when you could find a native key sequence instead, but surround.vim is supremely useful, as it can also handle XML/HTML tags and perform enclosures on complex text objects. I regard it as one of those "stuck on a desert island, must have under any circumstance" plugins.

like image 105
Michael Berkowski Avatar answered Oct 20 '22 15:10

Michael Berkowski