删除 Vim 中两个括号之间的所有内容,包括换行符 [英] Delete everything between two brackets in Vim, including newlines

查看:39
本文介绍了删除 Vim 中两个括号之间的所有内容,包括换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下 python 数组文字:

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 = [] 

如何在 vim 中使用最少的命令来做到这一点?

How can I do that with minimal commands in vim?

这些是我的一些尝试:

  • 使用 di] 将删除文本,但不会删除空的换行符,留下很多我必须删除的空格:

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

def f():
    arr = [         
    ]

  • 使用 da] 将删除换行符和括号:

  • Using da] will delete the newlines, but also the brackets:

    def f():
        arr =
    

  • 推荐答案

    您只需:

    ca[[]<Esc>
    

    或:

    ca][]<Esc>
    

    参见:help text-objects.

    这篇关于删除 Vim 中两个括号之间的所有内容,包括换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆