vim中的这一系列击键如何删除除编号线之外的所有内容?

Non*_*ona 4 vim

通过这个只是中间的卡塔,

Leave only the
numbered lines.
LINE 1
LINE 2
LINE 3
That's all.
Thank you
very much.
Run Code Online (Sandbox Code Playgroud)

以下按键序列是有意义的,并在缓冲区中执行某些操作:

djGd2kZZ
Run Code Online (Sandbox Code Playgroud)

它基本上将命令链接在一起.但是下面做了什么,为什么我不能在缓冲区中看到它?我试着省略"q!" (退出?)命令但是它没有用.

)3:wq!<CR>
Run Code Online (Sandbox Code Playgroud)

Tes*_*ler 5

)是一个运动,其向前跳了一句.一句话是:

*sentence*

    A sentence is defined as ending at a '.', '!' or '?' followed by either the
    end of a line, or by a space or tab.
Run Code Online (Sandbox Code Playgroud)

在这个文件中:

Leave only the
numbered lines.
LINE1
Run Code Online (Sandbox Code Playgroud)

前两行是以点和换行结尾的句子,因此)将光标移动到开头LINE 1.

:wq!<CR> 是保存和退出的常用顺序,在没有提示的情况下进行覆盖.

诀窍是:w 接受范围命令

:[range]w[rite][!] [++opt]

    Write the specified lines to the current file.  This
    is unusual, because the file will not contain all
    lines in the buffer.
Run Code Online (Sandbox Code Playgroud)

并且之前加上一个数字:N: Count和Range

Count and Range                     *N:*

    When giving a count before entering ":", this is translated into:
        :.,.+(count - 1)

    In words: The 'count' lines at and after the cursor.  Example: To delete
    three lines:
        3:d<CR>    is translated into: .,.+2d<CR>
Run Code Online (Sandbox Code Playgroud)

3:w变成:.,.+2w意义写出当前行和以下两行.

)3:wq!<CR>删除除编号行以外的所有内容,它会将编号行保存在原始文件上.当Vim强制退出时,文本的其余部分将丢失.这就是为什么你看不到缓冲区的变化 - 它不会改变.

(过了一段时间我也djGd2kZZ独自完成了这个,并且不知道你可以做[范围]:直到我看到更短的答案).