7

I've recently switched to using a Mac at work from previously using Linux. I found out about MacVim (from http://code.google.com/p/macvim/) and have been trying to port over my previous keymappings.

The mappings I used to have are as follows:

  • Ctrl-T: New tab
  • Ctrl-W: Close tab/window
  • Ctrl-1 ... Ctrl-0: Switch to numbered tab
  • Alt-Up: New tab (same as Ctrl-T)
  • Alt-Left/Alt-Right: Switch to the previous/next tab
  • Ctrl-Alt-E: Open FuzzyFinder in file mode
  • Ctrl-Alt-B: Open FuzzyFinder in buffer mode
  • Ctrl-Alt-W: Clear trailing whitespace from the buffer

Now, to make these mappings more 'Mac like', I decided to switch the first two to use the option (ie. Apple logo) key, and all the others to use the command key instead of Alt (ie. Ctrl-Alt-E becomes Ctrl-Command-E). I read on http://macvim.org/OSX/index.php that this key can be mapped with D (ie ). The new contents of my .vimrc is as follows:

nmap <D-t> :tabnew<cr>
nmap <D-w> :close<cr>
nmap <D-1> 1gt
nmap <D-2> 2gt
nmap <D-3> 3gt
nmap <D-4> 4gt
nmap <D-5> 5gt
nmap <D-6> 6gt
nmap <D-7> 7gt
nmap <D-8> 8gt
nmap <D-9> 9gt
nmap <D-0> 10gt

nmap <D-Up> :tabnew<CR>
nmap <D-Right> :tabnext<CR>
nmap <D-Left> :tabprevious<CR>

"FuzzyFinder
nmap <C-D-e> :FufFileWithFullCwd<CR>
nmap <C-D-b> :FufBuffer<CR>

"Whitespace remover
nmap <C-D-w> :%s/\s\+$//<CR>

So, after re-mapping the keys, some now work and others don't, with no clear logic as to why.

What works:

  • Cmd-T and Cmd-W successfully work for opening and closing tabs.
  • Cmd-1 ... Cmd-0 successfully work for switching tabs.

What doesn't work:

  • Cmd-Up for opening a tab does not work.
  • Cmd-Left and Cmd-Right for switching tabs does not work.
  • Ctrl-Cmd-E and Ctrl-Cmd-B for opening FuzzyFinder do not work.
  • Ctrl-Cmd-W for clearing whitespace does not work (but neither does it close the tab, as it would without ctrl.
Alex Celeste
  • 12,824
  • 10
  • 46
  • 89
Joel Cross
  • 1,400
  • 15
  • 22
  • you can accept your own answer if you found the solution yourself. ;) – sjas Aug 11 '12 at 21:15
  • There is a [reason](http://learnvimscriptthehardway.stevelosh.com/chapters/05.html) to always use `*nore(map|abbrev)` (e.g. `nnoremap`) and never `nmap`. – ZyX Jul 25 '13 at 17:18
  • Thanks ZyX for the advice. I think I'm going to read the whole of 'Learn Vim Script the Hard Way' when I get the chance! – Joel Cross Aug 03 '13 at 16:58

2 Answers2

7

Investigate the cause by doing

:verbose map <D-Up>

Additionally try selectively enabling your other plugins to see whether mappings are being cleared somehow

sehe
  • 374,641
  • 47
  • 450
  • 633
  • * Last set from /Applications/MacPorts/MacVim.app/Contents/Resources/vim/gvimrc – Joel Cross Nov 10 '11 at 11:22
  • So it would seem that a global file is overriding my config. I'm surprised though, because I would have thought my user config would take precedence. – Joel Cross Nov 10 '11 at 11:23
  • I added the line "let macvim_skip_cmd_opt_movement = 1" to my .vimrc and now the tabs are working fine. The Last three commands (the ones using the ctrl-cmd combination) still aren't working though. – Joel Cross Nov 10 '11 at 11:29
  • 1
    So it turns out that there is a bug in Macvim (http://code.google.com/p/macvim/issues/detail?id=317) which means it's not possible to map the ctrl key. Until that is fixed, I will try mapping the shift key instead. – Joel Cross Nov 10 '11 at 11:35
  • @JoelCross: good work. Please consider posting your answer so people can use it in the future. Was my answer helpful in any way? – sehe Nov 10 '11 at 11:36
  • Unfortunately as a StackOverflow newbie I have to wait another 7 hours before I can post an answer, hence all the comments on your answer. Yes, your answer solved half of my problem. – Joel Cross Nov 10 '11 at 11:55
5

So it turns out that there is a bug in Macvim (http://code.google.com/p/macvim/issues/detail?id=317) which means it's not possible to map the ctrl key. Instead I mapped the leader key (a.k.a. the backslash), and it all seems to work now.

Joel Cross
  • 1,400
  • 15
  • 22