sponsor Vim development Vim logo Vim Book Ad

basic Tip #924: alt up/down mappings like in eclipse.

 tip karma   Rating 11/5, Viewed by 1274 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   May 9, 2005 7:36      complexity:   basic
author:   Dane Summers      as of Vim:   6.0

Move the line your cursor is on up/down with the cursor as in eclipse like so:

map <M-Down> ddp
map <M-Up> ddkP
imap <M-Down> <Esc>ddpi
imap <M-Up> <Esc>ddkPi

These still need a little work but this is the basics...

 rate this tip  Life Changing Helpful Unfulfilling 

<< Sort lines by word# count | Not So Quick generic option toggling >>

Additional Notes

Gerald Lai, May 9, 2005 13:25
See vimtip#646

Using the ":move" command is much cleaner. The mappings below maintain cursor position after the move (except for visual, just in case you use the 'scrolloff' option).

nmap <C-Down> mz:m+<CR>`z
nmap <C-Up>   mz:m-2<CR>`z
imap <C-Down> <Esc>:m+<CR>gi
imap <C-Up>   <Esc>:m-2<CR>gi
vmap <C-Down> :m'>+<CR>`<my`>mzgv`yo`z
vmap <C-Up>   :m'<-2<CR>`>my`<mzgv`yo`z
amix at amix.dk, May 9, 2005 13:46
It is a great tip, but I think it is faster to use j and k, here are the mappings for the lazy people :]

nmap <C-j> mz:m+<CR>`z
nmap <C-k> mz:m-2<CR>`z
imap <C-j> <Esc>:m+<CR>gi
imap <C-k> <Esc>:m-2<CR>gi
vmap <C-j> :m'>+<CR>`<my`>mzgv`yo`z
vmap <C-k> :m'<-2<CR>`>my`<mzgv`yo`z

map <M-k> ddp
map <M-j> ddkP
imap <M-j> <Esc>ddpi
imap <M-k> <Esc>ddkPi
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge.net Logo