annotate runtime/doc/usr_42.txt @ 33521:1f9b1def80c8 v9.0.2009

patch 9.0.2009: cmdline-completion for comma-separated options wrong Commit: https://github.com/vim/vim/commit/54844857fd6933fa4f6678e47610c4b9c9f7a091 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Mon Oct 9 18:12:31 2023 +0200 patch 9.0.2009: cmdline-completion for comma-separated options wrong Problem: cmdline-completion for comma-separated options wrong Solution: Fix command-line expansions for options with filenames with commas Fix command-line expansions for options with filenames with commas Cmdline expansion for option values that take a comma-separated list of file names is currently not handling file names with commas as the commas are not escaped. For such options, the commas in file names need to be escaped (to differentiate from a comma that delimit the list items). The escaped comma is unescaped in `copy_option_part()` during option parsing. Fix as follows: - Cmdline completion for option values with comma-separated file/folder names will not start a new match when seeing `\\,` and will instead consider it as one value. - File/folder regex matching will strip the `\\` when seeing `\\,` to make sure it can match the correct files/folders. - The expanded value will escape `,` with `\\,`, similar to how spaces are escaped to make sure the option value is correct on the cmdline. This fix also takes into account the fact that Win32 Vim handles file name escaping differently. Typing '\,' for a file name results in it being handled literally but in other platforms '\,' is interpreted as a simple ',' and commas need to be escaped using '\\,' instead. Also, make sure this new logic only applies to comma-separated options like 'path'. Non-list options like 'set makeprg=<Tab>' and regular ex commands like `:edit <Tab>` do not require escaping and will continue to work. Also fix up documentation to be clearer. The original docs are slightly misleading in how it discusses triple slashes for 'tags'. closes: #13303 related: #13301 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Mon, 09 Oct 2023 18:30:04 +0200
parents f8116058ca76
children 4635e43f2c6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29314
f8116058ca76 release version 9.0
Bram Moolenaar <Bram@vim.org>
parents: 21676
diff changeset
1 *usr_42.txt* For Vim version 9.0. Last change: 2008 May 05
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 VIM USER MANUAL - by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 Add new menus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 By now you know that Vim is very flexible. This includes the menus used in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 the GUI. You can define your own menu entries to make certain commands easily
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 accessible. This is for mouse-happy users only.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 |42.1| Introduction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 |42.2| Menu commands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |42.3| Various
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 |42.4| Toolbar and popup menus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 Next chapter: |usr_43.txt| Using filetypes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 Previous chapter: |usr_41.txt| Write a Vim script
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 Table of contents: |usr_toc.txt|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 *42.1* Introduction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 The menus that Vim uses are defined in the file "$VIMRUNTIME/menu.vim". If
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 you want to write your own menus, you might first want to look through that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 To define a menu item, use the ":menu" command. The basic form of this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 command is as follows: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 :menu {menu-item} {keys}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 The {menu-item} describes where on the menu to put the item. A typical
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 {menu-item} is "File.Save", which represents the item "Save" under the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 "File" menu. A dot is used to separate the names. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 :menu File.Save :update<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 The ":update" command writes the file when it was modified.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 You can add another level: "Edit.Settings.Shiftwidth" defines a submenu
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 "Settings" under the "Edit" menu, with an item "Shiftwidth". You could use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 even deeper levels. Don't use this too much, you need to move the mouse quite
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 a bit to use such an item.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 The ":menu" command is very similar to the ":map" command: the left side
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 specifies how the item is triggered and the right hand side defines the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 characters that are executed. {keys} are characters, they are used just like
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 you would have typed them. Thus in Insert mode, when {keys} is plain text,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 that text is inserted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 ACCELERATORS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 The ampersand character (&) is used to indicate an accelerator. For instance,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 you can use Alt-F to select "File" and S to select "Save". (The 'winaltkeys'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 option may disable this though!). Therefore, the {menu-item} looks like
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 "&File.&Save". The accelerator characters will be underlined in the menu.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 You must take care that each key is used only once in each menu. Otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 you will not know which of the two will actually be used. Vim doesn't warn
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 you for this.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 PRIORITIES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 The actual definition of the File.Save menu item is as follows: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 :menu 10.340 &File.&Save<Tab>:w :confirm w<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 The number 10.340 is called the priority number. It is used by the editor to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 decide where it places the menu item. The first number (10) indicates the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 position on the menu bar. Lower numbered menus are positioned to the left,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 higher numbers to the right.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 These are the priorities used for the standard menus:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 10 20 40 50 60 70 9999
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 +------------------------------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 | File Edit Tools Syntax Buffers Window Help |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 +------------------------------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 Notice that the Help menu is given a very high number, to make it appear on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 the far right.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 The second number (340) determines the location of the item within the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 pull-down menu. Lower numbers go on top, higher number on the bottom. These
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 are the priorities in the File menu:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 +-----------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 10.310 |Open... |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 10.320 |Split-Open... |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 10.325 |New |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 10.330 |Close |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 10.335 |---------------- |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 10.340 |Save |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 10.350 |Save As... |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 10.400 |---------------- |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 10.410 |Split Diff with |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 10.420 |Split Patched By |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 10.500 |---------------- |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 10.510 |Print |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 10.600 |---------------- |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 10.610 |Save-Exit |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 10.620 |Exit |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 +-----------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 Notice that there is room in between the numbers. This is where you can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 insert your own items, if you really want to (it's often better to leave the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 standard menus alone and add a new menu for your own items).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 When you create a submenu, you can add another ".number" to the priority.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 Thus each name in {menu-item} has its priority number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 SPECIAL CHARACTERS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 7
diff changeset
112 The {menu-item} in this example is "&File.&Save<Tab>:w". This brings up an
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 important point: {menu-item} must be one word. If you want to put a dot,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 space or tabs in the name, you either use the <> notation (<Space> and <Tab>,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 for instance) or use the backslash (\) escape. >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 :menu 10.305 &File.&Do\ It\.\.\. :exit<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 In this example, the name of the menu item "Do It..." contains a space and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 command is ":exit<CR>".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 The <Tab> character in a menu name is used to separate the part that defines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 the menu name from the part that gives a hint to the user. The part after the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 <Tab> is displayed right aligned in the menu. In the File.Save menu the name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 used is "&File.&Save<Tab>:w". Thus the menu name is "File.Save" and the hint
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 is ":w".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 SEPARATORS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 The separator lines, used to group related menu items together, can be defined
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 by using a name that starts and ends in a '-'. For example "-sep-". When
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 using several separators the names must be different. Otherwise the names
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 don't matter.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 The command from a separator will never be executed, but you have to define
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 one anyway. A single colon will do. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 :amenu 20.510 Edit.-sep3- :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 *42.2* Menu commands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 You can define menu items that exist for only certain modes. This works just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 like the variations on the ":map" command:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 :menu Normal, Visual and Operator-pending mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 :nmenu Normal mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 :vmenu Visual mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 :omenu Operator-pending mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 :menu! Insert and Command-line mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 :imenu Insert mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 :cmenu Command-line mode
14952
405309f9dd13 patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
153 :tlmenu Terminal mode
405309f9dd13 patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
154 :amenu All modes (except for Terminal mode)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 To avoid that the commands of a menu item are being mapped, use the command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 ":noremenu", ":nnoremenu", ":anoremenu", etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 USING :AMENU
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 The ":amenu" command is a bit different. It assumes that the {keys} you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 give are to be executed in Normal mode. When Vim is in Visual or Insert mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 when the menu is used, Vim first has to go back to Normal mode. ":amenu"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 inserts a CTRL-C or CTRL-O for you. For example, if you use this command:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 :amenu 90.100 Mine.Find\ Word *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 Then the resulting menu commands will be:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 Normal mode: *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 Visual mode: CTRL-C *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 Operator-pending mode: CTRL-C *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 Insert mode: CTRL-O *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 Command-line mode: CTRL-C *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 When in Command-line mode the CTRL-C will abandon the command typed so far.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 In Visual and Operator-pending mode CTRL-C will stop the mode. The CTRL-O in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 Insert mode will execute the command and then return to Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 CTRL-O only works for one command. If you need to use two or more
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 commands, put them in a function and call that function. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 :amenu Mine.Next\ File :call <SID>NextFile()<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 :function <SID>NextFile()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 : next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 : 1/^Code
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 :endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 This menu entry goes to the next file in the argument list with ":next". Then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 it searches for the line that starts with "Code".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 The <SID> before the function name is the script ID. This makes the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 function local to the current Vim script file. This avoids problems when a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 function with the same name is defined in another script file. See |<SID>|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 SILENT MENUS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 The menu executes the {keys} as if you typed them. For a ":" command this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 means you will see the command being echoed on the command line. If it's a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 long command, the hit-Enter prompt will appear. That can be very annoying!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 To avoid this, make the menu silent. This is done with the <silent>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 argument. For example, take the call to NextFile() in the previous example.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 When you use this menu, you will see this on the command line:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 :call <SNR>34_NextFile() ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 To avoid this text on the command line, insert "<silent>" as the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 argument: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 :amenu <silent> Mine.Next\ File :call <SID>NextFile()<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 Don't use "<silent>" too often. It is not needed for short commands. If you
21676
1b345fb68ae3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 18879
diff changeset
213 make a menu for someone else, being able to see the executed command will give
1b345fb68ae3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 18879
diff changeset
214 him a hint about what he could have typed, instead of using the mouse.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 LISTING MENUS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 When a menu command is used without a {keys} part, it lists the already
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 defined menus. You can specify a {menu-item}, or part of it, to list specific
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 menus. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 :amenu
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 This lists all menus. That's a long list! Better specify the name of a menu
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 to get a shorter list: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 :amenu Edit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 This lists only the "Edit" menu items for all modes. To list only one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 specific menu item for Insert mode: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 :imenu Edit.Undo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 Take care that you type exactly the right name. Case matters here. But the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 '&' for accelerators can be omitted. The <Tab> and what comes after it can be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 left out as well.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 DELETING MENUS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 To delete a menu, the same command is used as for listing, but with "menu"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 changed to "unmenu". Thus ":menu" becomes, ":unmenu", ":nmenu" becomes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 ":nunmenu", etc. To delete the "Tools.Make" item for Insert mode: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 :iunmenu Tools.Make
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 You can delete a whole menu, with all its items, by using the menu name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 :aunmenu Syntax
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 This deletes the Syntax menu and all the items in it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 *42.3* Various
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 You can change the appearance of the menus with flags in 'guioptions'. In the
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1244
diff changeset
259 default value they are all included, except "M". You can remove a flag with a
73fe8baea242 updated for version 7.2a
vimboss
parents: 1244
diff changeset
260 command like: >
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 :set guioptions-=m
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 <
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 m When removed the menubar is not displayed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1244
diff changeset
266 M When added the default menus are not loaded.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 g When removed the inactive menu items are not made grey
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 but are completely removed. (Does not work on all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 systems.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 t When removed the tearoff feature is not enabled.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 The dotted line at the top of a menu is not a separator line. When you select
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 this item, the menu is "teared-off": It is displayed in a separate window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 This is called a tearoff menu. This is useful when you use the same menu
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 often.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 For translating menu items, see |:menutrans|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 Since the mouse has to be used to select a menu item, it is a good idea to use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 the ":browse" command for selecting a file. And ":confirm" to get a dialog
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 instead of an error message, e.g., when the current buffer contains changes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 These two can be combined: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 :amenu File.Open :browse confirm edit<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 The ":browse" makes a file browser appear to select the file to edit. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 ":confirm" will pop up a dialog when the current buffer has changes. You can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 then select to save the changes, throw them away or cancel the command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 For more complicated items, the confirm() and inputdialog() functions can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 be used. The default menus contain a few examples.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 *42.4* Toolbar and popup menus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 There are two special menus: ToolBar and PopUp. Items that start with these
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 names do not appear in the normal menu bar.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 TOOLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 The toolbar appears only when the "T" flag is included in the 'guioptions'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 option.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 The toolbar uses icons rather than text to represent the command. For
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 example, the {menu-item} named "ToolBar.New" causes the "New" icon to appear
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 on the toolbar.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 The Vim editor has 28 built-in icons. You can find a table here:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 |builtin-tools|. Most of them are used in the default toolbar. You can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 redefine what these items do (after the default menus are setup).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 You can add another bitmap for a toolbar item. Or define a new toolbar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 item with a bitmap. For example, define a new toolbar item with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 :tmenu ToolBar.Compile Compile the current file
5690
40f18a1c1592 updated for version 7.4.191
Bram Moolenaar <bram@vim.org>
parents: 5294
diff changeset
315 :amenu ToolBar.Compile :!cc %:S -o %:r:S<CR>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 Now you need to create the icon. For MS-Windows it must be in bitmap format,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 with the name "Compile.bmp". For Unix XPM format is used, the file name is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 "Compile.xpm". The size must be 18 by 18 pixels. On MS-Windows other sizes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 can be used as well, but it will look ugly.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 Put the bitmap in the directory "bitmaps" in one of the directories from
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 'runtimepath'. E.g., for Unix "~/.vim/bitmaps/Compile.xpm".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 You can define tooltips for the items in the toolbar. A tooltip is a short
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 text that explains what a toolbar item will do. For example "Open file". It
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 appears when the mouse pointer is on the item, without moving for a moment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 This is very useful if the meaning of the picture isn't that obvious.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 :tmenu ToolBar.Make Run make in the current directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 <
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 Pay attention to the case used. "Toolbar" and "toolbar" are different
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 from "ToolBar"!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 To remove a tooltip, use the |:tunmenu| command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 The 'toolbar' option can be used to display text instead of a bitmap, or both
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 text and a bitmap. Most people use just the bitmap, since the text takes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 quite a bit of space.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 POPUP MENU
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 The popup menu pops up where the mouse pointer is. On MS-Windows you activate
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 it by clicking the right mouse button. Then you can select an item with the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 left mouse button. On Unix the popup menu is used by pressing and holding the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 right mouse button.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 The popup menu only appears when the 'mousemodel' has been set to "popup"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 or "popup_setpos". The difference between the two is that "popup_setpos"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 moves the cursor to the mouse pointer position. When clicking inside a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 selection, the selection will be used unmodified. When there is a selection
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 but you click outside of it, the selection is removed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 There is a separate popup menu for each mode. Thus there are never grey
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 items like in the normal menus.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 What is the meaning of life, the universe and everything? *42*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 Douglas Adams, the only person who knew what this question really was about is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 now dead, unfortunately. So now you might wonder what the meaning of death
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 is...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 Next chapter: |usr_43.txt| Using filetypes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365
14519
5c5908e81e93 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 13963
diff changeset
366 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: