20

Are there any shortcuts to switch the Tabs from one to another in MacVim?

MacVim Tabs

Any tips to bind the shortcuts myself in .vimrc like ⌘ + 1 for Tab 1 and ⌘ + 2 for Tab 2. For example, like switching browser tabs.

edit: i'm back to working on linux. Not being forced to sufer a Mac just entered my list of demands for new jobs. Good luck to anyone else still dealing with this.

gcb
  • 5,442
  • 13
  • 62
  • 86
Ye Lin Aung
  • 5,700

5 Answers5

27

You can of course change shortcuts with OSXs system preferences for your keyboard as shown here: How to Remap Any Keyboard Shortcut in Mac OS X

Some might prefer to do it via their .vimrc:

if has("gui_macvim")
  " Press Ctrl-Tab to switch between open tabs (like browser tabs) to 
  " the right side. Ctrl-Shift-Tab goes the other way.
  noremap <C-Tab> :tabnext<CR>
  noremap <C-S-Tab> :tabprev<CR>

  " Switch to specific tab numbers with Command-number
  noremap <D-1> :tabn 1<CR>
  noremap <D-2> :tabn 2<CR>
  noremap <D-3> :tabn 3<CR>
  noremap <D-4> :tabn 4<CR>
  noremap <D-5> :tabn 5<CR>
  noremap <D-6> :tabn 6<CR>
  noremap <D-7> :tabn 7<CR>
  noremap <D-8> :tabn 8<CR>
  noremap <D-9> :tabn 9<CR>
  " Command-0 goes to the last tab
  noremap <D-0> :tablast<CR>
endif
cseelus
  • 373
18

Since MacVim is an actual program on Mac OS, you can map tab switching the same way you map commands in any program (which I personally just learned about recently).

Open up System Preferences, select "Keyboard", then "Application Shortcuts" (in the left menu). Under the menu on the right, click on the plus (+) to add a new command. Choose MacVim for the application, and for the menu title, type "Select Next Tab", and choose a shortcut (I chose Cmd+right arrow). Then do the same thing for the command "Select Previous Tab".

"Select Next Tab" and "Select Previous Tab" are found in MacVim under the "Window" menu. Any option you see in any of the menus for an app can be remapped using this method.

DevDaddyNick
  • 196
  • 1
  • 3
14

You can Select Next Tab with +} and Select Previous Tab with +{

The shift key is required to not just hit a [ instead of a }
So the shortcut is +shift+] or +shift+[
This shortcuts works in many apps, i.e. in the Terminal

Masolino
  • 172
5

I have the following in my ~/.vimrc for Linux. You should be able to change the "<M-" sequence to "<D-" to get what you want:

" Meta+1-0 jumps to tab 1-10, Shift+Meta+1-0 jumps to tab 11-20:
let s:windowmapnr = 0
let s:wins='1234567890!@#$%^&*()'
while (s:windowmapnr < strlen(s:wins))
    exe 'noremap <silent> <M-' . s:wins[s:windowmapnr] . '> ' . (s:windowmapnr + 1) . 'gt'
    exe 'inoremap <silent> <M-' . s:wins[s:windowmapnr] . '> <C-O>' . (s:windowmapnr + 1) . 'gt'
    exe 'cnoremap <silent> <M-' . s:wins[s:windowmapnr] . '> <C-C>' . (s:windowmapnr + 1) . 'gt'
    exe 'vnoremap <silent> <M-' . s:wins[s:windowmapnr] . '> <C-C>' . (s:windowmapnr + 1) . 'gt'
    let s:windowmapnr += 1
endwhile
unlet s:windowmapnr s:wins
Heptite
  • 20,411
4

In addition to making your own mappings, there are built-in vim shortcuts. Try a number followed by gt. For example: 3gt takes you to the 3rd tab. You can also do just gt to go to the next tab, or gT to go to the previous one.

(Since vim 7.something, tabs have been baked in even in the text-mode non-gvim version.)

murftown
  • 141