matze / vim-move

Plugin to move lines and selections up and down
http://www.vim.org/scripts/script.php?script_id=4687
MIT License
1.2k stars 56 forks source link

Better default mappings for macOS: use arrow keys #73

Open huyz opened 2 years ago

huyz commented 2 years ago

After my comments a couple of weeks ago on https://github.com/matze/vim-move/pull/71#issuecomment-1199893686, I realized that not everything was working. So I revisited the configuration. My conclusion is that the default bindings for vim-move are not ideal.

Here are the problems as I see them:

This is what I've figured out works very well for vim and neovim in iTerm2 terminal and in MacVim and VimR:

let g:move_map_keys = 0

if has("gui_running")
  nmap <A-Down> <Plug>MoveLineDown
  nmap <A-Up> <Plug>MoveLineUp
  nmap <A-Left> <Plug>MoveCharLeft
  nmap <A-Right> <Plug>MoveCharRight
  vmap <A-Down> <Plug>MoveBlockDown
  vmap <A-Up> <Plug>MoveBlockUp
  vmap <A-Left> <Plug>MoveBlockLeft
  vmap <A-Right> <Plug>MoveBlockRight
else
  nmap <Esc><Down> <Plug>MoveLineDown
  nmap <Esc><Up> <Plug>MoveLineUp
  nmap <Esc><Left> <Plug>MoveCharLeft
  nmap <Esc><Right> <Plug>MoveCharRight

  " WARNING: if instead of using h,j,k,l, you tend to use arrow keys for motion
  " in Normal mode, then the mappings below may interfere when you try to exit
  " out of Visual mode with <Esc> and immediately hit an arrow key. In that
  " case, you might want to use the `C` modifier instead as here:
  "vmap <C-Down> <Plug>MoveBlockDown
  "vmap <C-Up> <Plug>MoveBlockUp
  "vmap <C-Left> <Plug>MoveBlockLeft
  "vmap <C-Right> <Plug>MoveBlockRight
  vmap <Esc><Down> <Plug>MoveBlockDown
  vmap <Esc><Up> <Plug>MoveBlockUp
  vmap <Esc><Left> <Plug>MoveBlockLeft
  vmap <Esc><Right> <Plug>MoveBlockRight
endif

It took quite some time to figure this out. So I think that it would help mac users if either these were the defaults or there was a section in the README that listed all of these.

matze commented 2 years ago

Sorry for the late reply. I'd really prefer if we "just" list these bindings in the README and docs for the simple reason not to break existing configurations for who-knows-how-many Mac users.