Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vim 如何在当前行之后加入上面的行?_Vim_Join_Lines - Fatal编程技术网

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

Vim 如何在当前行之后加入上面的行?,vim,join,lines,Vim,Join,Lines,我知道Vim中的这些命令: J:在当前行之后连接下面的行 -J:在上面的一行接一行地连接当前行 但是如何在当前行之后加入上面的行呢?有很多方法。一种是……删除上面的行并将其附加到下面的行末尾: k move up one line ^ move to the first printable character y$ yank to the end of the line "_d get rid of the now useless line by deleting it into the bla

我知道Vim中的这些命令:

J:在当前行之后连接下面的行
-J:在上面的一行接一行地连接当前行


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

有很多方法。一种是……删除上面的行并将其附加到下面的行末尾:

k move up one line
^ move to the first printable character
y$ yank to the end of the line
"_d get rid of the now useless line by deleting it into the black hole register
$ move to the end of the line
p put the deleted text

也可以使用ex命令

:m-2|j
  • m-2
    具有将当前行移动到其当前位置上方2行的效果;这将切换当前线路和上方线路的位置
  • j
    连接当前行和上面的行,在两者之间插入空格。使用
    j如果您不想要空间
  • |
    分隔两个ex命令
此ex命令是编写以下内容的一种简短方式

:move .-2
:join  

我在.vimrc中添加了以下行。现在,在正常模式下,我可以按@j或j。我的领袖是空间。我也见过有人把它设置为

" join with previous line with @j
let @j="kJ"
nnoremap <leader>j @j

kddpkJ
……要保存击键,
ddkPJ
。如果你做大量的线交换,考虑制作。更容易首先交换这些线,然后<代码> J < /代码> ON(AS)。是的,我知道。我采取了“随地”的方式。事实上,我也同意William Pursell的方法。请注意,
J
处理空格的方式与逐字连接不同。也就是说,如果你想得到由
J
产生的结果,
k^d$k$p
会做一些不同的事情!根据我的经验,
J
添加的空间几乎总是一个问题。当我写文本时,它很酷,但当我加入HTML标签时,它很糟糕。我倾向于使用
:j取而代之。谢谢威廉和罗曼因!交换?当我在您的邮件中读到关于交换的内容时,我找到了另一个解决方案:m.-2 |:正常JJ为什么不跳过reg步骤,直接
nnoremap j kJ
?注意,这与问题中的OPs
-J
相同。我使用了寄存器,以便在开始时进行计数。5kJ不正确地转换为5k和J,这将连接两条比当前线路高出5条线路的线路。鉴于5@j将正确转换为连接前5行。
let mapleader = " "
let g:mapleader = " "