如何在当前行之后加入上面的行?

Rem*_*man 6 vim join lines

我在Vim中知道这些命令:

J:在当前行
-J 之后加入下面的行:在上面的行之后加入当前行

但是如何在当前行之后加入上面的行?

dou*_*own 5

您也可以使用 ex 命令

:m-2|j
Run Code Online (Sandbox Code Playgroud)
  • m-2具有将当前行移动到其当前位置上方 2 行的效果;这会切换当前行和上面行的位置。
  • j连接当前行和上面的行,在两者之间插入一个空格。使用j!,如果你不想要的空间。
  • | 将 2 个前命令分开

此前命令是编写以下内容的简短方法

:move .-2
:join  
Run Code Online (Sandbox Code Playgroud)


rom*_*inl 1

有很多方法可以做到这一点。一种是 \xe2\x80\xa6 删除上面的行并将其附加到下面行的末尾:

\n\n
k move up one line\n^ move to the first printable character\ny$ yank to the end of the line\n"_d get rid of the now useless line by deleting it into the black hole register\n$ move to the end of the line\np put the deleted text\n
Run Code Online (Sandbox Code Playgroud)\n