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