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