简体   繁体   English

vim:如何删除空格直到第一个字符?

[英]vim: how to delete spaces till the first character?

I have a line like this:我有这样一行:

      foobar

as you can see there are many spaces between the first column and 'foobar'.如您所见,第一列和“foobar”之间有很多空格。 If I have the cursor in the first column, is there any key binding to remove the spaces till 'foobar'?如果我在第一列中有光标,是否有任何键绑定可以删除空格直到'foobar'?

d w d w ^

Will delete all the whitespace if you're on the first column.如果您在第一列,将删除所有空格。

dtf

Delete Till F删除直到 F

There is no other easy command.没有其他简单的命令。 You could use a regex, but that'd be more painful to write.您可以使用正则表达式,但编写起来会更痛苦。

My bad, @Mat's answer is even better ( dw ).我的错,@Mat 的答案更好( dw )。

The simple answer is简单的答案是

dw

...which performs [d]elete [w]ord. ...执行 [d]elete [w]ord。 If you want to remove all whitespace in the whole document before all occurences of "foobar":如果要在“foobar”出现之前删除整个文档中的所有空格:

:%s/^\s*foobar/foobar/

use :%s/\\s\\+$//e使用:%s/\\s\\+$//e

\\s stands for space and tab + find one or more occurence \\s 代表空格和制表符 + 查找一个或多个出现

You can find more details in Remove unwanted spaces您可以在删除不需要的空格中找到更多详细信息

Way 1: Go to the line, and :s/^ *//g方式1:转到该行,然后:s/^ *//g

Way 2: Go to the first blank space of that line and press dw方式2:转到该行的第一个空格并按dw

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM