Certain key mappings not working in MacVim
-
25-02-2021 - |
Question
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.
Solution 2
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.
OTHER TIPS
Investigate the cause by doing
:verbose map <D-Up>
Additionally try selectively enabling your other plugins to see whether mappings are being cleared somehow