Unbind ⌘F and Remap It
You can “unbind” ⌘F (Command+F; written as
<D-f> in Vim) from the Edit > Find > Find… menu item with MacVim’s
:macmenu command and then map it with a normal
macmenu Edit.Find.Find\.\.\. key=<nop>
map <D-f> /
:macmenu command is only effective if you put it in your
~/.gvimrc, so the above lines should be placed there.
The Mac OS X find dialog will still be displayed if you invoke the menu item itself (clicking on it or using
Redefine the Menu Item
An alternate approach is to redefine the menu items themselves. This would be inappropriate if you wanted to bind ⌘F to some different function (since the Edit > Find > Find… menu item would do something other than a search!), but it might be acceptable since you just want to start a different style of search.
You can use variations on the
:menu command to redefine the menu item to be (more or less) equivalent to typing
nmenu Edit.Find.Find\.\.\. /
vmenu Edit.Find.Find\.\.\. <C-C>/
imenu Edit.Find.Find\.\.\. <C-\><C-O>/
cmenu Edit.Find.Find\.\.\. <C-C>/
omenu Edit.Find.Find\.\.\. <C-C>/
The best place for the these commands is your
~/.gvimrc (though for slightly different reasons than for the
:macmenu command above).
These commands cover normal mode, the visual and select modes, insert mode, command mode, and operator-pending mode.
This approach means that both pressing ⌘F and selecting the menu item will start a
/-based search (i.e. the mode indicated by the cursor just after
/ in the command line area instead of using the GUI-based
As noted in each of the above suggestions, the placement of the commands is important. They should each work correctly if you put them in
~/.gvimrc. But some of the commands can also be effective in other contexts.
The biggest influence on the effectiveness of the menu commands is their position with respect to the sourcing of
$VIMRUNTIME/menu.vim. This file contains the commands that build the menus. It is automatically sourced between
~/.gvimrc, but it can also be source manually (e.g. see
:help console-menus). Most of the commands in this file are protected by an if statement so that they are only ever run once. This means that you could source it manually and then redefine some of the menu items in your
.vimrc so that you could use the changed menu items in both the console and GUI modes.
The commands from the “Redefine the Menu Item” solution can be effective in your
~/.vimrc if you put
source $VIMRUNTIME/menu.vim before them. If you do not source
menu.vim first, then your definitions will be overwritten if/when it is sourced later (i.e. later in
~/.vimrc; automatically, when switching on syntax highlighting; automatically, before
~./gvimrc for GUI-based instances of Vim; or manually, at a
Most GUI instances of Vim use
Edit.Find\.\.\. for the menu item, but MacVim inserts an
Find submenu in the hierarchy to match the usual Mac OS X arrangement, so the commands should be protected by
has('gui_macvim') (so that they do not cause errors if you ever use your startup file with a non-MacVim build of Vim).
macmenu command is only effective at startup time. You can type it in at a
: prompt, but it does not actually change any setting if you use it that way. This is mentioned in
:help :macmenu, but I missed it the first several times I skimmed the documentation:
This command must be used in a startup file, for example in "~/.gvimrc". It has no effect otherwise.
menu.vim, after the menu items have been created, some
macmenu commands are used to establish the default shortcut keys for the menu items and the GUI “actions” they trigger. However, unlike the menu definition commands in the same file, the
macmenu commands that establish these bindings are not protected from being run multiple times. This means you can use
macmenu commands in
~/.vimrc to establish bindings/actions for menu items that do not have default bindings/actions, but that you must use
~/.gvimrc to modify the bindings/actions that are established in
menu.vim. This seems like a mild bug in the MacVim version of
So, the only (currently) valid place for
macmenu command is in
~/.gvimrc, after the final startup-time sourcing of
menu.vim. And again, some of the menu hierarchies are specific to MacVim, so the commands should be protected with
<D-…> key notation looks like it is valid in most builds of Vim (though it is probably only actually usable on “Mac” builds). So, you should be able to safely map Command keys in your
~/.vimrc without worrying about causing errors for other builds of Vim. Of course, in MacVim, if you are mapping a key that is usually a menu item shortcut, you will also have to unbind it from the menu item (which means an accompanying
macmenu command in