Nvim :help
pages, generated
from source
using the tree-sitter-vimdoc parser.
:menu {menu-item} {keys}The
{menu-item}
describes where on the menu to put the item. A typical
{menu-item}
is "File.Save", which represents the item "Save" under the
"File" menu. A dot is used to separate the names. Example::menu File.Save :update<CR>The ":update" command writes the file when it was modified. You can add another level: "Edit.Settings.Shiftwidth" defines a submenu "Settings" under the "Edit" menu, with an item "Shiftwidth". You could use even deeper levels. Don't use this too much, you need to move the mouse quite a bit to use such an item. The ":menu" command is very similar to the ":map" command: the left side specifies how the item is triggered and the right hand side defines the characters that are executed.
{keys}
are characters, they are used just like
you would have typed them. Thus in Insert mode, when {keys}
is plain text,
that text is inserted.{menu-item}
looks like
"&File.&Save". The accelerator characters will be underlined in the menu.
You must take care that each key is used only once in each menu. Otherwise
you will not know which of the two will actually be used. Vim doesn't warn
you for this.:menu 10.340 &File.&Save<Tab>:w :confirm w<CR>The number 10.340 is called the priority number. It is used by the editor to decide where it places the menu item. The first number (10) indicates the position on the menu bar. Lower numbered menus are positioned to the left, higher numbers to the right. These are the priorities used for the standard menus:
+-----------------+ 10.310 |Open... | 10.320 |Split-Open... | 10.325 |New | 10.330 |Close | 10.335 |---------------- | 10.340 |Save | 10.350 |Save As... | 10.400 |---------------- | 10.410 |Split Diff with | 10.420 |Split Patched By | 10.500 |---------------- | 10.510 |Print | 10.600 |---------------- | 10.610 |Save-Exit | 10.620 |Exit | +-----------------+
{menu-item}
has its priority number.{menu-item}
in this example is "&File.&Save<Tab>:w". This brings up an
important point: {menu-item}
must be one word. If you want to put a dot,
space or tabs in the name, you either use the <> notation (<Space>
and <Tab>
,
for instance) or use the backslash (\) escape.:menu 10.305 &File.&Do\ It\.\.\. :exit<CR>In this example, the name of the menu item "Do It..." contains a space and the command is ":exit<CR>".
<Tab>
character in a menu name is used to separate the part that defines
the menu name from the part that gives a hint to the user. The part after the
<Tab>
is displayed right aligned in the menu. In the File.Save menu the name
used is "&File.&Save<Tab>:w". Thus the menu name is "File.Save" and the hint
is ":w".:amenu 20.510 Edit.-sep3- :
{keys}
you
give are to be executed in Normal mode. When Vim is in Visual or 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:
*
Visual mode: CTRL-C
*
Operator-pending mode: CTRL-C
*
Insert mode: CTRL-O
*
Command-line mode: CTRL-C
*
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 :endfunctionThis 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>.{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:<SNR>
34_NextFile():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.
{keys}
part, it lists the already
defined menus. You can specify a {menu-item}
, or part of it, to list specific
menus. Example::amenuThis lists all menus. That's a long list! Better specify the name of a menu to get a shorter list:
:amenu EditThis lists only the "Edit" menu items for all modes. To list only one specific menu item for Insert mode:
:imenu Edit.UndoTake 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.:iunmenu Tools.MakeYou can delete a whole menu, with all its items, by using the menu name. Example:
:aunmenu SyntaxThis deletes the Syntax menu and all the items in it.
:set guioptions-=m
:amenu File.Open :browse confirm edit<CR>The ":browse" makes a file browser appear to select the file to edit. The ":confirm" will pop up a dialog when the current buffer has changes. You can then select to save the changes, throw them away or cancel the command. For more complicated items, the confirm() and inputdialog() functions can be used. The default menus contain a few examples.
{menu-item}
named "ToolBar.New" causes the "New" icon to appear
on the toolbar.
The Vim editor has 28 built-in icons. You can find a table here:
builtin-tools. Most of them are used in the default toolbar. You can
redefine what these items do (after the default menus are setup).
You can add another bitmap for a toolbar item. Or define a new toolbar
item with a bitmap. For example, define a new toolbar item with::tmenu ToolBar.Compile Compile the current file :amenu ToolBar.Compile :!cc %:S -o %:r:S<CR>Now you need to create the icon. For MS-Windows it must be in bitmap format, with the name "Compile.bmp". For Unix XPM format is used, the file name is "Compile.xpm". The size must be 18 by 18 pixels. On MS-Windows other sizes can be used as well, but it will look ugly. Put the bitmap in the directory "bitmaps" in one of the directories from 'runtimepath'. E.g., for Unix "~/.config/nvim/bitmaps/Compile.xpm".
:tmenu ToolBar.Make Run make in the current directory