Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Join the line above after current line?

Tags:

join

vim

lines

I know these commands in Vim:

J : Join line below after current line
-J : Join current line after line above

but how do I join the line above after current line?

like image 773
Reman Avatar asked Nov 28 '12 16:11

Reman


2 Answers

You can also use the ex-command

:m-2|j
  • m-2 has the effect of moving the current line to 2 lines above its current position; this switches the position of the current line and the line above.
  • j joins the current line and the line above, inserting a space between the two. Use j! if you don't want the space.
  • | separates the 2 ex-commands

This ex-command is a short way of writing the following

:move .-2
:join  
like image 81
doubleDown Avatar answered Nov 01 '22 15:11

doubleDown


There are many ways to do it. One would be… deleting the line above and appending it to the end of the line below:

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
like image 1
romainl Avatar answered Nov 01 '22 14:11

romainl