blob: b3132a9002e7a7d3dcc1f34989cab5cc79ce83f0 [file] [log] [blame]
Bram Moolenaarf1f60f82016-01-16 15:40:53 +01001*repeat.txt* For Vim version 7.4. Last change: 2016 Jan 16
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 Moolenaara0ed84a2015-11-19 17:56:13 +0100112 a mapping and |:normal|.
113
114 Note: If the register being used for recording is also
115 used for |y| and |p| the result is most likely not
116 what is expected, because the put will paste the
117 recorded macro and the yank will overwrite the
118 recorded macro. {Vi: no recording}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119
120q Stops recording. (Implementation note: The 'q' that
121 stops recording is not stored in the register, unless
122 it was the result of a mapping) {Vi: no recording}
123
124 *@*
Bram Moolenaar61d35bd2012-03-28 20:51:51 +0200125@{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} [count]
Bram Moolenaar071d4272004-06-13 20:20:40 +0000126 times. Note that register '%' (name of the current
127 file) and '#' (name of the alternate file) cannot be
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +0100128 used.
129 The register is executed like a mapping, that means
130 that the difference between 'wildchar' and 'wildcharm'
131 applies.
132 For "@=" you are prompted to enter an expression. The
133 result of the expression is then executed.
134 See also |@:|. {Vi: only named registers}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135
Bram Moolenaar26a60b42005-02-22 08:49:11 +0000136 *@@* *E748*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137@@ Repeat the previous @{0-9a-z":*} [count] times.
138
Bram Moolenaar61d35bd2012-03-28 20:51:51 +0200139:[addr]*{0-9a-z".=+} *:@* *:star*
140:[addr]@{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} as an Ex
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141 command. First set cursor at line [addr] (default is
142 current line). When the last line in the register does
143 not have a <CR> it will be added automatically when
144 the 'e' flag is present in 'cpoptions'.
145 Note that the ":*" command is only recognized when the
146 '*' flag is present in 'cpoptions'. This is NOT the
147 default when 'nocompatible' is used.
148 For ":@=" the last used expression is used. The
149 result of evaluating the expression is executed as an
150 Ex command.
151 Mappings are not recognized in these commands.
152 {Vi: only in some versions} Future: Will execute the
153 register for each line in the address range.
154
155 *:@:*
156:[addr]@: Repeat last command-line. First set cursor at line
157 [addr] (default is current line). {not in Vi}
158
159 *:@@*
160:[addr]@@ Repeat the previous :@{0-9a-z"}. First set cursor at
161 line [addr] (default is current line). {Vi: only in
162 some versions}
163
164==============================================================================
1654. Using Vim scripts *using-scripts*
166
167For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
168
169 *:so* *:source* *load-vim-script*
170:so[urce] {file} Read Ex commands from {file}. These are commands that
171 start with a ":".
Bram Moolenaar1f35bf92006-03-07 22:38:47 +0000172 Triggers the |SourcePre| autocommand.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000173
174:so[urce]! {file} Read Vim commands from {file}. These are commands
175 that are executed from Normal mode, like you type
176 them.
177 When used after |:global|, |:argdo|, |:windo|,
178 |:bufdo|, in a loop or when another command follows
179 the display won't be updated while executing the
180 commands.
181 {not in Vi}
182
183 *:ru* *:runtime*
184:ru[ntime][!] {file} ..
185 Read Ex commands from {file} in each directory given
186 by 'runtimepath'. There is no error for non-existing
187 files. Example: >
188 :runtime syntax/c.vim
189
190< There can be multiple {file} arguments, separated by
191 spaces. Each {file} is searched for in the first
192 directory from 'runtimepath', then in the second
193 directory, etc. Use a backslash to include a space
194 inside {file} (although it's better not to use spaces
195 in file names, it causes trouble).
196
197 When [!] is included, all found files are sourced.
198 When it is not included only the first found file is
199 sourced.
200
201 When {file} contains wildcards it is expanded to all
202 matching files. Example: >
203 :runtime! plugin/*.vim
204< This is what Vim uses to load the plugin files when
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000205 starting up. This similar command: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000206 :runtime plugin/*.vim
207< would source the first file only.
208
209 When 'verbose' is one or higher, there is a message
210 when no file could be found.
211 When 'verbose' is two or higher, there is a message
212 about each searched file.
213 {not in Vi}
214
215:scripte[ncoding] [encoding] *:scripte* *:scriptencoding* *E167*
216 Specify the character encoding used in the script.
217 The following lines will be converted from [encoding]
218 to the value of the 'encoding' option, if they are
219 different. Examples: >
220 scriptencoding iso-8859-5
221 scriptencoding cp932
222<
223 When [encoding] is empty, no conversion is done. This
224 can be used to restrict conversion to a sequence of
225 lines: >
226 scriptencoding euc-jp
227 ... lines to be converted ...
228 scriptencoding
229 ... not converted ...
230
231< When conversion isn't supported by the system, there
232 is no error message and no conversion is done.
233
234 Don't use "ucs-2" or "ucs-4", scripts cannot be in
235 these encodings (they would contain NUL bytes).
236 When a sourced script starts with a BOM (Byte Order
Bram Moolenaar06b5d512010-05-22 15:37:44 +0200237 Mark) in utf-8 format Vim will recognize it, no need
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238 to use ":scriptencoding utf-8" then.
239
240 When compiled without the |+multi_byte| feature this
241 command is ignored.
242 {not in Vi}
243
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100244 *:scr* *:scriptnames*
245:scr[iptnames] List all sourced script names, in the order they were
Bram Moolenaar071d4272004-06-13 20:20:40 +0000246 first sourced. The number is used for the script ID
247 |<SID>|.
248 {not in Vi} {not available when compiled without the
249 |+eval| feature}
250
251 *:fini* *:finish* *E168*
252:fini[sh] Stop sourcing a script. Can only be used in a Vim
253 script file. This is a quick way to skip the rest of
254 the file. If it is used after a |:try| but before the
255 matching |:finally| (if present), the commands
256 following the ":finally" up to the matching |:endtry|
257 are executed first. This process applies to all
258 nested ":try"s in the script. The outermost ":endtry"
259 then stops sourcing the script. {not in Vi}
260
261All commands and command sequences can be repeated by putting them in a named
262register and then executing it. There are two ways to get the commands in the
263register:
264- Use the record command "q". You type the commands once, and while they are
265 being executed they are stored in a register. Easy, because you can see
266 what you are doing. If you make a mistake, "p"ut the register into the
267 file, edit the command sequence, and then delete it into the register
268 again. You can continue recording by appending to the register (use an
269 uppercase letter).
270- Delete or yank the command sequence into the register.
271
272Often used command sequences can be put under a function key with the ':map'
273command.
274
275An alternative is to put the commands in a file, and execute them with the
276':source!' command. Useful for long command sequences. Can be combined with
277the ':map' command to put complicated commands under a function key.
278
279The ':source' command reads Ex commands from a file line by line. You will
280have to type any needed keyboard input. The ':source!' command reads from a
281script file character by character, interpreting each character as if you
282typed it.
283
284Example: When you give the ":!ls" command you get the |hit-enter| prompt. If
285you ':source' a file with the line "!ls" in it, you will have to type the
286<Enter> yourself. But if you ':source!' a file with the line ":!ls" in it,
287the next characters from that file are read until a <CR> is found. You will
288not have to type <CR> yourself, unless ":!ls" was the last line in the file.
289
290It is possible to put ':source[!]' commands in the script file, so you can
291make a top-down hierarchy of script files. The ':source' command can be
292nested as deep as the number of files that can be opened at one time (about
29315). The ':source!' command can be nested up to 15 levels deep.
294
295You can use the "<sfile>" string (literally, this is not a special key) inside
296of the sourced file, in places where a file name is expected. It will be
297replaced by the file name of the sourced file. For example, if you have a
298"other.vimrc" file in the same directory as your ".vimrc" file, you can source
299it from your ".vimrc" file with this command: >
300 :source <sfile>:h/other.vimrc
301
302In script files terminal-dependent key codes are represented by
303terminal-independent two character codes. This means that they can be used
304in the same way on different kinds of terminals. The first character of a
305key code is 0x80 or 128, shown on the screen as "~@". The second one can be
306found in the list |key-notation|. Any of these codes can also be entered
307with CTRL-V followed by the three digit decimal code. This does NOT work for
308the <t_xx> termcap codes, these can only be used in mappings.
309
310 *:source_crnl* *W15*
311MS-DOS, Win32 and OS/2: Files that are read with ":source" normally have
312<CR><NL> <EOL>s. These always work. If you are using a file with <NL> <EOL>s
313(for example, a file made on Unix), this will be recognized if 'fileformats'
314is not empty and the first line does not end in a <CR>. This fails if the
315first line has something like ":map <F1> :help^M", where "^M" is a <CR>. If
316the first line ends in a <CR>, but following ones don't, you will get an error
317message, because the <CR> from the first lines will be lost.
318
Bram Moolenaar520470a2005-06-16 21:59:56 +0000319Mac Classic: Files that are read with ":source" normally have <CR> <EOL>s.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320These always work. If you are using a file with <NL> <EOL>s (for example, a
321file made on Unix), this will be recognized if 'fileformats' is not empty and
322the first line does not end in a <CR>. Be careful not to use a file with <NL>
323linebreaks which has a <CR> in first line.
324
325On other systems, Vim expects ":source"ed files to end in a <NL>. These
326always work. If you are using a file with <CR><NL> <EOL>s (for example, a
327file made on MS-DOS), all lines will have a trailing <CR>. This may cause
328problems for some commands (e.g., mappings). There is no automatic <EOL>
329detection, because it's common to start with a line that defines a mapping
330that ends in a <CR>, which will confuse the automaton.
331
332 *line-continuation*
333Long lines in a ":source"d Ex command script file can be split by inserting
334a line continuation symbol "\" (backslash) at the start of the next line.
335There can be white space before the backslash, which is ignored.
336
337Example: the lines >
338 :set comments=sr:/*,mb:*,el:*/,
339 \://,
340 \b:#,
341 \:%,
342 \n:>,
343 \fb:-
344are interpreted as if they were given in one line:
345 :set comments=sr:/*,mb:*,el:*/,://,b:#,:%,n:>,fb:-
346
347All leading whitespace characters in the line before a backslash are ignored.
348Note however that trailing whitespace in the line before it cannot be
349inserted freely; it depends on the position where a command is split up
350whether additional whitespace is allowed or not.
351
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100352When a space is required it's best to put it right after the backslash. A
353space at the end of a line is hard to see and may be accidentally deleted. >
354 :syn match Comment
355 \ "very long regexp"
356 \ keepend
357
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358There is a problem with the ":append" and ":insert" commands: >
359 :1append
360 \asdf
361 .
362The backslash is seen as a line-continuation symbol, thus this results in the
363command: >
364 :1appendasdf
365 .
366To avoid this, add the 'C' flag to the 'cpoptions' option: >
367 :set cpo+=C
368 :1append
369 \asdf
370 .
371 :set cpo-=C
372
373Note that when the commands are inside a function, you need to add the 'C'
374flag when defining the function, it is not relevant when executing it. >
375 :set cpo+=C
376 :function Foo()
377 :1append
378 \asdf
379 .
380 :endfunction
381 :set cpo-=C
382
383Rationale:
384 Most programs work with a trailing backslash to indicate line
385 continuation. Using this in Vim would cause incompatibility with Vi.
386 For example for this Vi mapping: >
387 :map xx asdf\
388< Therefore the unusual leading backslash is used.
389
390==============================================================================
3915. Debugging scripts *debug-scripts*
392
393Besides the obvious messages that you can add to your scripts to find out what
394they are doing, Vim offers a debug mode. This allows you to step through a
395sourced file or user function and set breakpoints.
396
397NOTE: The debugging mode is far from perfect. Debugging will have side
398effects on how Vim works. You cannot use it to debug everything. For
399example, the display is messed up by the debugging messages.
400{Vi does not have a debug mode}
401
402An alternative to debug mode is setting the 'verbose' option. With a bigger
403number it will give more verbose messages about what Vim is doing.
404
405
406STARTING DEBUG MODE *debug-mode*
407
408To enter debugging mode use one of these methods:
4091. Start Vim with the |-D| argument: >
410 vim -D file.txt
411< Debugging will start as soon as the first vimrc file is sourced. This is
412 useful to find out what is happening when Vim is starting up. A side
413 effect is that Vim will switch the terminal mode before initialisations
414 have finished, with unpredictable results.
415 For a GUI-only version (Windows, Macintosh) the debugging will start as
416 soon as the GUI window has been opened. To make this happen early, add a
417 ":gui" command in the vimrc file.
418 *:debug*
4192. Run a command with ":debug" prepended. Debugging will only be done while
420 this command executes. Useful for debugging a specific script or user
421 function. And for scripts and functions used by autocommands. Example: >
422 :debug edit test.txt.gz
423
4243. Set a breakpoint in a sourced file or user function. You could do this in
425 the command line: >
426 vim -c "breakadd file */explorer.vim" .
427< This will run Vim and stop in the first line of the "explorer.vim" script.
428 Breakpoints can also be set while in debugging mode.
429
430In debugging mode every executed command is displayed before it is executed.
431Comment lines, empty lines and lines that are not executed are skipped. When
432a line contains two commands, separated by "|", each command will be displayed
433separately.
434
435
436DEBUG MODE
437
438Once in debugging mode, the usual Ex commands can be used. For example, to
439inspect the value of a variable: >
440 echo idx
441When inside a user function, this will print the value of the local variable
442"idx". Prepend "g:" to get the value of a global variable: >
443 echo g:idx
444All commands are executed in the context of the current function or script.
445You can also set options, for example setting or resetting 'verbose' will show
446what happens, but you might want to set it just before executing the lines you
447are interested in: >
448 :set verbose=20
449
450Commands that require updating the screen should be avoided, because their
451effect won't be noticed until after leaving debug mode. For example: >
452 :help
453won't be very helpful.
454
455There is a separate command-line history for debug mode.
456
457The line number for a function line is relative to the start of the function.
458If you have trouble figuring out where you are, edit the file that defines
459the function in another Vim, search for the start of the function and do
460"99j". Replace "99" with the line number.
461
462Additionally, these commands can be used:
463 *>cont*
464 cont Continue execution until the next breakpoint is hit.
465 *>quit*
466 quit Abort execution. This is like using CTRL-C, some
467 things might still be executed, doesn't abort
468 everything. Still stops at the next breakpoint.
469 *>next*
470 next Execute the command and come back to debug mode when
471 it's finished. This steps over user function calls
472 and sourced files.
473 *>step*
474 step Execute the command and come back to debug mode for
475 the next command. This steps into called user
476 functions and sourced files.
477 *>interrupt*
478 interrupt This is like using CTRL-C, but unlike ">quit" comes
479 back to debug mode for the next command that is
480 executed. Useful for testing |:finally| and |:catch|
481 on interrupt exceptions.
482 *>finish*
483 finish Finish the current script or user function and come
484 back to debug mode for the command after the one that
485 sourced or called it.
Bram Moolenaarf1f60f82016-01-16 15:40:53 +0100486 *>bt*
487 *>backtrace*
488 *>where*
489 backtrace Show the call stacktrace for current debugging session.
490 bt
491 where
492 *>frame*
493 frame N Goes to N bactrace level. + and - signs make movement
494 relative. E.g., ":frame +3" goes three frames up.
495 *>up*
496 up Goes one level up from call stacktrace.
497 *>down*
498 down Goes one level down from call stacktrace.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499
500About the additional commands in debug mode:
501- There is no command-line completion for them, you get the completion for the
502 normal Ex commands only.
Bram Moolenaarf1f60f82016-01-16 15:40:53 +0100503- You can shorten them, up to a single character, unless more then one command
504 starts with the same letter. "f" stands for "finish", use "fr" for "frame".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505- Hitting <CR> will repeat the previous one. When doing another command, this
506 is reset (because it's not clear what you want to repeat).
507- When you want to use the Ex command with the same name, prepend a colon:
508 ":cont", ":next", ":finish" (or shorter).
509
Bram Moolenaarf1f60f82016-01-16 15:40:53 +0100510The backtrace shows the hierarchy of function calls, e.g.:
511 >bt ~
512 3 function One[3] ~
513 2 Two[3] ~
514 ->1 Three[3] ~
515 0 Four ~
516 line 1: let four = 4 ~
517
518The "->" points to the current frame. Use "up", "down" and "frame N" to
519select another frame.
520
521In the current frame you can evaluate the local function variables. There is
522no way to see the command at the current line yet.
523
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524
525DEFINING BREAKPOINTS
526 *:breaka* *:breakadd*
527:breaka[dd] func [lnum] {name}
528 Set a breakpoint in a function. Example: >
529 :breakadd func Explore
530< Doesn't check for a valid function name, thus the breakpoint
531 can be set before the function is defined.
532
533:breaka[dd] file [lnum] {name}
534 Set a breakpoint in a sourced file. Example: >
535 :breakadd file 43 .vimrc
536
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000537:breaka[dd] here
538 Set a breakpoint in the current line of the current file.
539 Like doing: >
540 :breakadd file <cursor-line> <current-file>
541< Note that this only works for commands that are executed when
542 sourcing the file, not for a function defined in that file.
543
Bram Moolenaar071d4272004-06-13 20:20:40 +0000544The [lnum] is the line number of the breakpoint. Vim will stop at or after
545this line. When omitted line 1 is used.
546
Bram Moolenaar05159a02005-02-26 23:04:13 +0000547 *:debug-name*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000548{name} is a pattern that is matched with the file or function name. The
549pattern is like what is used for autocommands. There must be a full match (as
550if the pattern starts with "^" and ends in "$"). A "*" matches any sequence
551of characters. 'ignorecase' is not used, but "\c" can be used in the pattern
552to ignore case |/\c|. Don't include the () for the function name!
553
Bram Moolenaar843ee412004-06-30 16:16:41 +0000554The match for sourced scripts is done against the full file name. If no path
555is specified the current directory is used. Examples: >
556 breakadd file explorer.vim
557matches "explorer.vim" in the current directory. >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 breakadd file *explorer.vim
Bram Moolenaar843ee412004-06-30 16:16:41 +0000559matches ".../plugin/explorer.vim", ".../plugin/iexplorer.vim", etc. >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 breakadd file */explorer.vim
Bram Moolenaar843ee412004-06-30 16:16:41 +0000561matches ".../plugin/explorer.vim" and "explorer.vim" in any other directory.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562
563The match for functions is done against the name as it's shown in the output
564of ":function". For local functions this means that something like "<SNR>99_"
565is prepended.
566
Bram Moolenaar2ce06f62005-01-31 19:19:04 +0000567Note that functions are first loaded and later executed. When they are loaded
568the "file" breakpoints are checked, when they are executed the "func"
569breakpoints.
570
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571
572DELETING BREAKPOINTS
573 *:breakd* *:breakdel* *E161*
574:breakd[el] {nr}
575 Delete breakpoint {nr}. Use |:breaklist| to see the number of
576 each breakpoint.
577
Bram Moolenaarf461c8e2005-06-25 23:04:51 +0000578:breakd[el] *
579 Delete all breakpoints.
580
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581:breakd[el] func [lnum] {name}
582 Delete a breakpoint in a function.
583
584:breakd[el] file [lnum] {name}
585 Delete a breakpoint in a sourced file.
586
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000587:breakd[el] here
588 Delete a breakpoint at the current line of the current file.
589
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590When [lnum] is omitted, the first breakpoint in the function or file is
591deleted.
592The {name} must be exactly the same as what was typed for the ":breakadd"
593command. "explorer", "*explorer.vim" and "*explorer*" are different.
594
595
596LISTING BREAKPOINTS
597 *:breakl* *:breaklist*
598:breakl[ist]
599 List all breakpoints.
600
601
602OBSCURE
603
604 *:debugg* *:debuggreedy*
605:debugg[reedy]
606 Read debug mode commands from the normal input stream, instead
607 of getting them directly from the user. Only useful for test
608 scripts. Example: >
609 echo 'q^Mq' | vim -e -s -c debuggreedy -c 'breakadd file script.vim' -S script.vim
610
611:0debugg[reedy]
612 Undo ":debuggreedy": get debug mode commands directly from the
613 user, don't use typeahead for debug commands.
614
Bram Moolenaar05159a02005-02-26 23:04:13 +0000615==============================================================================
6166. Profiling *profile* *profiling*
617
Bram Moolenaar996343d2010-07-04 22:20:21 +0200618Profiling means that Vim measures the time that is spent on executing
Bram Moolenaar05159a02005-02-26 23:04:13 +0000619functions and/or scripts. The |+profile| feature is required for this.
620It is only included when Vim was compiled with "huge" features.
621{Vi does not have profiling}
622
Bram Moolenaar433f7c82006-03-21 21:29:36 +0000623You can also use the |reltime()| function to measure time. This only requires
624the |+reltime| feature, which is present more often.
625
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200626For profiling syntax highlighting see |:syntime|.
627
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +0100628For example, to profile the one_script.vim script file: >
629 :profile start /tmp/one_script_profile
630 :profile file one_script.vim
631 :source one_script.vim
632 :exit
633
Bram Moolenaar16ea3672013-07-28 16:02:18 +0200634
Bram Moolenaar05159a02005-02-26 23:04:13 +0000635:prof[ile] start {fname} *:prof* *:profile* *E750*
636 Start profiling, write the output in {fname} upon exit.
Bram Moolenaar0a63ded2015-04-15 13:31:24 +0200637 "~/" and environment variables in {fname} will be expanded.
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000638 If {fname} already exists it will be silently overwritten.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000639 The variable |v:profiling| is set to one.
640
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000641:prof[ile] pause
642 Don't profile until the following ":profile continue". Can be
643 used when doing something that should not be counted (e.g., an
644 external command). Does not nest.
645
646:prof[ile] continue
647 Continue profiling after ":profile pause".
648
Bram Moolenaar05159a02005-02-26 23:04:13 +0000649:prof[ile] func {pattern}
650 Profile function that matches the pattern {pattern}.
651 See |:debug-name| for how {pattern} is used.
652
653:prof[ile][!] file {pattern}
654 Profile script file that matches the pattern {pattern}.
655 See |:debug-name| for how {pattern} is used.
656 This only profiles the script itself, not the functions
657 defined in it.
658 When the [!] is added then all functions defined in the script
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +0100659 will also be profiled.
660 Note that profiling only starts when the script is loaded
661 after this command. A :profile command in the script itself
662 won't work.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000663
664
Bram Moolenaard9fba312005-06-26 22:34:35 +0000665:profd[el] ... *:profd* *:profdel*
666 Stop profiling for the arguments specified. See |:breakdel|
667 for the arguments.
668
669
Bram Moolenaar05159a02005-02-26 23:04:13 +0000670You must always start with a ":profile start fname" command. The resulting
671file is written when Vim exits. Here is an example of the output, with line
672numbers prepended for the explanation:
673
674 1 FUNCTION Test2() ~
675 2 Called 1 time ~
676 3 Total time: 0.155251 ~
677 4 Self time: 0.002006 ~
678 5 ~
679 6 count total (s) self (s) ~
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000680 7 9 0.000096 for i in range(8) ~
681 8 8 0.153655 0.000410 call Test3() ~
682 9 8 0.000070 endfor ~
683 10 " Ask a question ~
684 11 1 0.001341 echo input("give me an answer: ") ~
Bram Moolenaar05159a02005-02-26 23:04:13 +0000685
686The header (lines 1-4) gives the time for the whole function. The "Total"
687time is the time passed while the function was executing. The "Self" time is
688the "Total" time reduced by time spent in:
689- other user defined functions
690- sourced scripts
691- executed autocommands
692- external (shell) commands
693
694Lines 7-11 show the time spent in each executed line. Lines that are not
695executed do not count. Thus a comment line is never counted.
696
697The Count column shows how many times a line was executed. Note that the
698"for" command in line 7 is executed one more time as the following lines.
699That is because the line is also executed to detect the end of the loop.
700
701The time Vim spends waiting for user input isn't counted at all. Thus how
702long you take to respond to the input() prompt is irrelevant.
703
704Profiling should give a good indication of where time is spent, but keep in
705mind there are various things that may clobber the results:
706
707- The accuracy of the time measured depends on the gettimeofday() system
708 function. It may only be as accurate as 1/100 second, even though the times
709 are displayed in micro seconds.
710
711- Real elapsed time is measured, if other processes are busy they may cause
712 delays at unpredictable moments. You may want to run the profiling several
713 times and use the lowest results.
714
715- If you have several commands in one line you only get one time. Split the
716 line to see the time for the individual commands.
717
718- The time of the lines added up is mostly less than the time of the whole
719 function. There is some overhead in between.
720
721- Functions that are deleted before Vim exits will not produce profiling
722 information. You can check the |v:profiling| variable if needed: >
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000723 :if !v:profiling
Bram Moolenaar05159a02005-02-26 23:04:13 +0000724 : delfunc MyFunc
725 :endif
726<
Bram Moolenaar8cd06ca2005-02-28 22:44:58 +0000727- Profiling may give weird results on multi-processor systems, when sleep
728 mode kicks in or the processor frequency is reduced to save power.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000729
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000730- The "self" time is wrong when a function is used recursively.
731
732
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733 vim:tw=78:ts=8:ft=help:norl: