Vimr: Switch tabs using <⌘-1>, <⌘-2>, etc.

Created on 12 Oct 2017  Â·  8Comments  Â·  Source: qvacua/vimr

It would be awesome if we could switch VimR tabs using ⌘-<number>, just like it happens in Chrome/Firefox/iTerm and probably a bunch of other apps.

What do you think?

Most helpful comment

Alternatively, you can remap the File Browser, as you can with any macOS app (instead of turning it off).

  1. Go to System Preferences -> Keyboard -> Shortcuts,
  2. choose App Shortcuts,
  3. add (with the +) a new shortcut
  4. Configure it to:
    a. set the Application to VimR.app,
    b. set the Menu Title to Toggle File Browser
    c. set the Keyboard Shortcut to whatever you want (I use Shift+Cmd+E to mimic VSCode)

It'll look something like,

screenshot 2018-03-12 12 32 33

In my vim configuration I have,

    " Switch tab with Cmd + [1-9].
    nnoremap <d-1> :tabn 1<CR>
    nnoremap <d-2> :tabn 2<CR>
    nnoremap <d-3> :tabn 3<CR>
    nnoremap <d-4> :tabn 4<CR>
    nnoremap <d-5> :tabn 5<CR>
    nnoremap <d-6> :tabn 6<CR>
    nnoremap <d-7> :tabn 7<CR>
    nnoremap <d-8> :tabn 8<CR>
    nnoremap <d-9> :tabn 9<CR>
    nnoremap <d-9> :tabn 0<CR>
    inoremap <d-1> <C-o>:tabn 1<CR>
    inoremap <d-2> <C-o>:tabn 2<CR>
    inoremap <d-3> <C-o>:tabn 3<CR>
    inoremap <d-4> <C-o>:tabn 4<CR>
    inoremap <d-5> <C-o>:tabn 5<CR>
    inoremap <d-6> <C-o>:tabn 6<CR>
    inoremap <d-7> <C-o>:tabn 7<CR>
    inoremap <d-8> <C-o>:tabn 8<CR>
    inoremap <d-9> <C-o>:tabn 9<CR>
    inoremap <d-9> <C-o>:tabn 0<CR>

and some additional nice ones are,

  " Save file with CMD+s.
  nnoremap <d-s> :w<CR>
  inoremap <d-s> <C-o>:w<CR>
  " Close current buffer/file with Cmd + w.
  nnoremap <d-w> :tabclose<CR>
  inoremap <d-w> <C-o>:tabclose<CR>
  " Map CMD+z and CMD+Shift+z to undo/redo.
  nnoremap <C-z> u
  inoremap <C-z> <C-o>u
  nnoremap <C-S-z> <C-r>
  inoremap <C-S-z> <C-o><C-r>
  " Map CMD+p to CtrlP.
  nnoremap <d-p> :CtrlP<CR>
  inoremap <d-p> <C-o>:CtrlP<CR>

All 8 comments

Thanks! That's one impressive .vimrc. However, in VimR ⌘+1 is mapped the hard way to toggle "File Browser" 😢

Any way to turn it off?

This is related to #418... Maybe we should do it like the IdeaVim plugin for JetBrains IDEs...

@pjg you can turn off the File Browser in the Preferences > Tools menu. I turn off all the tools, then all Apple+# keys work!

@askedrelic thanks, this worked!

Alternatively, you can remap the File Browser, as you can with any macOS app (instead of turning it off).

  1. Go to System Preferences -> Keyboard -> Shortcuts,
  2. choose App Shortcuts,
  3. add (with the +) a new shortcut
  4. Configure it to:
    a. set the Application to VimR.app,
    b. set the Menu Title to Toggle File Browser
    c. set the Keyboard Shortcut to whatever you want (I use Shift+Cmd+E to mimic VSCode)

It'll look something like,

screenshot 2018-03-12 12 32 33

In my vim configuration I have,

    " Switch tab with Cmd + [1-9].
    nnoremap <d-1> :tabn 1<CR>
    nnoremap <d-2> :tabn 2<CR>
    nnoremap <d-3> :tabn 3<CR>
    nnoremap <d-4> :tabn 4<CR>
    nnoremap <d-5> :tabn 5<CR>
    nnoremap <d-6> :tabn 6<CR>
    nnoremap <d-7> :tabn 7<CR>
    nnoremap <d-8> :tabn 8<CR>
    nnoremap <d-9> :tabn 9<CR>
    nnoremap <d-9> :tabn 0<CR>
    inoremap <d-1> <C-o>:tabn 1<CR>
    inoremap <d-2> <C-o>:tabn 2<CR>
    inoremap <d-3> <C-o>:tabn 3<CR>
    inoremap <d-4> <C-o>:tabn 4<CR>
    inoremap <d-5> <C-o>:tabn 5<CR>
    inoremap <d-6> <C-o>:tabn 6<CR>
    inoremap <d-7> <C-o>:tabn 7<CR>
    inoremap <d-8> <C-o>:tabn 8<CR>
    inoremap <d-9> <C-o>:tabn 9<CR>
    inoremap <d-9> <C-o>:tabn 0<CR>

and some additional nice ones are,

  " Save file with CMD+s.
  nnoremap <d-s> :w<CR>
  inoremap <d-s> <C-o>:w<CR>
  " Close current buffer/file with Cmd + w.
  nnoremap <d-w> :tabclose<CR>
  inoremap <d-w> <C-o>:tabclose<CR>
  " Map CMD+z and CMD+Shift+z to undo/redo.
  nnoremap <C-z> u
  inoremap <C-z> <C-o>u
  nnoremap <C-S-z> <C-r>
  inoremap <C-S-z> <C-o><C-r>
  " Map CMD+p to CtrlP.
  nnoremap <d-p> :CtrlP<CR>
  inoremap <d-p> <C-o>:CtrlP<CR>

If you want, I could add this to the wiki?

Feel free to do it. I hope that at some point I can implement a real keyboard shortcut management....

Was this page helpful?
0 / 5 - 0 ratings

Related issues

romaninsh picture romaninsh  Â·  7Comments

cvincent picture cvincent  Â·  4Comments

qvacua picture qvacua  Â·  7Comments

0ax1 picture 0ax1  Â·  8Comments

kunxi picture kunxi  Â·  5Comments