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