Last Updated: February 25, 2016
·
391
· klj613

Moving lines in vim

ctrl + k/j to move lines up and down. Also works in visual mode.

nnoremap <C-j> :m .+1<CR>==
nnoremap <C-k> :m .-2<CR>==
inoremap <C-j> <Esc>:m .+1<CR>==gi
inoremap <C-k> <Esc>:m .-2<CR>==gi
vnoremap <C-j> :m '>+1<CR>gv=gv
vnoremap <C-k> :m '<-2<CR>gv=gv

Note

I probably got this from the internet somewhere - but been in my vimrc for a while now...