I recently started using vim extensively on OSX Tiger and I'd really
like to use the command key as meta. I found the tip "How do I map the
Apple key?" on http://macvim.org/OSX/index.php (whose binary I'm
using). The tip works fine on mappings such as command+s, but when I
try to map command+h, OSX still interprets that as "hide window". Is
there a way to block OSX from processing these shortcuts ala
mac-pass-command-to-system option in emacs?
Any help is greatly appreciated.
Or, is it possible to configure the `option' key on mac as the meta
key in gvim? That would help greatly too.
Thanks.
Liu Chang
> I recently started using Vim extensively on OSX Tiger and I'd really
> like to use the command key as meta. I found the tip "How do I map the
> Apple key?" on http://macVim.org/OSX/index.php (whose binary I'm
> using). The tip works fine on mappings such as command+s, but when I
> try to map command+h, OSX still interprets that as "hide window". Is
> there a way to block OSX from processing these shortcuts ala
> mac-pass-command-to-system option in emacs?
If your heart is set on using command-H, the answer is complicated by
the fact that Apple's fanatical (but generally beneficial) consistency
of keyboard shortcuts between applications.
If you might be satisfied with some other keystroke than command-H,
jump down to the section of this email entitled "Other Command-Key
Shortcuts in Vim".
Breaking Apple's Command-H Stranglehold
On virtually all Mac OS X applications, Command-H is mapped to "Hide
<application>" and Option- Command-H is mapped to "Hide Other
Applications". While Apple gave us some control over keyboard
shortcuts through the Keyboard and Mouse System Preferences panel,
they did not give us any control over this one (and a handful of its
global friends).
All is not lost, however. "Menu Master"(1) is a $10 System Preference
panel (which they call a "Haxie", but don't let that put you off) that
lets you change any keyboard shortcut in virtually any application,
including Vim.
(1) http://www.unsanity.com/haxies/menumaster
Once downloaded, purchased, and installed according to the product's
instructions, you can change any command-key shortcut in any
application on the fly. It's really pretty amazing that it works, and
is a testament to ... something. Maybe the power of the Mac's Cocoa
framework, maybe the 1337 5K1LL5 of Unsanity's coders.
Launch the Vim GUI. I'm going to assume that you're not using Vim in
terminal mode, because otherwise, you probably would have mentioned
that your terminal gets hidden, rather than Vim.
Then click and release the mouse at the top of the Vim menu -- don't
move down into the menu itself when you release, or, of course, you'll
select the item under the mouse.
Then move the mouse down so that "Hide Vim" is highlighted, and press
the delete key. The command-key shortcut (Command-H) will vanish. For
the rest of that Vim session, Command-H is no longer owned by Apple,
but by you. Feel free to reassign it as described below, in the
section entitled "Other Command-Key Shortcuts on Mac in Vim".
Oops!
Here's a caveat: each time you launch Vim, you will have to reveal the
contents of the Vim menu before Command-H is actually removed. This
does not appear to be a problem with Menu Master (other apps to not
exhibit this behavior), but perhaps with way the Vim binary is built.
If you are religious about not touching the mouse while in Vim, you
can use the Keyboard Shortcuts tab of the Keyboard & Mouse System
Preference panel to activate "Keyboard Navigation > Move focus to the
menu bar", which by default is control-F2. Then, in Vim, you can type
control-F2, right-arrow, down-arrow and escape to reveal the menu and
trigger the keyboard-shortcut-removal.
I have written to Unsanity, the developers of Menu Master, to see if
they've come across this with other apps.
Other Command-Key Shortcuts on Mac in Vim
If all the above seems a little too much like work, you can use any
unused command-key shortcut in your mappings, including shift-
command-keys. Begin the mapping as usual (:map and friends), then type
control-V (to insert character literally), then type your desired
command-key shortcut. Vim displays it like this:
:map <D-m>
or, for shift-command shortcuts:
:map <S-D-m>
Option-command-key and control-command-key shortcuts do not appear to
be possible (nor Shift-option-command, shift-control-command, etc).
Option-Key Shortcuts on Mac in Vim
Many option-key shortcuts can be mapped, too, and don't require the
control-V escaping when entering them. Watch out, though, because (at
least the way my system is set up), almost all option-key combinations
return the same character, a Latin small letter o with stroke (ø). It
is possible that this would be affected by the fileencoding, but maybe
not. Here are the option-key shortcuts that are available to me,
arranged by row on the keyboard. The ones with dashes are unavailable.
The characters shown below may not map to the ones that show up in
Vim, but they're what I get in Mail.app when I type them:
` 1 2 3 4 5 6 7 8 9 0 - +
- ¡ - £ ¢ - § ¶ - ª º - -
q w e r t y u i o p [ ] \
- - * ® - ¥ - - ø - - - «
a s d f g h j k l ; '
å ß - - © - - - ¬ - æ
z x c v b n m , . /
- - ç - - - µ - - ÷
There are five so-called "dead keys" on the Mac keyboard: when holding
down the option-key and typing them, nothing seems to happen. The next
keystroke, however, they reveal their secret identity: they accent the
following character. Unfortunately, of them, only option-e (marked
with an asterisk above) seems to work well in a mapping. Type
option-ee (type "e" twice while holding option) to use this "extra"
option-key.
Vim_Mac Mailing List
Also, did you know that there's a whole mailing list devoted to using
Vim on the Mac? http://groups.google.com/group/vim_mac
Thanks for your question, hope to see you on the other list, too!
Dave
Thanks Dave for the very helpful post!