tags:

views:

49

answers:

2

In Netbeans, Ctrl-Shift-Up/Down duplicates the current line or selection and Alt+Shift+Up/Down/Left/Right moves the current line or selection. How can this be achieved in VIM 7?

So far, I'm able to get Alt+Shift+Up/Down working using these mappings:

:nmap <A-S-up> :m .-2<Enter>
:imap <A-S-up> <Esc>:m .-2<Enter>gi
:vmap <A-S-up> :m .-2<Enter>gv

:nmap <A-S-down> :m .+1<Enter>
:imap <A-S-down> <Esc>:m +1<Enter>gi
:vmap <A-S-down> :m '>+1<Enter>gv

I'm still strugging with:

  1. Having Alt+Shift+j/k work like Alt+Shift+Up/Down. Simply changing "up" to "k" isn't working.
  2. Ctrl-Shift-Up/Down mappings aren't working. Is this an unmappable sequence?
  3. To map both Alt+Shift+up and Alt+Shift+k to the same command, is there a better way than duplicating the map command to another line?
+1  A: 

Instead of typing out the key sequence, press Ctrl-V (or Ctrl-Q on Windows) and then your key sequence.

In other words, instead of typing this:

< A - S - u p >

Type this:

Ctrl-Q Alt-Shift-Up

I don't really understand why, but for some reason vim doesn't translate all key combinations in the way that you think it would. For example, Alt-Shift-K shows up as Ë for me, but the key mapping still works. And Alt-Shift-Up translates to <M-S-Up> rather than <A-S-Up>.

As to your third question, map one key combination to the other.

:nmap <A-S-up> :m .-2<Enter>
:nmap Ë <A-S-up>

(Keep in mind that Ë is Alt-Shift-K, at least on my machine.)

BTW, Ctrl-V works for me in GVIM but not in VIM.
Brian Harris
A: 

Not all of this works in VIM but it all works in GVIM.

" Alt+Shift+Up/k moves content up
:nmap <M-S-Up> :m .-2<Enter>
:nmap <M-S-k> <M-S-Up>
:imap <M-S-Up> <Esc>:m .-2<Enter>gi
:imap <M-S-k> <M-S-Up>
:vmap <M-S-Up> :m .-2<Enter>gv
:vmap <M-S-k> <M-S-Up>

" Alt+Shift+Down/j moves content down
:nmap <M-S-Down> :m .+1<Enter>
:nmap <M-S-j> <M-S-Down>
:imap <M-S-Down> <Esc>:m .+1<Enter>gi
:imap <M-S-j> <M-S-Down>
:vmap <M-S-Down> :m '>+1<Enter>gv
:vmap <M-S-j> <M-S-Down>

" Ctrl+Shift+Up/k copies content up
:nmap <C-S-Up> :co .-1<Enter>
:nmap <C-S-k> <C-S-Up>
:imap <C-S-Up> <Esc>:co .<Enter>gi
:imap <C-S-k> <C-S-Up>
:vmap <C-S-Up> :co '><Enter>gv
:vmap <C-S-k> <C-S-Up>

" Ctrl+Shift+Down/j copies content down
:nmap <C-S-Down> :co .<Enter>
:nmap <C-S-j> <C-S-Down>
:imap <C-S-Down> <Esc>:co .<Enter>gi<Down>
:imap <C-S-j> <C-S-Down>
:vmap <C-S-Down> :co .-1<Enter>gv
:imap <C-S-j> <C-S-Down>

" Alt+Shift+Left/h shifts content left 
:nmap <M-S-Left> <<
:nmap <M-S-h> <M-S-Left>
:imap <M-S-Left> ^D
:imap <M-S-h> <M-S-Left>
:vmap <M-S-Left> <gv
:vmap <M-S-h> <M-S-Left>

" Alt+Shift+Right/l shifts content right
:nmap <M-S-Right> >>
:nmap <M-S-l> <M-S-Right>
:imap <M-S-Right> ^T
:imap <M-S-l> <M-S-Right>
:vmap <M-S-Right> >gv
:vmap <M-S-l> <M-S-Right>
Brian Harris