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

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

我正在玩 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

对此:

通过使第二行与第一行相同来使两行匹配:

# 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

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

:g/#/+2d<CR>:<Up><BS><BS>1t.<CR>ZZ

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

答案1

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

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

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

剩下 2 条相同的线。

相关内容