access the menu entries almost like a real menu
system. To do this, put these commands in your vimrc file: >
:source $VIMRUNTIME/menu.vim
:set wildmenu
:set cpo-=<
:set wcm=<C-Z>
:map <F4> :emenu <C-Z>
Pressing <F4> will start the menu. You can now use the cursor keys to select
a menu entry. Hit <Enter> to execute it. Hit <Esc> if you want to cancel.
Creating New Menus *creating-menus*
*:me* *:menu* *:noreme* *:noremenu*
*E330* *E327* *E331* *E336* *E333*
*E328* *E329* *E337* *E792*
To create a new menu item, use the ":menu" commands. They are mostly like
the ":map" set of commands (see |map-modes|), but the first argument is a menu
item name, given as a path of menus and submenus with a '.' between them,
e.g.: >
:menu File.Save :w<CR>
:inoremenu File.Save <C-O>:w<CR>
:menu Edit.Big\ Changes.Delete\ All\ Spaces :%s/[ ^I]//g<CR>
This last one will create a new item in the menu bar called "Edit", holding
the mouse button down on this will pop up a menu containing the item
"Big Changes", which is a sub-menu containing the item "Delete All Spaces",
which when selected, performs the operation.
To create a menu for terminal mode, use |:tlmenu| instead of |:tmenu| unlike
key mapping (|:tmap|). This is because |:tmenu| is already used for defining
tooltips for menus. See |terminal-input|.
Special characters in a menu name:
*menu-shortcut*
- & The next character is the shortcut key. Make sure each shortcut key is
only used once in a (sub)menu. If you want to insert a literal "&" in the
menu name use "&&".
*menu-text*
- <Tab> Separates the menu name from right-aligned text. This can be used to
show the equivalent typed command. The text "<Tab>" can be used here for
convenience. If you are using a real tab, don't forget to put a backslash
before it!
Example: >
:amenu &File.&Open<Tab>:e :browse e<CR>
[typed literally]
With the shortcut "F" (while keeping the <Alt> key pressed), and then "O",
this menu can be used. The second part is shown as "Open :e". The ":e"
is right aligned, and the "O" is underlined, to indicate it is the shortcut.
*:am* *:amenu* *:an* *:anoremenu*
The ":amenu" command can be used to define menu entries for all modes at once,
except for Terminal mode. To make the command work correctly, a character is
automatically inserted for some modes: >
mode inserted appended
Normal nothing nothing
Visual <C-C> <C-\><C-G>
Insert <C-\><C-O>
Cmdline <C-C> <C-\><C-G>
Op-pending <C-C> <C-\><C-G>
<
Example: >
:amenu File.Next :next^M
is equal to: >
:nmenu File.Next :next^M
:vmenu File.Next ^C:next^M^\^G
:imenu File.Next ^\^O:next^M
:cmenu File.Next ^C:next^M^\^G
:omenu File.Next ^C:next^M^\^G
Careful: In Insert mode this only works for a SINGLE Normal mode command,
because of the CTRL-O. If you have two or more commands, you will need to use
the ":imenu" command. For inserting text in any mode, you can use the
expression register: >
:amenu Insert.foobar "='foobar'<CR>P
The special text <Cmd> begins a "command menu", it executes the command
directly without changing modes. Where you might use ":...<CR>" you can
instead use "<Cmd>...<CR>". See |<Cmd>| for more info. Example: >
anoremenu File.Next <Cmd>next<CR>
Note that <Esc> in Cmdline mode executes the command, like in a mapping. This
is Vi compatible. Use CTRL-C to quit Cmdline mode.
*:nme* *:nmenu* *:nnoreme* *:nnoremenu* *:nunme* *:nunmenu*
Menu commands starting with "n" work in Normal mode.