Mapping keys in VIM on Mac
Solution 1
The simplest way is the best way:
nmap <D-Right> <C-w>l
nmap <D-Left> <C-w>h
This answers your question but I don't advise you to go that way.
The first problem you'll encounter is that all of your cmdsomething mappings are going to fail in the terminal.
The second is that MacVim doesn't support multiple modifiers: you won't be able to have CtrlShiftb, for example. Well, it will work but the Shift part will be ignored so you will be limited very quicly.
The third problem will be that you'll fail to commit Vim's commands to memory. The day you'll ssh
into a server and use Vim there you'll be lost.
So yeah, you CAN do that but (I think that) you SHOULDN'T.
Instead, learn the Vim way and type :help windows
. It will pay. Quickly.
Solution 2
Just gone through all this myself. Quickest and easiest solution on a Mac I've found is: http://pqrs.org/macosx/keyremap4macbook/document.html
This utility will allow you to change your Command keys. You may also set up profiles (I set up a VIM profile) so that I just turn on my VIM profile only when in VIM (quick toggle on menu bar) so it doesn't mess anything (mac osx behaviour, utilities or applications) else up.
I'm on a Macbook Pro so I wanted to change my option keys to control keys while in VIM. This utiltiy allowed me to do that and I also changed my fn key to option just in case.
They also have another utility: http://pqrs.org/macosx/keyremap4macbook/extra.html
Which allowed me to change my Caps Lock key to be Esc. Which is FANTASTIC in VIM; no more reaching for Esc constantly. Note: this utility doesn't have the profiles, so my caps lock is always Esc whether in vim or not.
Solution 3
I have no idea where you got the ":maca" command, but it is not a Vim command. Also, what is "_cycleWindowsBackwards:" and "_cycleWindows:"?
I suspect what you really want is something more like this:
:nmap <D-Right> :wincmd W<CR>
:nmap <D-Left> :wincmd w<CR>
Related videos on Youtube
Naatan
Updated on September 18, 2022Comments
-
Naatan over 1 year
I had a previous problem that was solved, but it seems I am stuck once again.
I'm trying to reassign the keys for switching between Windows to be more intuitive. I've found that you should be able to add the following to your vimrc:
nmap <D-Right> :maca _cycleWindowsBackwards:<CR> nmap <D-Left> :maca _cycleWindows:<CR>
Which I've tried but it does not seem to do anything for me. My vimrc is definitely being loaded as when I enter bogus I get an error when starting vim.
I've tried different variations of assigning keys, with none really seeming to do anything.
Also, what is the recommended resource for VIM documentation?
-
Naatan almost 13 yearsLol you edited "Thank you" out of my post? I'm aware VIM comes with it's own documentation, I was just hoping there was a better alternative.
-
Wuffers almost 13 yearsYes, I did remove the "Thank you". It is unnecessary.
-
-
Wuffers almost 13 yearsThe
:maca
command is a command specific to MacVim. -
Naatan almost 13 yearsThanks, I'll try and adopt the VIM way, I can always use Keyboard Maestro to remap some keys.
-
Naatan almost 13 yearsThanks, I didn't realize I was looking at MacVim specific documentation, I guess I'll need to find a solution that'll work for both.
-
Naatan almost 13 yearsThanks, I use Keyboard Maestro for my keyboard remapping needs (CMD+C / CMD+V just cripples your fingers..), but I try to avoid using it when there are (supposedly) build in settings to change keys.