How would I move the current line behind the line above it? Say I have:
function foo()
{
^ Cursor is here
And want to turn that into:
function foo() {
I am still new to vim, so what I do now is i[backspace][backspace]...etc. 🙂
Several ways:
kJorkgJorVkJorVkgJ(the last two commands do the same in visual mode).kwill go to previous line, andJorgJwill merge with next line (Jinserts a space inbetween,gJjust removes the EOL characters):-,jor:-,j!-,is a range that is abbreviation for.-1,.which means “from previous line to current line”jis the ex command for concatenating lines in a range. The banged (with exclamation mark) version acts like gJ.:-s/\s*\n\s*//-means previous line:sis probably known to you, else you should runvimtutor./\s*\n\s*/is pattern for as many spaces as possible plus line terminator (matches different byte sequences according to the file format: LF, CR or CRLF) plus as many spaces as possible.Here, replacement pattern is empty.
CTRL-Wtwice (each time it deletes a word, or leading whitespace on a line, or newline) (as ib. suggests, this depends on thebackspacesetting).References:
:help J:help gJ:help k:help range:help :j:help pattern:help i_CTRL-W