Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete everything between two brackets in Vim, including newlines

Tags:

vim

vi

Say I have the following python array literal:

def f():
    arr = [
        1,          
        2,
        3   
    ]  

I want to delete everything in the brackets so that it becomes this:

def f():
    arr = [] 

How can I do that with minimal commands in vim?


These are some of my attempts:

  • Using di] will delete the text, but not the empty newlines, leaving a lot of whitespace I'd have to delete:

    def f():
        arr = [         
        ]
    
  • Using da] will delete the newlines, but also the brackets:

    def f():
        arr =
    
like image 211
Migwell Avatar asked Oct 24 '16 00:10

Migwell


1 Answers

You can simply do:

ca[[]<Esc>

or:

ca][]<Esc>

See :help text-objects.

like image 125
romainl Avatar answered Sep 29 '22 21:09

romainl