2012-11-28 26 views
5

我在Vim的知道這些命令:如何在當前行之後加入上面的行?

記者:加入以下行當前行之後
-J:加入行後當前行

但我如何加入線上方後電流線?

+8

'kddpkJ' .......? –

+2

保存按鍵「ddkPJ」。如果你做了很多換行,可以考慮製作[這個技巧中的映射](http://vim.wikia.com/wiki/VimTip646#Mappings_to_move_lines)。 –

回答

2

有很多方法可以做到這一點。其中之一是...刪除上面的行並將其附加到下面一行的末尾:

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 
+1

首先交換行然後'J'oin他們會更容易([@WilliamPursell建議](http://stackoverflow.com/questions/13609736/how-do-i-join-the-line-above -after電流線#comment18659642_13609736))。 – bitmask

+0

是的,我知道。我去了一個「litteral」的方法。實際上,我也會和William Pursell的方法一起。 – romainl

+0

請注意,'J'確實處理與逐字連接不同的空格。也就是說,如果有人想要'J'產生的結果,'k^d $ k $ p'會做一些不同的事情! – bitmask

1

您還可以使用ex命令

:m-2|j 
  • m-2有移動的效果當前行至當前位置上方2行;這將切換當前行的位置和上面的行。
  • j加入當前行和上面的行,在兩者之間插入一個空格。如果你不想要這個空間,請使用j!
  • |分離2 ex命令

該前命令是寫的短方式下面

:move .-2 
:join 
相關問題