在 vim 中可视选择下从光标删除到行尾

Delete from cursor to end of line under visual selection in vim

我有如下代码段。

type Account struct {                                                                                                                                                                                       
    Id                         int                                                                                                                                                                          
    UserId                     int                                                                                                                                                                          
    Name                       string                                                                                                                                                                       
    Address                    string                                                                                                                                                                       
    City                       string                                                                                                                                                                       
    State                      string                                                                                                                                                                       
    CountryId                  string 
}

我想删除所有数据类型。这个有组合键吗?

我尝试了 <C-V> 和 select 所有数据类型的第一个字母在一条垂直线上,希望 d + $ 可以工作 post 但是 vim 只接受第一个输入 d 并删除第一个字母。

使用 <C-v> 进入可视化块模式,select 您要更改的行,然后 D 删除直到这些行结束。

来自 :h v_D :

{Visual}["x]X   or                  *v_X* *v_D* *v_b_D*
{Visual}["x]D       Delete the highlighted lines [into register x] (for
                    {Visual} see |Visual-mode|).  In Visual block mode,
                    "D" deletes the highlighted text plus all text until
                    the end of the line.  {not in Vi}

注意,在帮助中提到,XD在视觉block模式下是不等价的(X只删除当前 selection,直到行尾)。

你可以移动到左大括号,按%键并发出:

s/ \+[^ ]* *$/

获得:

type Account struct
    Id
    UserId
    Name
    Address
    City
    State
    CountryId
}

替换会删除行尾的所有非白色字符space。

  1. 在视觉上 select 所有带有 v6j 的行。
  2. 使用 :'<,'>norm ElD 删除多余的内容('<,'> 会自动为您添加)。

此外,请注意尾随 space!

你可以使用C-V和select所有数据类型的第一列,然后做$到select直到行尾,然后是xd 删除。

不是最短的可能序列,但跟随对我来说更自然

  • vi{ - 视觉上select内段
  • '<,'>norm weld$ (输入为:norm weld$)

分解为

  • '<,'>norm - 在 selection
  • 上应用普通命令
  • wel - 跳转到第一个单词的末尾
  • d$ -删除直到行尾