Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better default mappings for macOS: use arrow keys #73

Open
huyz opened this issue Aug 13, 2022 · 1 comment
Open

Better default mappings for macOS: use arrow keys #73

huyz opened this issue Aug 13, 2022 · 1 comment

Comments

@huyz
Copy link

huyz commented Aug 13, 2022

After my comments a couple of weeks ago on #71 (comment), 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:

  • I don't want to use C as the modifier because <C-l> is useful for redrawing the screen (and in neovim, also clearing any search highlighting).
  • I don't want to use S as the modifier because I'd like to figure out mappings that would work the same with vim and with JetBrains and VS code and the Shift key is often used in GUI apps to mean "extend the selection"
  • So that leaves the A modifier which on macOS is the Option key.
  • But if we select A, there are problems with using the h, j, k, l keys. In the terminal (at least iTerm), the recommended setting is to make the left Option key map to <Esc>+. The problem comes when you're in visual mode in the terminal and you hit Esc to exit out of Visual mode and then hit one of the above motion keys, such as h. What happens is that because of the vim-move mappings, this would be interpreted as a vim-move operation. One workaround is to hit Esc and wait until vim times out—but who wants to wait around? So the solution is to map to arrow keys instead of h and friends. Bonus: JetBrains and VS Code IDEs already use the arrow keys for moving line/statements, so the mappings will be similar or even the same (default VS code mappings for moving a line is indeed Option + arrow keys).

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.

@huyz huyz changed the title Better default mappings for macOS Better default mappings for macOS: use arrow keys Aug 13, 2022
@matze
Copy link
Owner

matze commented Aug 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants