Vim Tips Wiki
Advertisement
Tip 191 Printable Monobook Previous Next

created January 3, 2002 · complexity intermediate · author Kontra Gergely · version 5.7


You can easily move lines with these maps using <C-Up> and <C-Down> (only in GUI version).

Works in normal, insert, and visual mode, but you can't add a count to them.

" Transposing lines
nmap <C-Down> :<C-u>move .+1<CR>
nmap <C-Up> :<C-u>move .-2<CR>
imap <C-Down> <C-o>:<C-u>move .+1<CR>
imap <C-Up> <C-o>:<C-u>move .-2<CR>
vmap <C-Down> :move '>+1<CR>gv
vmap <C-Up> :move '<-2<CR>gv

" Transpose chars (like Ctrl-T in emacs, shell)
imap <C-F> <Esc>Xpa

Comments

There is another way to transpose chars. Simply type xp in command mode.


Nice touch using the ex move commands. Keeps from 'polluting' registers with the text you are transposing.


Advertisement