1

I find a .vimrc file config:

" Move selection up/down (add =gv to reindent after move)
:vmap <D-S-Up> :m-2<CR>gv
:vmap <D-S-Down> :m'>+<CR>gv

I know the D-S-Up must be a key, but what is the key?

I type:

:help D-S-Up

nothing happened

Thomas Baruchel
  • 7,236
  • 2
  • 27
  • 46
lovespring
  • 420
  • 1
  • 4
  • 14

2 Answers2

3
  1. :help key-notation tells you the meaning of all those <key> notations.

  2. You can't expect :help D-S-Up to do anything because:

    • it doesn't follow established patterns like i_ctrl-r,
    • it is a custom mapping and Vim only provides documentation for its own commands.
  3. <D> is the Cmd key on Mac keyboards, <S> is the Shift key, and <Up> is the Up arrow key.

    So <D-S-Up> means Cmd + Shift + Up.

  4. The Cmd key only works in the MacVim GUI.

  5. Non-portable mappings are worthless.

  6. One should use :xmap or :xnoremap for visual mode mappings, not :v*.

  7. Non-recursive mappings should be used by default unless one really wants recursion.

  8. Using someone else's vimrc is a bad idea.

  9. By the way, here are enhanced versions of those mappings:

    nnoremap <silent> <D-S-Up>   :<C-u>move-2<CR>==
    nnoremap <silent> <D-S-Down> :<C-u>move+<CR>==
    xnoremap <silent> <D-S-Up>   :move-2<CR>gv=gv
    xnoremap <silent> <D-S-Down> :move'>+<CR>gv=gv
    

    where:

    • <silent> prevents the commands in the mapping from echoing useless info,
    • <C-u> removes any default range inserted by Vim,
    • move-2<CR> is a more readable version of m-2<CR>,
    • == re-indents the line,
    • gv=gv reselects the lines, re-indents them, and re-selects them again.
romainl
  • 186,200
  • 21
  • 280
  • 313
1

Have a look at Move entire line up and down in Vim

In an answer you can read (concerning the line :vmap <D-S-Up> :m-2<CR>gv):

According to the shortcuts above, pressing Cmd-Shift-Up/Down will shift the block selection up/down. "D" is the Command key in MacVim, for Windows try "C" (Control), or "A" (Alt) (eg. would be Control Alt f).

Since I don't have a Mac myself, I can't check, but it's most certainly true.

Community
  • 1
  • 1
Thomas Baruchel
  • 7,236
  • 2
  • 27
  • 46