Insert mode
when the menu is used, Vim first has to go back to Normal mode. ":amenu"
inserts a CTRL-C or CTRL-O for you. For example, if you use this command:
>
:amenu 90.100 Mine.Find\ Word *
Then the resulting menu commands will be:
Normal mode: `*`
Visual mode: CTRL-C `*`
Operator-pending mode: CTRL-C `*`
Insert mode: CTRL-O `*`
Command-line mode: CTRL-C `*`
When in Command-line mode the CTRL-C will abandon the command typed so far.
In Visual and Operator-pending mode CTRL-C will stop the mode. The CTRL-O in
Insert mode will execute the command and then return to Insert mode.
CTRL-O only works for one command. If you need to use two or more
commands, put them in a function and call that function. Example: >
:amenu Mine.Next\ File :call <SID>NextFile()<CR>
:function <SID>NextFile()
: next
: 1/^Code
:endfunction
This menu entry goes to the next file in the argument list with ":next". Then
it searches for the line that starts with "Code".
The <SID> before the function name is the script ID. This makes the
function local to the current Vim script file. This avoids problems when a
function with the same name is defined in another script file. See |<SID>|.
SILENT MENUS
The menu executes the {keys} as if you typed them. For a ":" command this
means you will see the command being echoed on the command line. If it's a
long command, the hit-Enter prompt will appear. That can be very annoying!
To avoid this, make the menu silent. This is done with the <silent>
argument. For example, take the call to NextFile() in the previous example.
When you use this menu, you will see this on the command line:
:call <SNR>34_NextFile() ~
To avoid this text on the command line, insert "<silent>" as the first
argument: >
:amenu <silent> Mine.Next\ File :call <SID>NextFile()<CR>
Don't use "<silent>" too often. It is not needed for short commands. If you
make a menu for someone else, being able to see the executed command will
give them a hint about what they could have typed, instead of using the mouse.
LISTING MENUS
When a menu command is used without a {keys} part, it lists the already
defined menus. You can specify a {menu-item}, or part of it, to list specific
menus. Example: >
:amenu
This lists all menus. That's a long list! Better specify the name of a menu
to get a shorter list: >
:amenu Edit
This lists only the "Edit" menu items for all modes. To list only one
specific menu item for Insert mode: >
:imenu Edit.Undo
Take care that you type exactly the right name. Case matters here. But the
'&' for accelerators can be omitted. The <Tab> and what comes after it can be
left out as well.
DELETING MENUS
To delete a menu, the same command is used as for listing, but with "menu"
changed to "unmenu". Thus ":menu" becomes, ":unmenu", ":nmenu" becomes
":nunmenu", etc. To delete the "Tools.Make" item for Insert mode: >
:iunmenu Tools.Make
You can delete a whole menu, with all its items, by using the menu name.
Example: >
:aunmenu Syntax
This deletes the Syntax menu and all the items in it.
==============================================================================
*42.3* Various
You can change the appearance of the menus with flags in 'guioptions'. In the
default value they are all included, except "M". You can remove a flag with a
command like: >
:set guioptions-=m
<
m When removed the menubar is not displayed.
M When added the default menus are not loaded.
g When removed the inactive menu items are not made grey
but are completely removed. (Does not work on all
systems.)
For translating menu items, see |:menutrans|.
Since the mouse has to be used to select a menu item, it is a good idea to use
the ":browse" command