这个 vim 命令是如何工作的`:g/#/+1t.`

Ali*_*Ali 6 vim

我正在玩 vimgolf(顺便说一句,很容易上瘾),我无法理解这个挑战的解决方案之一http://vimgolf.com/challenges/4d1a34ccfa85f32065000004

挑战是转换此文本:

Make the pairs of lines match up by making each second line same as first:

# Appending text:
The name "Vim" is an acronym for "Vi IMproved"
The name "Vim" is an acronym for

# Editing text:
Vim is a text editor originally released by Bram Moolenaar in 1991 for the Amiga
Trivia: Vim is a text editor released by Bram Moolenaar in 1991 for the Amiga

# Deleting text:
Vim has a vi compatibility mode
Vim has a vi compatibility mode but when not in this mode Vim has many enhancements over vi
Run Code Online (Sandbox Code Playgroud)

对此:

通过使每第二行与第一行相同来使成对的行匹配:

# Appending text:
The name "Vim" is an acronym for "Vi IMproved"
The name "Vim" is an acronym for "Vi IMproved"

# Editing text:
Vim is a text editor originally released by Bram Moolenaar in 1991 for the Amiga
Vim is a text editor originally released by Bram Moolenaar in 1991 for the Amiga

# Deleting text:
Vim has a vi compatibility mode
Vim has a vi compatibility mode
Run Code Online (Sandbox Code Playgroud)

我的问题是,这个解决方案的第二行是如何工作的:

:g/#/+2d<CR>:<Up><BS><BS>1t.<CR>ZZ
Run Code Online (Sandbox Code Playgroud)

第二行我的意思是 :g/#/+1t.

Nik*_*RIP 4

您可能已经知道 :g/#/ 对包含 # 的所有行运行命令,这些行是不同挑战的主题。

现在,由于您的第一行已删除“错误”行,因此第二行仅复制剩余的行

您在 # 行上,向前移动一行 (+1) 并将其复制 (t) 到当前行 (.)

剩下 2 条相同的线。

  • 试试吧:帮助:t (2认同)