如何在Vim中删除单行和多行?

Vim provides different keyboard and command shortcuts. One of the most used action is delete . Vim provides a lot of different use cases for deleting single and multiple lines.

Vim提供了不同的键盘和命令快捷方式。 最常用的操作之一是delete 。 Vim提供了许多不同的用例来删除单行和多行。

删除当前行 (Delete Current Line)

Vim has cursor which will reside current active location. We can delete this line completely with the D or dd command.

Vim具有光标,该光标将位于当前活动位置。 我们可以使用Ddd命令完全删除此行。

D

Or

要么

dd

删除到当前行的末尾 (Delete To The End Of The Current Line)

Another useful shortcut for deletion is deleting from cursor to the end of current line.

删除的另一个有用的快捷方式是从光标删除到当前行的末尾。

d$

删除到当前行的开头 (Delete To The Start Of The Current Line)

We can delete from current cursor positions to the start of the current line with the following command.

我们可以使用以下命令从当前光标位置删除到当前行的开头。

d0

删除指定的行数 (Delete Specified Number Of Lines)

We can specify the line count we want to delete. We will use d command two times where we will put the line count between d commands like below. We will delete 5 lines from current line.

我们可以指定要删除的行数。 我们将使用d命令两次,然后将d命令之间的行数放入如下所示。 我们将从当前行中删除5行。

d5d

删除当前词 (Delete Current Word)

Words are separated with spaces from each other. We can delete current word where cursor locate can be delete with the following command.

单词之间用空格隔开。 我们可以使用以下命令删除当前单词,从而删除光标所在的位置。

dw

删除到文件末尾 (Delete To The End Of File)

We can delete from current location where cursor blinks to the end of file with the following command.

我们可以使用以下命令从光标闪烁到文件末尾的当前位置删除。

:1,$d

删除到文件开头 (Delete To The Start Of File)

We can also delete from current location where cursor blinks to the start of the line with the following command.

我们还可以使用以下命令从当前位置删除光标闪烁到行首的位置。

:.,$d
LEARN MORE  Vim Undo and Redo Operations
了解更多Vim撤消和重做操作

翻译自: https://www.poftut.com/delete-single-multiple-lines-vim/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值