robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1*gui.txt* Nvim 2 3 4 VIM REFERENCE MANUAL by Bram Moolenaar 5 6 7Nvim Graphical User Interface *gui* *GUI* 8 9Any client that supports the Nvim |ui-protocol| can be used as a UI for Nvim. 10And multiple UIs can connect to the same Nvim instance! The terms "UI" and 11"GUI" are often used interchangeably because all Nvim UI clients have the same 12potential capabilities; the "TUI" refers to a UI client that outputs to your 13terminal, whereas a "GUI" outputs directly to the OS graphics system. 14 15Except where noted, this document describes UI capabilities available to both 16TUI and GUI (assuming the UI supports the given feature). See |TUI| for notes 17specific to the terminal UI. Help tags with the "gui-" prefix refer to UI 18features, whereas help tags with the "ui-" prefix refer to the |ui-protocol|. 19 20 Type |gO| to see the table of contents. 21 22============================================================================== 23Third-party GUIs *third-party-guis* *vscode* 24 25Nvim provides a builtin "terminal UI" (|TUI|), but also works with many 26(third-party) GUIs which may provide a fresh look or extra features on top of 27Nvim. For example, "vscode-neovim" essentially allows you to use VSCode as 28a Nvim GUI. 29 30- vscode-neovim (Nvim in VSCode!) https://github.com/vscode-neovim/vscode-neovim 31- Firenvim (Nvim in your web browser!) https://github.com/glacambre/firenvim 32- Neovide https://neovide.dev/ 33- Goneovim https://github.com/akiyosi/goneovim 34- Nvy https://github.com/RMichelsen/Nvy 35- Neovim-Qt (Qt5) https://github.com/equalsraf/neovim-qt 36- VimR (macOS) https://github.com/qvacua/vimr 37- Others https://github.com/neovim/neovim/wiki/Related-projects#gui 38 39============================================================================== 40Starting the GUI *gui-config* *gui-start* 41 42 *ginit.vim* *gui-init* *gvimrc* *$MYGVIMRC* 43For GUI-specific configuration Nvim provides the |UIEnter| event. This 44happens after other |initialization|s, or whenever a UI attaches (multiple UIs 45can connect to any Nvim instance). 46 47Example: this sets "g:gui" to the value of the UI's "rgb" field: > 48 :autocmd UIEnter * let g:gui = filter(nvim_list_uis(),{k,v-> v.chan==v:event.chan})[0].rgb 49< 50 *ui-lifecycle* 51Nvim's |clientserver| architecture allows you to |:restart|, |:detach| (Nvim 52continues in the background), or |:connect| to another instance. 53 54Use cases: 55- keep the session running on remote machines after (unexpected) SSH disconnect 56- open files in an existing session from your OS file explorer 57- run Nvim as a background process (daemon/service), atttach/detach as needed 58 59------------------------------------------------------------------------------ 60Stop or detach the current UI 61 62 *:detach* *E5768* 63:[range]detach Detaches the current UI. Other UIs (if any) remain attached, 64 unless [range] was given. If [range] is "%", all UIs _except_ 65 the current UI are detached: >vim 66 67 :%detach 68 69< The server (typically `nvim --embed`) continues running as 70 a background process. Use |:connect| or |--remote-ui| to 71 reattach. Before detaching, you may want to note the server 72 address: 73 >vim 74 :echo v:servername 75< 76 Note: The server closes the UI RPC channel, so :detach works 77 for any GUI/UI; but if the client isn't expecting this, it may 78 (incorrectly) report an error. 79 80 *:detach!* 81:detach! Marks the current UI as "detachable" without detaching it now: 82 the UI stays attached, but if it later disconnects 83 unexpectedly (e.g. host terminal closed, ssh disconnect, 84 etc.), the server keeps running in the background. 85 Use |:connect| or |--remote-ui| to reattach. 86 87 If you always want Nvim to survive accidental disconnect, put 88 this in your config: >vim 89 90 silent detach! 91< 92 93------------------------------------------------------------------------------ 94Restart Nvim 95 96 *:restart* *:restart!* *E5201* 97:restart[!] [+cmd] [command] 98 Restarts Nvim. Saves and restores the current session, unless 99 [!] is given. Sets |v:exitreason|. See also |ZR|. 100 101 1. Saves the current session (unless [!] was given). 102 2. Stops Nvim using `:qall` (or |+cmd|, if given). 103 3. Starts a new Nvim server using the same |v:argv| (except 104 `-- [file…]` files and `-S [file]`), and sets |v:startreason|. 105 4. Restores the saved session (unless [!] was given). 106 5. Attaches all UIs to the new Nvim server and runs `[command]` 107 on it. 108 109 Example: discard changes and stop with `:qall!`, then restart: > 110 :restart +qall! 111< Example: restart and (manually) restore the session: > 112 :mksession! Session.vim | restart! source Session.vim 113< Example: restart and update plugins: > 114 :restart packupdate 115< 116 Note: 117 • Only works if the UI and server are on the same system. 118 • Windows limitation: during +cmd execution, |v:servername| 119 refers to a temporary address. 120 • If no UI handles the "restart" event, this leaves a dangling 121 process. 122 • To adjust what `:restart` restores, set 'sessionoptions'. 123 124------------------------------------------------------------------------------ 125Connect UI to a different server 126 127 *:connect* 128:connect {address} 129 Attaches the UI to another Nvim instance: detaches from the 130 current server, then attaches to {address}. 131 132 Note: If the current UI hasn't implemented the "connect" UI 133 event, this command is equivalent to |:detach|. 134 135:connect! {address} 136 Same as |:connect| but it also stops the detached server if 137 no other UI is currently attached to it. 138 139------------------------------------------------------------------------------ 140GUI commands 141 142 *:winp* *:winpos* *E188* 143:winp[os] 144 Display current position of the top left corner of the GUI vim 145 window in pixels. Does not work in all versions. 146 Also see |getwinpos()|, |getwinposx()| and |getwinposy()|. 147 148:winp[os] {X} {Y} *E466* 149 Put the GUI vim window at the given {X} and {Y} coordinates. 150 The coordinates should specify the position in pixels of the 151 top left corner of the window. 152 When the GUI window has not been opened yet, the values are 153 remembered until the window is opened. The position is 154 adjusted to make the window fit on the screen (if possible). 155 156 *:wi* *:win* *:winsize* *E465* 157:win[size] {width} {height} 158 Set the window height to {width} by {height} characters. 159 Obsolete, use ":set lines=11 columns=22". 160 161============================================================================== 162Using the mouse *mouse-using* 163 164 *mouse-mode-table* *mouse-overview* 165Overview of what the mouse buttons do, when 'mousemodel' is "extend": 166 167 *<S-LeftMouse>* *<A-RightMouse>* *<S-RightMouse>* *<RightDrag>* 168 *<RightRelease>* *<LeftDrag>* 169Normal Mode: > 170 event position selection change action 171 cursor window 172 --------------------------------------------------------------------------- 173 <LeftMouse> yes end yes 174 <C-LeftMouse> no no change no toggle multicursor 175 <S-LeftMouse> yes no change yes "*" (2) 176 <LeftDrag> yes start or extend (1) no 177 <LeftRelease> yes start or extend (1) no 178 <MiddleMouse> yes if not active no put 179 <MiddleMouse> yes if active no yank and put 180 <RightMouse> yes start or extend yes 181 <A-RightMouse> yes start or extend blockw. yes 182 <S-RightMouse> yes no change yes "#" (2) 183 <C-RightMouse> no no change no "CTRL-T" 184 <RightDrag> yes extend no 185 <RightRelease> yes extend no 186 187Insert or Replace Mode: > 188 event position selection change action 189 cursor window 190 --------------------------------------------------------------------------- 191 <LeftMouse> yes (cannot be active) yes 192 <C-LeftMouse> no (cannot be active) no no-op 193 <S-LeftMouse> yes (cannot be active) yes "CTRL-O*" (2) 194 <LeftDrag> yes start or extend (1) no like CTRL-O (1) 195 <LeftRelease> yes start or extend (1) no like CTRL-O (1) 196 <MiddleMouse> no (cannot be active) no put register 197 <RightMouse> yes start or extend yes like CTRL-O 198 <A-RightMouse> yes start or extend blockw. yes 199 <S-RightMouse> yes (cannot be active) yes "CTRL-O#" (2) 200 <C-RightMouse> no (cannot be active) no "CTRL-O CTRL-T" 201 202In a help window: > 203 event position selection change action 204 cursor window 205 --------------------------------------------------------------------------- 206 <2-LeftMouse> yes (cannot be active) no "^]" (jump to help tag) 207 208When 'mousemodel' is "popup", these are different: 209 210 *<A-LeftMouse>* 211Normal Mode: > 212 event position selection change action 213 cursor window 214 --------------------------------------------------------------------------- 215 <S-LeftMouse> yes start or extend (1) no 216 <A-LeftMouse> yes start/extend blockw no 217 <RightMouse> no popup menu no 218 219Insert or Replace Mode: > 220 event position selection change action 221 cursor window 222 --------------------------------------------------------------------------- 223 <S-LeftMouse> yes start or extend (1) no like CTRL-O (1) 224 <A-LeftMouse> yes start/extend blockw no 225 <RightMouse> no popup menu no 226 227(1) only if mouse pointer moved since press 228(2) only if click is in same buffer 229 230Clicking the left mouse button causes the cursor to be positioned. If the 231click is in another window that window is made the active window. When 232editing the command-line the cursor can only be positioned on the 233command-line. When in Insert mode Vim remains in Insert mode. If 'scrolloff' 234is set, and the cursor is positioned within 'scrolloff' lines from the window 235border, the text is scrolled. 236 237A selection can be started by pressing the left mouse button on the first 238character, moving the mouse to the last character, then releasing the mouse 239button. You will not always see the selection until you release the button, 240only in some versions (GUI, Win32) will the dragging be shown immediately. 241Note that you can make the text scroll by moving the mouse at least one 242character in the first/last line in the window when 'scrolloff' is non-zero. 243 244In Normal, Visual and Select mode clicking the right mouse button causes the 245Visual area to be extended. When 'mousemodel' is "popup", the left button has 246to be used while keeping the shift key pressed. When clicking in a window 247which is editing another buffer, the Visual or Select mode is stopped. 248 249In Normal, Visual and Select mode clicking the right mouse button with the alt 250key pressed causes the Visual area to become blockwise. When 'mousemodel' is 251"popup" the left button has to be used with the alt key. Note that this won't 252work on systems where the window manager consumes the mouse events when the 253alt key is pressed (it may move the window). 254 255 *double-click* *<2-LeftMouse>* *<3-LeftMouse>* *<4-LeftMouse>* 256Double, triple and quadruple clicks are supported. For selecting text, extra 257clicks extend the selection: > 258 259 click select 260 --------------------------------- 261 double word or % match 262 triple line 263 quadruple rectangular block 264 265Exception: In a :help window, double-click jumps to help for the word that is 266clicked on. 267 268Double-click on a word selects that word. 'iskeyword' is used to specify 269which characters are included in a word. Double-click on a character that has 270a match selects until that match (like using "v%"). If the match is an 271#if/#else/#endif block, the selection becomes linewise. The time for 272double-clicking can be set with the 'mousetime' option. 273 274Example: configure double-click to jump to the tag under the cursor: >vim 275 :map <2-LeftMouse> :exe "tag " .. expand("<cword>")<CR> 276 277Dragging the mouse with a double-click (button-down, button-up, button-down 278and then drag) will result in whole words to be selected. This continues 279until the button is released, at which point the selection is per character 280again. 281 282For scrolling with the mouse see |scroll-mouse-wheel|. 283 284In Insert mode, when a selection is started, Vim goes into Normal mode 285temporarily. When Visual or Select mode ends, it returns to Insert mode. 286This is like using CTRL-O in Insert mode. Select mode is used when the 287'selectmode' option contains "mouse". 288 289 *X1Mouse* *X1Drag* *X1Release* 290 *X2Mouse* *X2Drag* *X2Release* 291 *<MiddleRelease>* *<MiddleDrag>* 292Mouse clicks can be mapped using these |keycodes|: > 293 code mouse button normal action 294 --------------------------------------------------------------------------- 295 <LeftMouse> left pressed set cursor position 296 <LeftDrag> left moved while pressed extend selection 297 <LeftRelease> left released set selection end 298 <MiddleMouse> middle pressed paste text at cursor position 299 <MiddleDrag> middle moved while pressed - 300 <MiddleRelease> middle released - 301 <RightMouse> right pressed extend selection 302 <RightDrag> right moved while pressed extend selection 303 <RightRelease> right released set selection end 304 <X1Mouse> X1 button pressed - 305 <X1Drag> X1 moved while pressed - 306 <X1Release> X1 button release - 307 <X2Mouse> X2 button pressed - 308 <X2Drag> X2 moved while pressed - 309 <X2Release> X2 button release - 310 311The X1 and X2 buttons refer to the extra buttons found on some mice (e.g. the 312right thumb). 313 314Examples: >vim 315 :noremap <MiddleMouse> <LeftMouse><MiddleMouse> 316Paste at the position of the middle mouse button click (otherwise the paste 317would be done at the cursor position). >vim 318 319 :noremap <LeftRelease> <LeftRelease>y 320Immediately yank the selection, when using Visual mode. 321 322Note the use of ":noremap" instead of "map" to avoid a recursive mapping. 323>vim 324 :map <X1Mouse> <C-O> 325 :map <X2Mouse> <C-I> 326Map the X1 and X2 buttons to go forwards and backwards in the jump list, see 327|CTRL-O| and |CTRL-I|. 328 329 *mouse-swap-buttons* *pi_swapmouse* 330To swap the meaning of the left and right mouse buttons: >vim 331 :noremap <LeftMouse> <RightMouse> 332 :noremap <LeftDrag> <RightDrag> 333 :noremap <LeftRelease> <RightRelease> 334 :noremap <RightMouse> <LeftMouse> 335 :noremap <RightDrag> <LeftDrag> 336 :noremap <RightRelease> <LeftRelease> 337 :noremap g<LeftMouse> <C-RightMouse> 338 :noremap g<RightMouse> <C-LeftMouse> 339 :noremap! <LeftMouse> <RightMouse> 340 :noremap! <LeftDrag> <RightDrag> 341 :noremap! <LeftRelease> <RightRelease> 342 :noremap! <RightMouse> <LeftMouse> 343 :noremap! <RightDrag> <LeftDrag> 344 :noremap! <RightRelease> <LeftRelease> 345< 346 347The `swapmouse` plugin does exactly this. Use |pack-add| to load it: >vim 348 :packadd! swapmouse 349< 350 351============================================================================== 352Scrollbars *gui-scrollbars* 353 354There are vertical scrollbars and a horizontal scrollbar. You may 355configure which ones appear with the 'guioptions' option. 356 357The interface looks like this (with `:set guioptions=mlrb`): 358> 359 +------------------------------+ 360 | File Edit Help | <- Menu bar (m) 361 +-+--------------------------+-+ 362 |^| |^| 363 |#| Text area. |#| 364 | | | | 365 |v|__________________________|v| 366 Normal status line -> |-+ File.c 5,2 +-| 367 between Vim windows |^|""""""""""""""""""""""""""|^| 368 | | | | 369 | | Another file buffer. | | 370 | | | | 371 |#| |#| 372 Left scrollbar (l) -> |#| |#| <- Right 373 |#| |#| scrollbar (r) 374 | | | | 375 |v| |v| 376 +-+--------------------------+-+ 377 | |< #### >| | <- Bottom 378 +-+--------------------------+-+ scrollbar (b) 379< 380Any of the scrollbar or menu components may be turned off by not putting the 381appropriate letter in the 'guioptions' string. The bottom scrollbar is 382only useful when 'nowrap' is set. 383 384 385VERTICAL SCROLLBARS *gui-vert-scroll* 386 387Each Vim window has a scrollbar next to it which may be scrolled up and down 388to move through the text in that buffer. The size of the scrollbar-thumb 389indicates the fraction of the buffer which can be seen in the window. 390When the scrollbar is dragged all the way down, the last line of the file 391will appear in the top of the window. 392 393If a window is shrunk to zero height (by the growth of another window) its 394scrollbar disappears. It reappears when the window is restored. 395 396If a window is vertically split, it will get a scrollbar when it is the 397current window and when, taking the middle of the current window and drawing a 398vertical line, this line goes through the window. 399When there are scrollbars on both sides, and the middle of the current window 400is on the left half, the right scrollbar column will contain scrollbars for 401the rightmost windows. The same happens on the other side. 402 403 404HORIZONTAL SCROLLBARS *gui-horiz-scroll* 405 406The horizontal scrollbar (at the bottom of the Vim GUI) may be used to 407scroll text sideways when the 'wrap' option is turned off. The 408scrollbar-thumb size is such that the text of the longest visible line may be 409scrolled as far as possible left and right. The cursor is moved when 410necessary, it must remain on a visible character (unless 'virtualedit' is 411set). 412 413Computing the length of the longest visible line takes quite a bit of 414computation, and it has to be done every time something changes. If this 415takes too much time or you don't like the cursor jumping to another line, 416include the 'h' flag in 'guioptions'. Then the scrolling is limited by the 417text of the current cursor line. 418 419============================================================================== 420Drag and drop *drag-n-drop* 421 422You can drag and drop one or more files into the Vim window, where they will 423be opened as if a |:drop| command was used. 424 425If you hold down Shift while doing this, Vim changes to the first dropped 426file's directory. If you hold Ctrl Vim will always split a new window for the 427file. Otherwise it's only done if the current buffer has been changed. 428 429You can also drop a directory on Vim. This starts the explorer plugin for 430that directory (assuming it was enabled, otherwise you'll get an error 431message). Keep Shift pressed to change to the directory instead. 432 433If Vim happens to be editing a command line, the names of the dropped files 434and directories will be inserted at the cursor. This allows you to use these 435names with any Ex command. Special characters (space, tab, double quote and 436"|"; backslash on non-MS-Windows systems) will be escaped. 437 438============================================================================== 439Menus *menus* 440 441For an introduction see |usr_42.txt| in the user manual. 442 443 444Using Menus *using-menus* 445 446Basically, menus can be used just like mappings. You can define your own 447menus, as many as you like. 448Long-time Vim users won't use menus much. But the power is in adding your own 449menus and menu items. They are most useful for things that you can't remember 450what the key sequence was. 451 452For creating menus in a different language, see |:menutrans|. 453 454 *menu.vim* 455The default menus are read from the file "$VIMRUNTIME/menu.vim". See 456|$VIMRUNTIME| for where the path comes from. You can set up your own menus. 457Starting off with the default set is a good idea. You can add more items, or, 458if you don't like the defaults at all, start with removing all menus 459|:unmenu-all|. You can also avoid the default menus being loaded by adding 460this line to your vimrc file (NOT your gvimrc file!): > 461 :let did_install_default_menus = 1 462If you also want to avoid the Syntax menu: > 463 :let did_install_syntax_menu = 1 464The first item in the Syntax menu can be used to show all available filetypes 465in the menu (which can take a bit of time to load). If you want to have all 466filetypes already present at startup, add: > 467 :let do_syntax_sel_menu = 1 468 469Note that the menu.vim is sourced when `:syntax on` or `:filetype on` is 470executed or after your .vimrc file is sourced. This means that the 'encoding' 471option and the language of messages (`:language messages`) must be set before 472that (if you want to change them). 473 474 *console-menus* 475Although this documentation is in the GUI section, you can actually use menus 476in console mode too. You will have to load |menu.vim| explicitly then, it is 477not done by default. You can use the |:emenu| command and command-line 478completion with 'wildmenu' to access the menu entries almost like a real menu 479system. To do this, put these commands in your vimrc file: > 480 :source $VIMRUNTIME/menu.vim 481 :set wildmenu 482 :set cpo-=< 483 :set wcm=<C-Z> 484 :map <F4> :emenu <C-Z> 485Pressing <F4> will start the menu. You can now use the cursor keys to select 486a menu entry. Hit <Enter> to execute it. Hit <Esc> if you want to cancel. 487 488Creating New Menus *creating-menus* 489 490 *:me* *:menu* *:noreme* *:noremenu* 491 *E330* *E327* *E331* *E336* *E333* 492 *E328* *E329* *E337* *E792* *E1310* 493To create a new menu item, use the ":menu" commands. They are mostly like 494the ":map" set of commands (see |map-modes|), but the first argument is a menu 495item name, given as a path of menus and submenus with a '.' between them, 496e.g.: > 497 498 :menu File.Save :w<CR> 499 :inoremenu File.Save <C-O>:w<CR> 500 :menu Edit.Big\ Changes.Delete\ All\ Spaces :%s/[ ^I]//g<CR> 501 502This last one will create a new item in the menu bar called "Edit", holding 503the mouse button down on this will pop up a menu containing the item 504"Big Changes", which is a sub-menu containing the item "Delete All Spaces", 505which when selected, performs the operation. 506 507To create a menu for terminal mode, use |:tlmenu| instead of |:tmenu| unlike 508key mapping (|:tmap|). This is because |:tmenu| is already used for defining 509tooltips for menus. See |terminal-input|. 510 511Special characters in a menu name: 512 513 *menu-shortcut* 514- & The next character is the shortcut key. Make sure each shortcut key is 515 only used once in a (sub)menu. If you want to insert a literal "&" in the 516 menu name use "&&". 517 *menu-text* 518- <Tab> Separates the menu name from right-aligned text. This can be used to 519 show the equivalent typed command. The text "<Tab>" can be used here for 520 convenience. If you are using a real tab, don't forget to put a backslash 521 before it! 522 523Example: > 524 525 :amenu &File.&Open<Tab>:e :browse e<CR> 526 527[typed literally] 528With the shortcut "F" (while keeping the <Alt> key pressed), and then "O", 529this menu can be used. The second part is shown as "Open :e". The ":e" 530is right aligned, and the "O" is underlined, to indicate it is the shortcut. 531 532 *:am* *:amenu* *:an* *:anoremenu* 533The ":amenu" command can be used to define menu entries for all modes at once, 534except for Terminal mode. To make the command work correctly, a character is 535automatically inserted for some modes: > 536 mode inserted appended 537 Normal nothing nothing 538 Visual <C-C> <C-\><C-G> 539 Insert <C-\><C-O> 540 Cmdline <C-C> <C-\><C-G> 541 Op-pending <C-C> <C-\><C-G> 542< 543Example: > 544 545 :amenu File.Next :next^M 546 547is equal to: > 548 549 :nmenu File.Next :next^M 550 :vmenu File.Next ^C:next^M^\^G 551 :imenu File.Next ^\^O:next^M 552 :cmenu File.Next ^C:next^M^\^G 553 :omenu File.Next ^C:next^M^\^G 554 555Careful: In Insert mode this only works for a SINGLE Normal mode command, 556because of the CTRL-O. If you have two or more commands, you will need to use 557the ":imenu" command. For inserting text in any mode, you can use the 558expression register: > 559 560 :amenu Insert.foobar "='foobar'<CR>P 561 562The special text <Cmd> begins a "command menu", it executes the command 563directly without changing modes. Where you might use ":...<CR>" you can 564instead use "<Cmd>...<CR>". See |<Cmd>| for more info. Example: > 565 anoremenu File.Next <Cmd>next<CR> 566 567Note that <Esc> in Cmdline mode executes the command, like in a mapping. This 568is Vi compatible. Use CTRL-C to quit Cmdline mode. 569 570 *:nme* *:nmenu* *:nnoreme* *:nnoremenu* *:nunme* *:nunmenu* 571Menu commands starting with "n" work in Normal mode. |mapmode-n| 572 573 *:ome* *:omenu* *:onoreme* *:onoremenu* *:ounme* *:ounmenu* 574Menu commands starting with "o" work in Operator-pending mode. |mapmode-o| 575 576 *:vme* *:vmenu* *:vnoreme* *:vnoremenu* *:vunme* *:vunmenu* 577Menu commands starting with "v" work in Visual mode. |mapmode-v| 578 579 *:xme* *:xmenu* *:xnoreme* *:xnoremenu* *:xunme* *:xunmenu* 580Menu commands starting with "x" work in Visual and Select mode. |mapmode-x| 581 582 *:sme* *:smenu* *:snoreme* *:snoremenu* *:sunme* *:sunmenu* 583Menu commands starting with "s" work in Select mode. |mapmode-s| 584 585 *:ime* *:imenu* *:inoreme* *:inoremenu* *:iunme* *:iunmenu* 586Menu commands starting with "i" work in Insert mode. |mapmode-i| 587 588 *:cme* *:cmenu* *:cnoreme* *:cnoremenu* *:cunme* *:cunmenu* 589Menu commands starting with "c" work in Cmdline mode. |mapmode-c| 590 591 *:tlm* *:tlmenu* *:tln* *:tlnoremenu* *:tlu* *:tlunmenu* 592Menu commands starting with "tl" work in Terminal mode. |mapmode-t| 593 594 *:menu-<silent>* *:menu-silent* 595To define a menu which will not be echoed on the command line, add 596"<silent>" as the first argument. Example: > 597 :menu <silent> Settings.Ignore\ case :set ic<CR> 598The ":set ic" will not be echoed when using this menu. Messages from the 599executed command are still given though. To shut them up too, add a ":silent" 600in the executed command: > 601 :menu <silent> Search.Header :exe ":silent normal /Header\r"<CR> 602"<silent>" may also appear just after "<script>". 603 604 *:menu-<script>* *:menu-script* 605The "to" part of the menu will be inspected for mappings. If you don't want 606this, use the ":noremenu" command (or the similar one for a specific mode). 607If you do want to use script-local mappings, add "<script>" as the very first 608argument to the ":menu" command or just after "<silent>". 609 610 *menu-priority* 611You can give a priority to a menu. Menus with a higher priority go more to 612the right. The priority is given as a number before the ":menu" command. 613Example: > 614 :80menu Buffer.next :bn<CR> 615 616The default menus have these priorities: > 617 File 10 618 Edit 20 619 Tools 40 620 Syntax 50 621 Buffers 60 622 Window 70 623 Help 9999 624< 625When no or zero priority is given, 500 is used. 626The priority for the PopUp menu is not used. 627 628You can use a priority higher than 9999, to make it go after the Help menu, 629but that is non-standard and is discouraged. The highest possible priority is 630about 32000. The lowest is 1. 631 632 *sub-menu-priority* 633The same mechanism can be used to position a sub-menu. The priority is then 634given as a dot-separated list of priorities, before the menu name: > 635 :menu 80.500 Buffer.next :bn<CR> 636Giving the sub-menu priority is only needed when the item is not to be put 637in a normal position. For example, to put a sub-menu before the other items: > 638 :menu 80.100 Buffer.first :brew<CR> 639Or to put a sub-menu after the other items, and further items with default 640priority will be put before it: > 641 :menu 80.900 Buffer.last :blast<CR> 642When a number is missing, the default value 500 will be used: > 643 :menu .900 myMenu.test :echo "text"<CR> 644The menu priority is only used when creating a new menu. When it already 645existed, e.g., in another mode, the priority will not change. Thus, the 646priority only needs to be given the first time a menu is used. 647An exception is the PopUp menu. There is a separate menu for each mode 648(Normal, Op-pending, Visual, Insert, Cmdline). The order in each of these 649menus can be different. This is different from menu-bar menus, which have 650the same order for all modes. 651NOTE: sub-menu priorities currently don't work for all versions of the GUI. 652 653 *menu-separator* *E332* 654Menu items can be separated by a special item that inserts some space between 655items. Depending on the system this is displayed as a line or a dotted line. 656These items must start with a '-' and end in a '-'. The part in between is 657used to give it a unique name. Priorities can be used as with normal items. 658Example: > 659 :menu Example.item1 :do something 660 :menu Example.-Sep- : 661 :menu Example.item2 :do something different 662Note that the separator also requires a rhs. It doesn't matter what it is, 663because the item will never be selected. Use a single colon to keep it 664simple. 665 666 *gui-toolbar* 667The default toolbar is setup in menu.vim. The display of the toolbar is 668controlled by the 'guioptions' letter 'T'. You can thus have menu & toolbar 669together, or either on its own, or neither. The appearance is controlled by 670the 'toolbar' option. You can choose between an image, text or both. 671 672 *toolbar-icon* 673The toolbar is defined as a special menu called ToolBar, which only has one 674level. Vim interprets the items in this menu as follows: 675- 1 If an "icon=" argument was specified, the file with this name is used. 676 The file can either be specified with the full path or with the base name. 677 In the last case it is searched for in the "bitmaps" directory in 678 'runtimepath', like in point 3. Examples: > 679 :amenu icon=/usr/local/pixmaps/foo_icon.xpm ToolBar.Foo :echo "Foo"<CR> 680 :amenu icon=FooIcon ToolBar.Foo :echo "Foo"<CR> 681< Note that in the first case the extension is included, while in the second 682 case it is omitted. 683 If the file cannot be opened the next points are tried. 684 A space in the file name must be escaped with a backslash. 685 A menu priority must come _after_ the icon argument: > 686 :amenu icon=foo 1.42 ToolBar.Foo :echo "42!"<CR> 687- 2 An item called 'BuiltIn##', where ## is a number, is taken as number ## of 688 the built-in bitmaps available in Vim. Currently there are 31 numbered 689 from 0 to 30 which cover most common editing operations |builtin-tools|. > 690 :amenu ToolBar.BuiltIn22 :call SearchNext("back")<CR> 691- 3 An item with another name is first searched for in the directory 692 "bitmaps" in 'runtimepath'. If found, the bitmap file is used as the 693 toolbar button image. Note that the exact filename is OS-specific: For 694 example, under Win32 the command > 695 :amenu ToolBar.Hello :echo "hello"<CR> 696< would find the file 'hello.bmp'. Under X11 it is 'Hello.xpm'. 697 For MS-Windows and the bitmap is scaled to fit the button. For 698 MS-Windows a size of 18 by 18 pixels works best. 699 For MS-Windows the bitmap should have 16 colors with the standard palette. 700 The light grey pixels will be changed to the Window frame color and the 701 dark grey pixels to the window shadow color. More colors might also work, 702 depending on your system. 703- 4 If the bitmap is still not found, Vim checks for a match against its list 704 of built-in names. Each built-in button image has a name. 705 So the command > 706 :amenu ToolBar.Open :e 707< will show the built-in "open a file" button image if no open.bmp exists. 708 All the built-in names can be seen used in menu.vim. 709- 5 If all else fails, a blank, but functioning, button is displayed. 710 711 *builtin-tools* 712> 713 nr Name Normal action 714 00 New open new window 715 01 Open browse for file to open in current window 716 02 Save write buffer to file 717 03 Undo undo last change 718 04 Redo redo last undone change 719 05 Cut delete selected text to clipboard 720 06 Copy copy selected text to clipboard 721 07 Paste paste text from clipboard 722 08 Print print current buffer 723 09 Help open a buffer on Vim's builtin help 724 10 Find start a search command 725 11 SaveAll write all modified buffers to file 726 12 SaveSesn write session file for current situation 727 13 NewSesn write new session file 728 14 LoadSesn load session file 729 15 RunScript browse for file to run as a Vim script 730 16 Replace prompt for substitute command 731 17 WinClose close current window 732 18 WinMax make current window use many lines 733 19 WinMin make current window use few lines 734 20 WinSplit split current window 735 21 Shell start a shell 736 22 FindPrev search again, backward 737 23 FindNext search again, forward 738 24 FindHelp prompt for word to search help for 739 25 Make run make and jump to first error 740 26 TagJump jump to tag under the cursor 741 27 RunCtags build tags for files in current directory 742 28 WinVSplit split current window vertically 743 29 WinMaxWidth make current window use many columns 744 30 WinMinWidth make current window use few columns 745< 746 *hidden-menus* *win32-hidden-menus* 747In the Win32 GUI, starting a menu name with ']' excludes that menu from the 748main menu bar. You must then use the |:popup| command to display it. 749 750When splitting the window the window toolbar is not copied to the new window. 751 752 *popup-menu* 753You can define the special menu "PopUp". This is the menu that is displayed 754when the right mouse button is pressed, if 'mousemodel' is set to popup or 755popup_setpos. 756 757The default "PopUp" menu is: >vim 758 amenu PopUp.Open\ in\ web\ browser gx 759 anoremenu PopUp.Inspect <Cmd>Inspect<CR> 760 anoremenu PopUp.Go\ to\ definition <Cmd>lua vim.lsp.buf.definition()<CR> 761 anoremenu PopUp.Show\ Diagnostics <Cmd>lua vim.diagnostic.open_float()<CR> 762 anoremenu PopUp.Show\ All\ Diagnostics <Cmd>lua vim.diagnostic.setqflist()<CR> 763 anoremenu PopUp.Configure\ Diagnostics <Cmd>help vim.diagnostic.config()<CR> 764 anoremenu PopUp.-1- <Nop> 765 vnoremenu PopUp.Cut "+x 766 vnoremenu PopUp.Copy "+y 767 anoremenu PopUp.Paste "+gP 768 vnoremenu PopUp.Paste "+P 769 vnoremenu PopUp.Delete "_x 770 nnoremenu PopUp.Select\ All ggVG 771 vnoremenu PopUp.Select\ All gg0oG$ 772 inoremenu PopUp.Select\ All <C-Home><C-O>VG 773 anoremenu PopUp.-2- <Nop> 774 anoremenu PopUp.How-to\ disable\ mouse <Cmd>help disable-mouse<CR> 775< 776 777Showing What Menus Are Mapped To *showing-menus* 778 779To see what an existing menu is mapped to, use just one argument after the 780menu commands (just like you would with the ":map" commands). If the menu 781specified is a submenu, then all menus under that hierarchy will be shown. 782If no argument is given after :menu at all, then ALL menu items are shown 783for the appropriate mode (e.g., Command-line mode for :cmenu). 784 785Special characters in the list, just before the rhs: 786• * Menu was defined with "nore" to disallow remapping. 787• & Menu was defined with "<script>" to allow remapping script-local mappings. 788• s Menu was defined with "<silent>" to avoid showing what it is mapped to 789 when triggered. 790• - Menu was disabled. 791 792Note that hitting <Tab> while entering a menu name after a menu command may 793be used to complete the name of the menu item. 794 795 796Executing Menus *execute-menus* 797 798 *:em* *:emenu* *E334* *E335* 799:[range]em[enu] {menu} Execute {menu} from the command line. 800 The default is to execute the Normal mode 801 menu. If a range is specified, it executes 802 the Visual mode menu. 803 If used from <c-o>, it executes the 804 insert-mode menu Eg: > 805 :emenu File.Exit 806 807:[range]em[enu] {mode} {menu} Like above, but execute the menu for {mode}: 808 - 'n': |:nmenu| Normal mode 809 - 'v': |:vmenu| Visual mode 810 - 's': |:smenu| Select mode 811 - 'o': |:omenu| Operator-pending mode 812 - 't': |:tlmenu| Terminal mode 813 - 'i': |:imenu| Insert mode 814 - 'c': |:cmenu| Cmdline mode 815 816 817You can use :emenu to access useful menu items you may have got used to from 818GUI mode. See 'wildmenu' for an option that works well with this. See 819|console-menus| for an example. 820 821When using a range, if the lines match with '<,'>, then the menu is executed 822using the last visual selection. 823 824 825Deleting Menus *delete-menus* 826 827 *:unme* *:unmenu* 828 *:aun* *:aunmenu* 829To delete a menu item or a whole submenu, use the unmenu commands, which are 830analogous to the unmap commands. Eg: > 831 :unmenu! Edit.Paste 832 833This will remove the Paste item from the Edit menu for Insert and 834Command-line modes. 835 836Note that hitting <Tab> while entering a menu name after an umenu command 837may be used to complete the name of the menu item for the appropriate mode. 838 839To remove all menus use: *:unmenu-all* > 840 :unmenu * " remove all menus in Normal and visual mode 841 :unmenu! * " remove all menus in Insert and Command-line mode 842 :aunmenu * " remove all menus in all modes, except for Terminal 843 " mode 844 :tlunmenu * " remove all menus in Terminal mode 845 846If you want to get rid of the menu bar: > 847 :set guioptions-=m 848 849 850Disabling Menus *disable-menus* 851 852 *:menu-disable* *:menu-enable* 853If you do not want to remove a menu, but disable it for a moment, this can be 854done by adding the "enable" or "disable" keyword to a ":menu" command. 855Examples: > 856 :menu disable &File.&Open\.\.\. 857 :amenu enable * 858 :amenu disable &Tools.* 859 860The command applies to the modes as used with all menu commands. Note that 861characters like "&" need to be included for translated names to be found. 862When the argument is "*", all menus are affected. Otherwise the given menu 863name and all existing submenus below it are affected. 864 865 866Examples for Menus *menu-examples* 867 868Here is an example on how to add menu items with menus! You can add a menu 869item for the keyword under the cursor. The register "z" is used. > 870 871 :nmenu Words.Add\ Var wb"zye:menu! Words.<C-R>z <C-R>z<CR> 872 :nmenu Words.Remove\ Var wb"zye:unmenu! Words.<C-R>z<CR> 873 :vmenu Words.Add\ Var "zy:menu! Words.<C-R>z <C-R>z <CR> 874 :vmenu Words.Remove\ Var "zy:unmenu! Words.<C-R>z<CR> 875 :imenu Words.Add\ Var <Esc>wb"zye:menu! Words.<C-R>z <C-R>z<CR>a 876 :imenu Words.Remove\ Var <Esc>wb"zye:unmenu! Words.<C-R>z<CR>a 877 878(the rhs is in <> notation, you can copy/paste this text to try out the 879mappings, or put these lines in your gvimrc; "<C-R>" is CTRL-R, "<CR>" is 880the <CR> key. |<>|) 881 882 *tooltips* *menu-tips* 883Tooltips & Menu tips 884 885See section |42.4| in the user manual. 886 887 *:tmenu* 888:tm[enu] {menupath} {rhs} Define a tip for a menu or tool. (only in 889 X11 and Win32 GUI) 890 891:tm[enu] [menupath] List menu tips. (only in X11 and Win32 GUI) 892 893 *:tunmenu* 894:tu[nmenu] {menupath} Remove a tip for a menu or tool. 895 (only in X11 and Win32 GUI) 896 897Note: To create menus for terminal mode, use |:tlmenu| instead. 898 899When a tip is defined for a menu item, it appears in the command-line area 900when the mouse is over that item, much like a standard Windows menu hint in 901the status bar. (Except when Vim is in Command-line mode, when of course 902nothing is displayed.) 903When a tip is defined for a ToolBar item, it appears as a tooltip when the 904mouse pauses over that button, in the usual fashion. Use the |hl-Tooltip| 905highlight group to change its colors. 906 907A "tip" can be defined for each menu item. For example, when defining a menu 908item like this: > 909 :amenu MyMenu.Hello :echo "Hello"<CR> 910The tip is defined like this: > 911 :tmenu MyMenu.Hello Displays a greeting. 912And delete it with: > 913 :tunmenu MyMenu.Hello 914 915Tooltips are currently only supported for the X11 and Win32 GUI. However, 916they should appear for the other gui platforms in the not too distant future. 917 918The ":tmenu" command works just like other menu commands, it uses the same 919arguments. ":tunmenu" deletes an existing menu tip, in the same way as the 920other unmenu commands. 921 922If a menu item becomes invalid (i.e. its actions in all modes are deleted) Vim 923deletes the menu tip (and the item) for you. This means that :aunmenu deletes 924a menu item - you don't need to do a :tunmenu as well. 925 926 9275.9 Popup Menus 928 929You can cause a menu to popup at the cursor. This behaves similarly to the 930PopUp menus except that any menu tree can be popped up. 931 932 *:popup* *:popu* 933:popu[p] {name} Popup the menu {name}. The menu named must 934 have at least one subentry, but need not 935 appear on the menu-bar (see |hidden-menus|). 936 937:popu[p]! {name} Like above, but use the position of the mouse 938 pointer instead of the cursor. 939 940Example: > 941 :popup File 942will make the "File" menu (if there is one) appear at the text cursor (mouse 943pointer if ! was used). > 944 945 :amenu ]Toolbar.Make :make<CR> 946 :popup ]Toolbar 947This creates a popup menu that doesn't exist on the main menu-bar. 948 949Note that a menu that starts with ']' will not be displayed. 950 951 952 vim:tw=78:sw=4:ts=8:et:ft=help:norl: