Mercurial > vim
annotate runtime/doc/repeat.txt @ 8246:f16bfe02cef1
commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 25 00:00:01 2016 +0100
Updated runtime files.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 25 Feb 2016 00:15:06 +0100 |
parents | 95d59081580f |
children | 88207f4b861a |
rev | line source |
---|---|
8246
f16bfe02cef1
commit https://github.com/vim/vim/commit/f391327adbbffb11180cf6038a92af1ed144e907
Christian Brabandt <cb@256bit.org>
parents:
8182
diff
changeset
|
1 *repeat.txt* For Vim version 7.4. Last change: 2016 Feb 24 |
7 | 2 |
3 | |
4 VIM REFERENCE MANUAL by Bram Moolenaar | |
5 | |
6 | |
7 Repeating commands, Vim scripts and debugging *repeating* | |
8 | |
9 Chapter 26 of the user manual introduces repeating |usr_26.txt|. | |
10 | |
11 1. Single repeats |single-repeat| | |
12 2. Multiple repeats |multi-repeat| | |
13 3. Complex repeats |complex-repeat| | |
14 4. Using Vim scripts |using-scripts| | |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
15 5. Using Vim packages |packages| |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
16 6. Debugging scripts |debug-scripts| |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
17 7. Profiling |profiling| |
7 | 18 |
19 ============================================================================== | |
20 1. Single repeats *single-repeat* | |
21 | |
22 *.* | |
23 . Repeat last change, with count replaced with [count]. | |
24 Also repeat a yank command, when the 'y' flag is | |
22 | 25 included in 'cpoptions'. Does not repeat a |
26 command-line command. | |
7 | 27 |
28 Simple changes can be repeated with the "." command. Without a count, the | |
29 count of the last change is used. If you enter a count, it will replace the | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
30 last one. |v:count| and |v:count1| will be set. |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
31 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
32 If the last change included a specification of a numbered register, the |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
33 register number will be incremented. See |redo-register| for an example how |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
34 to use this. |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
35 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
36 Note that when repeating a command that used a Visual selection, the same SIZE |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
37 of area is used, see |visual-repeat|. |
7 | 38 |
39 *@:* | |
40 @: Repeat last command-line [count] times. | |
41 {not available when compiled without the | |
42 |+cmdline_hist| feature} | |
43 | |
44 | |
45 ============================================================================== | |
46 2. Multiple repeats *multi-repeat* | |
47 | |
48 *:g* *:global* *E147* *E148* | |
49 :[range]g[lobal]/{pattern}/[cmd] | |
50 Execute the Ex command [cmd] (default ":p") on the | |
51 lines within [range] where {pattern} matches. | |
52 | |
53 :[range]g[lobal]!/{pattern}/[cmd] | |
54 Execute the Ex command [cmd] (default ":p") on the | |
55 lines within [range] where {pattern} does NOT match. | |
56 | |
57 *:v* *:vglobal* | |
58 :[range]v[global]/{pattern}/[cmd] | |
59 Same as :g!. | |
60 | |
1125 | 61 Instead of the '/' which surrounds the {pattern}, you can use any other |
5239 | 62 single byte character, but not an alphabetic character, '\', '"' or '|'. |
1125 | 63 This is useful if you want to include a '/' in the search pattern or |
64 replacement string. | |
65 | |
66 For the definition of a pattern, see |pattern|. | |
67 | |
6336 | 68 NOTE [cmd] may contain a range; see |collapse| and |edit-paragraph-join| for |
69 examples. | |
70 | |
7 | 71 The global commands work by first scanning through the [range] lines and |
72 marking each line where a match occurs (for a multi-line pattern, only the | |
73 start of the match matters). | |
74 In a second scan the [cmd] is executed for each marked line with its line | |
75 number prepended. For ":v" and ":g!" the command is executed for each not | |
76 marked line. If a line is deleted its mark disappears. | |
77 The default for [range] is the whole buffer (1,$). Use "CTRL-C" to interrupt | |
78 the command. If an error message is given for a line, the command for that | |
79 line is aborted and the global command continues with the next marked or | |
80 unmarked line. | |
81 | |
82 To repeat a non-Ex command, you can use the ":normal" command: > | |
83 :g/pat/normal {commands} | |
84 Make sure that {commands} ends with a whole command, otherwise Vim will wait | |
85 for you to type the rest of the command for each match. The screen will not | |
86 have been updated, so you don't know what you are doing. See |:normal|. | |
87 | |
88 The undo/redo command will undo/redo the whole global command at once. | |
89 The previous context mark will only be set once (with "''" you go back to | |
90 where the cursor was before the global command). | |
91 | |
92 The global command sets both the last used search pattern and the last used | |
93 substitute pattern (this is vi compatible). This makes it easy to globally | |
94 replace a string: | |
95 :g/pat/s//PAT/g | |
96 This replaces all occurrences of "pat" with "PAT". The same can be done with: | |
97 :%s/pat/PAT/g | |
98 Which is two characters shorter! | |
99 | |
1623 | 100 When using "global" in Ex mode, a special case is using ":visual" as a |
101 command. This will move to a matching line, go to Normal mode to let you | |
102 execute commands there until you use |Q| to return to Ex mode. This will be | |
103 repeated for each matching line. While doing this you cannot use ":global". | |
104 To abort this type CTRL-C twice. | |
168 | 105 |
7 | 106 ============================================================================== |
107 3. Complex repeats *complex-repeat* | |
108 | |
109 *q* *recording* | |
110 q{0-9a-zA-Z"} Record typed characters into register {0-9a-zA-Z"} | |
111 (uppercase to append). The 'q' command is disabled | |
112 while executing a register, and it doesn't work inside | |
7233
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
113 a mapping and |:normal|. |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
114 |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
115 Note: If the register being used for recording is also |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
116 used for |y| and |p| the result is most likely not |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
117 what is expected, because the put will paste the |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
118 recorded macro and the yank will overwrite the |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
119 recorded macro. {Vi: no recording} |
7 | 120 |
121 q Stops recording. (Implementation note: The 'q' that | |
122 stops recording is not stored in the register, unless | |
123 it was the result of a mapping) {Vi: no recording} | |
124 | |
125 *@* | |
3445 | 126 @{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} [count] |
7 | 127 times. Note that register '%' (name of the current |
128 file) and '#' (name of the alternate file) cannot be | |
2681 | 129 used. |
130 The register is executed like a mapping, that means | |
131 that the difference between 'wildchar' and 'wildcharm' | |
132 applies. | |
133 For "@=" you are prompted to enter an expression. The | |
134 result of the expression is then executed. | |
135 See also |@:|. {Vi: only named registers} | |
7 | 136 |
168 | 137 *@@* *E748* |
7 | 138 @@ Repeat the previous @{0-9a-z":*} [count] times. |
139 | |
3445 | 140 :[addr]*{0-9a-z".=+} *:@* *:star* |
141 :[addr]@{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} as an Ex | |
7 | 142 command. First set cursor at line [addr] (default is |
143 current line). When the last line in the register does | |
144 not have a <CR> it will be added automatically when | |
145 the 'e' flag is present in 'cpoptions'. | |
146 Note that the ":*" command is only recognized when the | |
147 '*' flag is present in 'cpoptions'. This is NOT the | |
148 default when 'nocompatible' is used. | |
149 For ":@=" the last used expression is used. The | |
150 result of evaluating the expression is executed as an | |
151 Ex command. | |
152 Mappings are not recognized in these commands. | |
153 {Vi: only in some versions} Future: Will execute the | |
154 register for each line in the address range. | |
155 | |
156 *:@:* | |
157 :[addr]@: Repeat last command-line. First set cursor at line | |
158 [addr] (default is current line). {not in Vi} | |
159 | |
160 *:@@* | |
161 :[addr]@@ Repeat the previous :@{0-9a-z"}. First set cursor at | |
162 line [addr] (default is current line). {Vi: only in | |
163 some versions} | |
164 | |
165 ============================================================================== | |
166 4. Using Vim scripts *using-scripts* | |
167 | |
168 For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|. | |
169 | |
170 *:so* *:source* *load-vim-script* | |
171 :so[urce] {file} Read Ex commands from {file}. These are commands that | |
172 start with a ":". | |
716 | 173 Triggers the |SourcePre| autocommand. |
7 | 174 |
175 :so[urce]! {file} Read Vim commands from {file}. These are commands | |
176 that are executed from Normal mode, like you type | |
177 them. | |
178 When used after |:global|, |:argdo|, |:windo|, | |
179 |:bufdo|, in a loop or when another command follows | |
180 the display won't be updated while executing the | |
181 commands. | |
182 {not in Vi} | |
183 | |
184 *:ru* *:runtime* | |
185 :ru[ntime][!] {file} .. | |
186 Read Ex commands from {file} in each directory given | |
187 by 'runtimepath'. There is no error for non-existing | |
188 files. Example: > | |
189 :runtime syntax/c.vim | |
190 | |
191 < There can be multiple {file} arguments, separated by | |
192 spaces. Each {file} is searched for in the first | |
193 directory from 'runtimepath', then in the second | |
194 directory, etc. Use a backslash to include a space | |
195 inside {file} (although it's better not to use spaces | |
196 in file names, it causes trouble). | |
197 | |
198 When [!] is included, all found files are sourced. | |
199 When it is not included only the first found file is | |
200 sourced. | |
201 | |
202 When {file} contains wildcards it is expanded to all | |
203 matching files. Example: > | |
204 :runtime! plugin/*.vim | |
205 < This is what Vim uses to load the plugin files when | |
237 | 206 starting up. This similar command: > |
7 | 207 :runtime plugin/*.vim |
208 < would source the first file only. | |
209 | |
210 When 'verbose' is one or higher, there is a message | |
211 when no file could be found. | |
212 When 'verbose' is two or higher, there is a message | |
213 about each searched file. | |
214 {not in Vi} | |
215 | |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
216 *:loadp* *:loadplugin* |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
217 :loadp[lugin] {name} Search for an optional plugin directory and source the |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
218 plugin files found. It is similar to: > |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
219 :runtime pack/*/opt/{name}/plugin/*.vim |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
220 < However, `:loadplugin` uses 'packpath' instead of |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
221 'runtimepath'. And the directory found is added to |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
222 'runtimepath'. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
223 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
224 Note that {name} is the directory name, not the name |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
225 of the .vim file. If the "{name}/plugin" directory |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
226 contains more than one file they are all sourced. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
227 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
228 Also see |load-plugin|. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
229 |
7 | 230 :scripte[ncoding] [encoding] *:scripte* *:scriptencoding* *E167* |
231 Specify the character encoding used in the script. | |
232 The following lines will be converted from [encoding] | |
233 to the value of the 'encoding' option, if they are | |
234 different. Examples: > | |
235 scriptencoding iso-8859-5 | |
236 scriptencoding cp932 | |
237 < | |
238 When [encoding] is empty, no conversion is done. This | |
239 can be used to restrict conversion to a sequence of | |
240 lines: > | |
241 scriptencoding euc-jp | |
242 ... lines to be converted ... | |
243 scriptencoding | |
244 ... not converted ... | |
245 | |
246 < When conversion isn't supported by the system, there | |
247 is no error message and no conversion is done. | |
248 | |
249 Don't use "ucs-2" or "ucs-4", scripts cannot be in | |
250 these encodings (they would contain NUL bytes). | |
251 When a sourced script starts with a BOM (Byte Order | |
2207
b17bbfa96fa0
Add the settabvar() and gettabvar() functions.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
252 Mark) in utf-8 format Vim will recognize it, no need |
7 | 253 to use ":scriptencoding utf-8" then. |
254 | |
255 When compiled without the |+multi_byte| feature this | |
256 command is ignored. | |
257 {not in Vi} | |
258 | |
6476 | 259 *:scr* *:scriptnames* |
260 :scr[iptnames] List all sourced script names, in the order they were | |
7 | 261 first sourced. The number is used for the script ID |
262 |<SID>|. | |
263 {not in Vi} {not available when compiled without the | |
264 |+eval| feature} | |
265 | |
266 *:fini* *:finish* *E168* | |
267 :fini[sh] Stop sourcing a script. Can only be used in a Vim | |
268 script file. This is a quick way to skip the rest of | |
269 the file. If it is used after a |:try| but before the | |
270 matching |:finally| (if present), the commands | |
271 following the ":finally" up to the matching |:endtry| | |
272 are executed first. This process applies to all | |
273 nested ":try"s in the script. The outermost ":endtry" | |
274 then stops sourcing the script. {not in Vi} | |
275 | |
276 All commands and command sequences can be repeated by putting them in a named | |
277 register and then executing it. There are two ways to get the commands in the | |
278 register: | |
279 - Use the record command "q". You type the commands once, and while they are | |
280 being executed they are stored in a register. Easy, because you can see | |
281 what you are doing. If you make a mistake, "p"ut the register into the | |
282 file, edit the command sequence, and then delete it into the register | |
283 again. You can continue recording by appending to the register (use an | |
284 uppercase letter). | |
285 - Delete or yank the command sequence into the register. | |
286 | |
287 Often used command sequences can be put under a function key with the ':map' | |
288 command. | |
289 | |
290 An alternative is to put the commands in a file, and execute them with the | |
291 ':source!' command. Useful for long command sequences. Can be combined with | |
292 the ':map' command to put complicated commands under a function key. | |
293 | |
294 The ':source' command reads Ex commands from a file line by line. You will | |
295 have to type any needed keyboard input. The ':source!' command reads from a | |
296 script file character by character, interpreting each character as if you | |
297 typed it. | |
298 | |
299 Example: When you give the ":!ls" command you get the |hit-enter| prompt. If | |
300 you ':source' a file with the line "!ls" in it, you will have to type the | |
301 <Enter> yourself. But if you ':source!' a file with the line ":!ls" in it, | |
302 the next characters from that file are read until a <CR> is found. You will | |
303 not have to type <CR> yourself, unless ":!ls" was the last line in the file. | |
304 | |
305 It is possible to put ':source[!]' commands in the script file, so you can | |
306 make a top-down hierarchy of script files. The ':source' command can be | |
307 nested as deep as the number of files that can be opened at one time (about | |
308 15). The ':source!' command can be nested up to 15 levels deep. | |
309 | |
310 You can use the "<sfile>" string (literally, this is not a special key) inside | |
311 of the sourced file, in places where a file name is expected. It will be | |
312 replaced by the file name of the sourced file. For example, if you have a | |
313 "other.vimrc" file in the same directory as your ".vimrc" file, you can source | |
314 it from your ".vimrc" file with this command: > | |
315 :source <sfile>:h/other.vimrc | |
316 | |
317 In script files terminal-dependent key codes are represented by | |
318 terminal-independent two character codes. This means that they can be used | |
319 in the same way on different kinds of terminals. The first character of a | |
320 key code is 0x80 or 128, shown on the screen as "~@". The second one can be | |
321 found in the list |key-notation|. Any of these codes can also be entered | |
322 with CTRL-V followed by the three digit decimal code. This does NOT work for | |
323 the <t_xx> termcap codes, these can only be used in mappings. | |
324 | |
325 *:source_crnl* *W15* | |
326 MS-DOS, Win32 and OS/2: Files that are read with ":source" normally have | |
327 <CR><NL> <EOL>s. These always work. If you are using a file with <NL> <EOL>s | |
328 (for example, a file made on Unix), this will be recognized if 'fileformats' | |
329 is not empty and the first line does not end in a <CR>. This fails if the | |
330 first line has something like ":map <F1> :help^M", where "^M" is a <CR>. If | |
331 the first line ends in a <CR>, but following ones don't, you will get an error | |
332 message, because the <CR> from the first lines will be lost. | |
333 | |
333 | 334 Mac Classic: Files that are read with ":source" normally have <CR> <EOL>s. |
7 | 335 These always work. If you are using a file with <NL> <EOL>s (for example, a |
336 file made on Unix), this will be recognized if 'fileformats' is not empty and | |
337 the first line does not end in a <CR>. Be careful not to use a file with <NL> | |
338 linebreaks which has a <CR> in first line. | |
339 | |
340 On other systems, Vim expects ":source"ed files to end in a <NL>. These | |
341 always work. If you are using a file with <CR><NL> <EOL>s (for example, a | |
342 file made on MS-DOS), all lines will have a trailing <CR>. This may cause | |
343 problems for some commands (e.g., mappings). There is no automatic <EOL> | |
344 detection, because it's common to start with a line that defines a mapping | |
345 that ends in a <CR>, which will confuse the automaton. | |
346 | |
347 *line-continuation* | |
348 Long lines in a ":source"d Ex command script file can be split by inserting | |
349 a line continuation symbol "\" (backslash) at the start of the next line. | |
350 There can be white space before the backslash, which is ignored. | |
351 | |
352 Example: the lines > | |
353 :set comments=sr:/*,mb:*,el:*/, | |
354 \://, | |
355 \b:#, | |
356 \:%, | |
357 \n:>, | |
358 \fb:- | |
359 are interpreted as if they were given in one line: | |
360 :set comments=sr:/*,mb:*,el:*/,://,b:#,:%,n:>,fb:- | |
361 | |
362 All leading whitespace characters in the line before a backslash are ignored. | |
363 Note however that trailing whitespace in the line before it cannot be | |
364 inserted freely; it depends on the position where a command is split up | |
365 whether additional whitespace is allowed or not. | |
366 | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
367 When a space is required it's best to put it right after the backslash. A |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
368 space at the end of a line is hard to see and may be accidentally deleted. > |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
369 :syn match Comment |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
370 \ "very long regexp" |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
371 \ keepend |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
372 |
7 | 373 There is a problem with the ":append" and ":insert" commands: > |
374 :1append | |
375 \asdf | |
376 . | |
377 The backslash is seen as a line-continuation symbol, thus this results in the | |
378 command: > | |
379 :1appendasdf | |
380 . | |
381 To avoid this, add the 'C' flag to the 'cpoptions' option: > | |
382 :set cpo+=C | |
383 :1append | |
384 \asdf | |
385 . | |
386 :set cpo-=C | |
387 | |
388 Note that when the commands are inside a function, you need to add the 'C' | |
389 flag when defining the function, it is not relevant when executing it. > | |
390 :set cpo+=C | |
391 :function Foo() | |
392 :1append | |
393 \asdf | |
394 . | |
395 :endfunction | |
396 :set cpo-=C | |
397 | |
398 Rationale: | |
399 Most programs work with a trailing backslash to indicate line | |
400 continuation. Using this in Vim would cause incompatibility with Vi. | |
401 For example for this Vi mapping: > | |
402 :map xx asdf\ | |
403 < Therefore the unusual leading backslash is used. | |
404 | |
405 ============================================================================== | |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
406 5. Using Vim packages *packages* |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
407 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
408 A Vim package is a directory that contains one or more plugins. The |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
409 advantages over normal plugins: |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
410 - A package can be downloaded as an archive and unpacked in its own directory. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
411 That makes it easy to updated and/or remove. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
412 - A package can be a git, mercurial, etc. respository. That makes it really |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
413 easy to update. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
414 - A package can contain multiple plugins that depend on each other. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
415 - A package can contain plugins that are automatically loaded on startup and |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
416 ones that are only loaded when needed with `:loadplugin`. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
417 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
418 Let's assume your Vim files are in the "~/.vim" directory and you want to add a |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
419 package from a zip archive "/tmp/mypack.zip": |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
420 % mkdir -p ~/.vim/pack/my |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
421 % cd ~/.vim/pack/my |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
422 % unzip /tmp/mypack.zip |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
423 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
424 The directory name "my" is arbitrary, you can pick anything you like. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
425 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
426 You would now have these files under ~/.vim: |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
427 pack/my/README.txt |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
428 pack/my/ever/always/plugin/always.vim |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
429 pack/my/ever/always/syntax/always.vim |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
430 pack/my/opt/mydebug/plugin/debugger.vim |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
431 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
432 When Vim starts up it scans all directories in 'packpath' for plugins under the |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
433 "ever" directory and loads them. When found that directory is added to |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
434 'runtimepath'. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
435 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
436 In the example Vim will find "my/ever/always/plugin/always.vim" and adds |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
437 "~/.vim/pack/my/ever/always" to 'runtimepath'. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
438 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
439 If the "always" plugin kicks in and sets the 'filetype' to "always", Vim will |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
440 find the syntax/always.vim file, because its directory is in 'runtimepath'. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
441 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
442 *load-plugin* |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
443 To load an optional plugin from a pack use the `:loadplugin` command: > |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
444 :loadplugin mydebug |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
445 This could be done inside always.vim, if some conditions are met. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
446 Or you could add this command to your |.vimrc|. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
447 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
448 It is perfectly normal for a package to only have files in the "opt" |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
449 directory. You then need to load each plugin when you want to use it. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
450 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
451 Loading packages will not happen if loading plugins is disabled, see |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
452 |load-plugins|. |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
453 |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
454 ============================================================================== |
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
455 6. Debugging scripts *debug-scripts* |
7 | 456 |
457 Besides the obvious messages that you can add to your scripts to find out what | |
458 they are doing, Vim offers a debug mode. This allows you to step through a | |
459 sourced file or user function and set breakpoints. | |
460 | |
461 NOTE: The debugging mode is far from perfect. Debugging will have side | |
462 effects on how Vim works. You cannot use it to debug everything. For | |
463 example, the display is messed up by the debugging messages. | |
464 {Vi does not have a debug mode} | |
465 | |
466 An alternative to debug mode is setting the 'verbose' option. With a bigger | |
467 number it will give more verbose messages about what Vim is doing. | |
468 | |
469 | |
470 STARTING DEBUG MODE *debug-mode* | |
471 | |
472 To enter debugging mode use one of these methods: | |
473 1. Start Vim with the |-D| argument: > | |
474 vim -D file.txt | |
475 < Debugging will start as soon as the first vimrc file is sourced. This is | |
476 useful to find out what is happening when Vim is starting up. A side | |
477 effect is that Vim will switch the terminal mode before initialisations | |
478 have finished, with unpredictable results. | |
479 For a GUI-only version (Windows, Macintosh) the debugging will start as | |
480 soon as the GUI window has been opened. To make this happen early, add a | |
481 ":gui" command in the vimrc file. | |
482 *:debug* | |
483 2. Run a command with ":debug" prepended. Debugging will only be done while | |
484 this command executes. Useful for debugging a specific script or user | |
485 function. And for scripts and functions used by autocommands. Example: > | |
486 :debug edit test.txt.gz | |
487 | |
488 3. Set a breakpoint in a sourced file or user function. You could do this in | |
489 the command line: > | |
490 vim -c "breakadd file */explorer.vim" . | |
491 < This will run Vim and stop in the first line of the "explorer.vim" script. | |
492 Breakpoints can also be set while in debugging mode. | |
493 | |
494 In debugging mode every executed command is displayed before it is executed. | |
495 Comment lines, empty lines and lines that are not executed are skipped. When | |
496 a line contains two commands, separated by "|", each command will be displayed | |
497 separately. | |
498 | |
499 | |
500 DEBUG MODE | |
501 | |
502 Once in debugging mode, the usual Ex commands can be used. For example, to | |
503 inspect the value of a variable: > | |
504 echo idx | |
505 When inside a user function, this will print the value of the local variable | |
506 "idx". Prepend "g:" to get the value of a global variable: > | |
507 echo g:idx | |
508 All commands are executed in the context of the current function or script. | |
509 You can also set options, for example setting or resetting 'verbose' will show | |
510 what happens, but you might want to set it just before executing the lines you | |
511 are interested in: > | |
512 :set verbose=20 | |
513 | |
514 Commands that require updating the screen should be avoided, because their | |
515 effect won't be noticed until after leaving debug mode. For example: > | |
516 :help | |
517 won't be very helpful. | |
518 | |
519 There is a separate command-line history for debug mode. | |
520 | |
521 The line number for a function line is relative to the start of the function. | |
522 If you have trouble figuring out where you are, edit the file that defines | |
523 the function in another Vim, search for the start of the function and do | |
524 "99j". Replace "99" with the line number. | |
525 | |
526 Additionally, these commands can be used: | |
527 *>cont* | |
528 cont Continue execution until the next breakpoint is hit. | |
529 *>quit* | |
530 quit Abort execution. This is like using CTRL-C, some | |
531 things might still be executed, doesn't abort | |
532 everything. Still stops at the next breakpoint. | |
533 *>next* | |
534 next Execute the command and come back to debug mode when | |
535 it's finished. This steps over user function calls | |
536 and sourced files. | |
537 *>step* | |
538 step Execute the command and come back to debug mode for | |
539 the next command. This steps into called user | |
540 functions and sourced files. | |
541 *>interrupt* | |
542 interrupt This is like using CTRL-C, but unlike ">quit" comes | |
543 back to debug mode for the next command that is | |
544 executed. Useful for testing |:finally| and |:catch| | |
545 on interrupt exceptions. | |
546 *>finish* | |
547 finish Finish the current script or user function and come | |
548 back to debug mode for the command after the one that | |
549 sourced or called it. | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
550 *>bt* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
551 *>backtrace* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
552 *>where* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
553 backtrace Show the call stacktrace for current debugging session. |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
554 bt |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
555 where |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
556 *>frame* |
8061
abd64cf67bcf
commit https://github.com/vim/vim/commit/38a55639d603823efcf2d2fdf542dbffdeb60b75
Christian Brabandt <cb@256bit.org>
parents:
7605
diff
changeset
|
557 frame N Goes to N backtrace level. + and - signs make movement |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
558 relative. E.g., ":frame +3" goes three frames up. |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
559 *>up* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
560 up Goes one level up from call stacktrace. |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
561 *>down* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
562 down Goes one level down from call stacktrace. |
7 | 563 |
564 About the additional commands in debug mode: | |
565 - There is no command-line completion for them, you get the completion for the | |
566 normal Ex commands only. | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
567 - You can shorten them, up to a single character, unless more then one command |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
568 starts with the same letter. "f" stands for "finish", use "fr" for "frame". |
7 | 569 - Hitting <CR> will repeat the previous one. When doing another command, this |
570 is reset (because it's not clear what you want to repeat). | |
571 - When you want to use the Ex command with the same name, prepend a colon: | |
572 ":cont", ":next", ":finish" (or shorter). | |
573 | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
574 The backtrace shows the hierarchy of function calls, e.g.: |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
575 >bt ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
576 3 function One[3] ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
577 2 Two[3] ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
578 ->1 Three[3] ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
579 0 Four ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
580 line 1: let four = 4 ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
581 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
582 The "->" points to the current frame. Use "up", "down" and "frame N" to |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
583 select another frame. |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
584 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
585 In the current frame you can evaluate the local function variables. There is |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
586 no way to see the command at the current line yet. |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
587 |
7 | 588 |
589 DEFINING BREAKPOINTS | |
590 *:breaka* *:breakadd* | |
591 :breaka[dd] func [lnum] {name} | |
592 Set a breakpoint in a function. Example: > | |
593 :breakadd func Explore | |
594 < Doesn't check for a valid function name, thus the breakpoint | |
595 can be set before the function is defined. | |
596 | |
597 :breaka[dd] file [lnum] {name} | |
598 Set a breakpoint in a sourced file. Example: > | |
599 :breakadd file 43 .vimrc | |
600 | |
10 | 601 :breaka[dd] here |
602 Set a breakpoint in the current line of the current file. | |
603 Like doing: > | |
604 :breakadd file <cursor-line> <current-file> | |
605 < Note that this only works for commands that are executed when | |
606 sourcing the file, not for a function defined in that file. | |
607 | |
7 | 608 The [lnum] is the line number of the breakpoint. Vim will stop at or after |
609 this line. When omitted line 1 is used. | |
610 | |
170 | 611 *:debug-name* |
7 | 612 {name} is a pattern that is matched with the file or function name. The |
613 pattern is like what is used for autocommands. There must be a full match (as | |
614 if the pattern starts with "^" and ends in "$"). A "*" matches any sequence | |
615 of characters. 'ignorecase' is not used, but "\c" can be used in the pattern | |
616 to ignore case |/\c|. Don't include the () for the function name! | |
617 | |
11 | 618 The match for sourced scripts is done against the full file name. If no path |
619 is specified the current directory is used. Examples: > | |
620 breakadd file explorer.vim | |
621 matches "explorer.vim" in the current directory. > | |
7 | 622 breakadd file *explorer.vim |
11 | 623 matches ".../plugin/explorer.vim", ".../plugin/iexplorer.vim", etc. > |
7 | 624 breakadd file */explorer.vim |
11 | 625 matches ".../plugin/explorer.vim" and "explorer.vim" in any other directory. |
7 | 626 |
627 The match for functions is done against the name as it's shown in the output | |
628 of ":function". For local functions this means that something like "<SNR>99_" | |
629 is prepended. | |
630 | |
148 | 631 Note that functions are first loaded and later executed. When they are loaded |
632 the "file" breakpoints are checked, when they are executed the "func" | |
633 breakpoints. | |
634 | |
7 | 635 |
636 DELETING BREAKPOINTS | |
637 *:breakd* *:breakdel* *E161* | |
638 :breakd[el] {nr} | |
639 Delete breakpoint {nr}. Use |:breaklist| to see the number of | |
640 each breakpoint. | |
641 | |
359 | 642 :breakd[el] * |
643 Delete all breakpoints. | |
644 | |
7 | 645 :breakd[el] func [lnum] {name} |
646 Delete a breakpoint in a function. | |
647 | |
648 :breakd[el] file [lnum] {name} | |
649 Delete a breakpoint in a sourced file. | |
650 | |
10 | 651 :breakd[el] here |
652 Delete a breakpoint at the current line of the current file. | |
653 | |
7 | 654 When [lnum] is omitted, the first breakpoint in the function or file is |
655 deleted. | |
656 The {name} must be exactly the same as what was typed for the ":breakadd" | |
657 command. "explorer", "*explorer.vim" and "*explorer*" are different. | |
658 | |
659 | |
660 LISTING BREAKPOINTS | |
661 *:breakl* *:breaklist* | |
662 :breakl[ist] | |
663 List all breakpoints. | |
664 | |
665 | |
666 OBSCURE | |
667 | |
668 *:debugg* *:debuggreedy* | |
669 :debugg[reedy] | |
670 Read debug mode commands from the normal input stream, instead | |
671 of getting them directly from the user. Only useful for test | |
672 scripts. Example: > | |
673 echo 'q^Mq' | vim -e -s -c debuggreedy -c 'breakadd file script.vim' -S script.vim | |
674 | |
675 :0debugg[reedy] | |
676 Undo ":debuggreedy": get debug mode commands directly from the | |
677 user, don't use typeahead for debug commands. | |
678 | |
170 | 679 ============================================================================== |
8182
95d59081580f
commit https://github.com/vim/vim/commit/f6fee0e2d4341c0c2f5339c1268e5877fafd07cf
Christian Brabandt <cb@256bit.org>
parents:
8061
diff
changeset
|
680 7. Profiling *profile* *profiling* |
170 | 681 |
2283
7e1bd501306d
Mainly documentation updates.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
682 Profiling means that Vim measures the time that is spent on executing |
170 | 683 functions and/or scripts. The |+profile| feature is required for this. |
684 It is only included when Vim was compiled with "huge" features. | |
685 {Vi does not have profiling} | |
686 | |
794 | 687 You can also use the |reltime()| function to measure time. This only requires |
688 the |+reltime| feature, which is present more often. | |
689 | |
5244 | 690 For profiling syntax highlighting see |:syntime|. |
691 | |
5763 | 692 For example, to profile the one_script.vim script file: > |
693 :profile start /tmp/one_script_profile | |
694 :profile file one_script.vim | |
695 :source one_script.vim | |
696 :exit | |
697 | |
5244 | 698 |
170 | 699 :prof[ile] start {fname} *:prof* *:profile* *E750* |
700 Start profiling, write the output in {fname} upon exit. | |
6757 | 701 "~/" and environment variables in {fname} will be expanded. |
790 | 702 If {fname} already exists it will be silently overwritten. |
170 | 703 The variable |v:profiling| is set to one. |
704 | |
790 | 705 :prof[ile] pause |
706 Don't profile until the following ":profile continue". Can be | |
707 used when doing something that should not be counted (e.g., an | |
708 external command). Does not nest. | |
709 | |
710 :prof[ile] continue | |
711 Continue profiling after ":profile pause". | |
712 | |
170 | 713 :prof[ile] func {pattern} |
714 Profile function that matches the pattern {pattern}. | |
715 See |:debug-name| for how {pattern} is used. | |
716 | |
717 :prof[ile][!] file {pattern} | |
718 Profile script file that matches the pattern {pattern}. | |
719 See |:debug-name| for how {pattern} is used. | |
720 This only profiles the script itself, not the functions | |
721 defined in it. | |
722 When the [!] is added then all functions defined in the script | |
5763 | 723 will also be profiled. |
724 Note that profiling only starts when the script is loaded | |
725 after this command. A :profile command in the script itself | |
726 won't work. | |
170 | 727 |
728 | |
364 | 729 :profd[el] ... *:profd* *:profdel* |
730 Stop profiling for the arguments specified. See |:breakdel| | |
731 for the arguments. | |
732 | |
733 | |
170 | 734 You must always start with a ":profile start fname" command. The resulting |
735 file is written when Vim exits. Here is an example of the output, with line | |
736 numbers prepended for the explanation: | |
737 | |
738 1 FUNCTION Test2() ~ | |
739 2 Called 1 time ~ | |
740 3 Total time: 0.155251 ~ | |
741 4 Self time: 0.002006 ~ | |
742 5 ~ | |
743 6 count total (s) self (s) ~ | |
856 | 744 7 9 0.000096 for i in range(8) ~ |
745 8 8 0.153655 0.000410 call Test3() ~ | |
746 9 8 0.000070 endfor ~ | |
747 10 " Ask a question ~ | |
748 11 1 0.001341 echo input("give me an answer: ") ~ | |
170 | 749 |
750 The header (lines 1-4) gives the time for the whole function. The "Total" | |
751 time is the time passed while the function was executing. The "Self" time is | |
752 the "Total" time reduced by time spent in: | |
753 - other user defined functions | |
754 - sourced scripts | |
755 - executed autocommands | |
756 - external (shell) commands | |
757 | |
758 Lines 7-11 show the time spent in each executed line. Lines that are not | |
759 executed do not count. Thus a comment line is never counted. | |
760 | |
761 The Count column shows how many times a line was executed. Note that the | |
762 "for" command in line 7 is executed one more time as the following lines. | |
763 That is because the line is also executed to detect the end of the loop. | |
764 | |
765 The time Vim spends waiting for user input isn't counted at all. Thus how | |
766 long you take to respond to the input() prompt is irrelevant. | |
767 | |
768 Profiling should give a good indication of where time is spent, but keep in | |
769 mind there are various things that may clobber the results: | |
770 | |
771 - The accuracy of the time measured depends on the gettimeofday() system | |
772 function. It may only be as accurate as 1/100 second, even though the times | |
773 are displayed in micro seconds. | |
774 | |
775 - Real elapsed time is measured, if other processes are busy they may cause | |
776 delays at unpredictable moments. You may want to run the profiling several | |
777 times and use the lowest results. | |
778 | |
779 - If you have several commands in one line you only get one time. Split the | |
780 line to see the time for the individual commands. | |
781 | |
782 - The time of the lines added up is mostly less than the time of the whole | |
783 function. There is some overhead in between. | |
784 | |
785 - Functions that are deleted before Vim exits will not produce profiling | |
786 information. You can check the |v:profiling| variable if needed: > | |
856 | 787 :if !v:profiling |
170 | 788 : delfunc MyFunc |
789 :endif | |
790 < | |
177 | 791 - Profiling may give weird results on multi-processor systems, when sleep |
792 mode kicks in or the processor frequency is reduced to save power. | |
170 | 793 |
1125 | 794 - The "self" time is wrong when a function is used recursively. |
795 | |
796 | |
7 | 797 vim:tw=78:ts=8:ft=help:norl: |