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