Home Explore Blog CI



neovim

1st chunk of `runtime/doc/usr_42.txt`
9cd7b061813cb28f1c65124c2239158f630f6f00de2e3e0d0000000100000fa2
*usr_42.txt*	Nvim

		     VIM USER MANUAL - by Bram Moolenaar

			      Add new menus


By now you know that Vim is very flexible.  This includes the menus used in
the GUI.  You can define your own menu entries to make certain commands easily
accessible.  This is for mouse-happy users only.

|42.1|	Introduction
|42.2|	Menu commands
|42.3|	Various
|42.4|	Toolbar and popup menus

     Next chapter: |usr_43.txt|  Using filetypes
 Previous chapter: |usr_41.txt|  Write a Vim script
Table of contents: |usr_toc.txt|

==============================================================================
*42.1*	Introduction

The menus that Vim uses are defined in the file "$VIMRUNTIME/menu.vim".  If
you want to write your own menus, you might first want to look through that
file.
   To define a menu item, use the ":menu" command.  The basic form of this
command is as follows: >

	: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.


ACCELERATORS

The ampersand character (&) is used to indicate an accelerator.  For instance,
you can use Alt-F to select "File" and S to select "Save".  (The 'winaltkeys'
option may disable this though!).  Therefore, the {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.


PRIORITIES

The actual definition of the File.Save menu item is as follows: >

	: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	20     40     50      60       70		9999

	+------------------------------------------------------------+
	| File	Edit  Tools  Syntax  Buffers  Window		Help |
	+------------------------------------------------------------+

Notice that the Help menu is given a very high number, to make it appear on
the far right.
   The second number (340) determines the location of the item within the
pull-down menu.  Lower numbers go on top, higher number on the bottom.  These
are the priorities in the File menu:
>
			+-----------------+
	    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		  |
			+-----------------+
<
Notice that there is room in between the numbers.  This is where you can
insert your own items, if you really want to (it's often better to leave the
standard menus alone and add a new menu for your own items).
   When you create a submenu, you can add another ".number" to the priority.
Thus each name in

Title: Adding New Menus in Vim
Summary
This section of the Vim user manual focuses on customizing the GUI menus. It explains how to add new menu entries using the ":menu" command, define accelerators with the ampersand (&), and control the positioning of menu items using priority numbers. The chapter guides users through understanding the structure of menu definitions in the "$VIMRUNTIME/menu.vim" file and provides examples of how to create custom menu items and submenus.