Skip to content

Instantly share code, notes, and snippets.

@AnsonH
Last active September 6, 2021 13:01
Show Gist options
  • Save AnsonH/0691db0064192fdc54c5a6879c6746dd to your computer and use it in GitHub Desktop.
Save AnsonH/0691db0064192fdc54c5a6879c6746dd to your computer and use it in GitHub Desktop.
Vim Tip #3 - Move lines up and down with <A-k> and <A-j>
nnoremap <silent> <A-j> :m .+1<CR>==
nnoremap <silent> <A-k> :m .-2<CR>==
inoremap <silent> <A-j> <Esc>:m .+1<CR>==gi
inoremap <silent> <A-k> <Esc>:m .-2<CR>==gi
vnoremap <silent> <A-j> :m '>+1<CR>gv=gv
vnoremap <silent> <A-k> :m '<-2<CR>gv=gv
@AnsonH
Copy link
Author

AnsonH commented Sep 6, 2021

Source: https://vim.fandom.com/wiki/Moving_lines_up_or_down#Mappings_to_move_lines
I added the <silent> argument so that it doesn't output the mapping in the Vim command line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment