Mercurial > vim
annotate runtime/doc/repeat.txt @ 7605:8fc60af6dbf5 v7.4.1102
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 16 15:40:53 2016 +0100
patch 7.4.1102
Problem: Debugger has no stack backtrace support.
Solution: Add "backtrace", "frame", "up" and "down" commands. (Alberto
Fanjul, closes https://github.com/vim/vim/issues/433)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 16 Jan 2016 15:45:04 +0100 |
parents | 9487ea110214 |
children | abd64cf67bcf |
rev | line source |
---|---|
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
1 *repeat.txt* For Vim version 7.4. Last change: 2016 Jan 16 |
7 | 2 |
3 | |
4 VIM REFERENCE MANUAL by Bram Moolenaar | |
5 | |
6 | |
7 Repeating commands, Vim scripts and debugging *repeating* | |
8 | |
9 Chapter 26 of the user manual introduces repeating |usr_26.txt|. | |
10 | |
11 1. Single repeats |single-repeat| | |
12 2. Multiple repeats |multi-repeat| | |
13 3. Complex repeats |complex-repeat| | |
14 4. Using Vim scripts |using-scripts| | |
15 5. Debugging scripts |debug-scripts| | |
170 | 16 6. Profiling |profiling| |
7 | 17 |
18 ============================================================================== | |
19 1. Single repeats *single-repeat* | |
20 | |
21 *.* | |
22 . Repeat last change, with count replaced with [count]. | |
23 Also repeat a yank command, when the 'y' flag is | |
22 | 24 included in 'cpoptions'. Does not repeat a |
25 command-line command. | |
7 | 26 |
27 Simple changes can be repeated with the "." command. Without a count, the | |
28 count of the last change is used. If you enter a count, it will replace the | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
29 last one. |v:count| and |v:count1| will be set. |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
30 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
31 If the last change included a specification of a numbered register, the |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
32 register number will be incremented. See |redo-register| for an example how |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
33 to use this. |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
34 |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
35 Note that when repeating a command that used a Visual selection, the same SIZE |
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5294
diff
changeset
|
36 of area is used, see |visual-repeat|. |
7 | 37 |
38 *@:* | |
39 @: Repeat last command-line [count] times. | |
40 {not available when compiled without the | |
41 |+cmdline_hist| feature} | |
42 | |
43 | |
44 ============================================================================== | |
45 2. Multiple repeats *multi-repeat* | |
46 | |
47 *:g* *:global* *E147* *E148* | |
48 :[range]g[lobal]/{pattern}/[cmd] | |
49 Execute the Ex command [cmd] (default ":p") on the | |
50 lines within [range] where {pattern} matches. | |
51 | |
52 :[range]g[lobal]!/{pattern}/[cmd] | |
53 Execute the Ex command [cmd] (default ":p") on the | |
54 lines within [range] where {pattern} does NOT match. | |
55 | |
56 *:v* *:vglobal* | |
57 :[range]v[global]/{pattern}/[cmd] | |
58 Same as :g!. | |
59 | |
1125 | 60 Instead of the '/' which surrounds the {pattern}, you can use any other |
5239 | 61 single byte character, but not an alphabetic character, '\', '"' or '|'. |
1125 | 62 This is useful if you want to include a '/' in the search pattern or |
63 replacement string. | |
64 | |
65 For the definition of a pattern, see |pattern|. | |
66 | |
6336 | 67 NOTE [cmd] may contain a range; see |collapse| and |edit-paragraph-join| for |
68 examples. | |
69 | |
7 | 70 The global commands work by first scanning through the [range] lines and |
71 marking each line where a match occurs (for a multi-line pattern, only the | |
72 start of the match matters). | |
73 In a second scan the [cmd] is executed for each marked line with its line | |
74 number prepended. For ":v" and ":g!" the command is executed for each not | |
75 marked line. If a line is deleted its mark disappears. | |
76 The default for [range] is the whole buffer (1,$). Use "CTRL-C" to interrupt | |
77 the command. If an error message is given for a line, the command for that | |
78 line is aborted and the global command continues with the next marked or | |
79 unmarked line. | |
80 | |
81 To repeat a non-Ex command, you can use the ":normal" command: > | |
82 :g/pat/normal {commands} | |
83 Make sure that {commands} ends with a whole command, otherwise Vim will wait | |
84 for you to type the rest of the command for each match. The screen will not | |
85 have been updated, so you don't know what you are doing. See |:normal|. | |
86 | |
87 The undo/redo command will undo/redo the whole global command at once. | |
88 The previous context mark will only be set once (with "''" you go back to | |
89 where the cursor was before the global command). | |
90 | |
91 The global command sets both the last used search pattern and the last used | |
92 substitute pattern (this is vi compatible). This makes it easy to globally | |
93 replace a string: | |
94 :g/pat/s//PAT/g | |
95 This replaces all occurrences of "pat" with "PAT". The same can be done with: | |
96 :%s/pat/PAT/g | |
97 Which is two characters shorter! | |
98 | |
1623 | 99 When using "global" in Ex mode, a special case is using ":visual" as a |
100 command. This will move to a matching line, go to Normal mode to let you | |
101 execute commands there until you use |Q| to return to Ex mode. This will be | |
102 repeated for each matching line. While doing this you cannot use ":global". | |
103 To abort this type CTRL-C twice. | |
168 | 104 |
7 | 105 ============================================================================== |
106 3. Complex repeats *complex-repeat* | |
107 | |
108 *q* *recording* | |
109 q{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 | |
7233
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
112 a mapping and |:normal|. |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
113 |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
114 Note: If the register being used for recording is also |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
115 used for |y| and |p| the result is most likely not |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
116 what is expected, because the put will paste the |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
117 recorded macro and the yank will overwrite the |
9487ea110214
commit https://github.com/vim/vim/commit/a0ed84a26897c994512873a895b9fc54e90c6845
Christian Brabandt <cb@256bit.org>
parents:
6757
diff
changeset
|
118 recorded macro. {Vi: no recording} |
7 | 119 |
120 q 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 *@* | |
3445 | 125 @{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} [count] |
7 | 126 times. Note that register '%' (name of the current |
127 file) and '#' (name of the alternate file) cannot be | |
2681 | 128 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} | |
7 | 135 |
168 | 136 *@@* *E748* |
7 | 137 @@ Repeat the previous @{0-9a-z":*} [count] times. |
138 | |
3445 | 139 :[addr]*{0-9a-z".=+} *:@* *:star* |
140 :[addr]@{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} as an Ex | |
7 | 141 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 ============================================================================== | |
165 4. Using Vim scripts *using-scripts* | |
166 | |
167 For 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 ":". | |
716 | 172 Triggers the |SourcePre| autocommand. |
7 | 173 |
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 | |
237 | 205 starting up. This similar command: > |
7 | 206 :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 | |
2207
b17bbfa96fa0
Add the settabvar() and gettabvar() functions.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
237 Mark) in utf-8 format Vim will recognize it, no need |
7 | 238 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 | |
6476 | 244 *:scr* *:scriptnames* |
245 :scr[iptnames] List all sourced script names, in the order they were | |
7 | 246 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 | |
261 All commands and command sequences can be repeated by putting them in a named | |
262 register and then executing it. There are two ways to get the commands in the | |
263 register: | |
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 | |
272 Often used command sequences can be put under a function key with the ':map' | |
273 command. | |
274 | |
275 An 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 | |
277 the ':map' command to put complicated commands under a function key. | |
278 | |
279 The ':source' command reads Ex commands from a file line by line. You will | |
280 have to type any needed keyboard input. The ':source!' command reads from a | |
281 script file character by character, interpreting each character as if you | |
282 typed it. | |
283 | |
284 Example: When you give the ":!ls" command you get the |hit-enter| prompt. If | |
285 you ':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, | |
287 the next characters from that file are read until a <CR> is found. You will | |
288 not have to type <CR> yourself, unless ":!ls" was the last line in the file. | |
289 | |
290 It is possible to put ':source[!]' commands in the script file, so you can | |
291 make a top-down hierarchy of script files. The ':source' command can be | |
292 nested as deep as the number of files that can be opened at one time (about | |
293 15). The ':source!' command can be nested up to 15 levels deep. | |
294 | |
295 You can use the "<sfile>" string (literally, this is not a special key) inside | |
296 of the sourced file, in places where a file name is expected. It will be | |
297 replaced 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 | |
299 it from your ".vimrc" file with this command: > | |
300 :source <sfile>:h/other.vimrc | |
301 | |
302 In script files terminal-dependent key codes are represented by | |
303 terminal-independent two character codes. This means that they can be used | |
304 in the same way on different kinds of terminals. The first character of a | |
305 key code is 0x80 or 128, shown on the screen as "~@". The second one can be | |
306 found in the list |key-notation|. Any of these codes can also be entered | |
307 with CTRL-V followed by the three digit decimal code. This does NOT work for | |
308 the <t_xx> termcap codes, these can only be used in mappings. | |
309 | |
310 *:source_crnl* *W15* | |
311 MS-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' | |
314 is not empty and the first line does not end in a <CR>. This fails if the | |
315 first line has something like ":map <F1> :help^M", where "^M" is a <CR>. If | |
316 the first line ends in a <CR>, but following ones don't, you will get an error | |
317 message, because the <CR> from the first lines will be lost. | |
318 | |
333 | 319 Mac Classic: Files that are read with ":source" normally have <CR> <EOL>s. |
7 | 320 These always work. If you are using a file with <NL> <EOL>s (for example, a |
321 file made on Unix), this will be recognized if 'fileformats' is not empty and | |
322 the first line does not end in a <CR>. Be careful not to use a file with <NL> | |
323 linebreaks which has a <CR> in first line. | |
324 | |
325 On other systems, Vim expects ":source"ed files to end in a <NL>. These | |
326 always work. If you are using a file with <CR><NL> <EOL>s (for example, a | |
327 file made on MS-DOS), all lines will have a trailing <CR>. This may cause | |
328 problems for some commands (e.g., mappings). There is no automatic <EOL> | |
329 detection, because it's common to start with a line that defines a mapping | |
330 that ends in a <CR>, which will confuse the automaton. | |
331 | |
332 *line-continuation* | |
333 Long lines in a ":source"d Ex command script file can be split by inserting | |
334 a line continuation symbol "\" (backslash) at the start of the next line. | |
335 There can be white space before the backslash, which is ignored. | |
336 | |
337 Example: the lines > | |
338 :set comments=sr:/*,mb:*,el:*/, | |
339 \://, | |
340 \b:#, | |
341 \:%, | |
342 \n:>, | |
343 \fb:- | |
344 are interpreted as if they were given in one line: | |
345 :set comments=sr:/*,mb:*,el:*/,://,b:#,:%,n:>,fb:- | |
346 | |
347 All leading whitespace characters in the line before a backslash are ignored. | |
348 Note however that trailing whitespace in the line before it cannot be | |
349 inserted freely; it depends on the position where a command is split up | |
350 whether additional whitespace is allowed or not. | |
351 | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
352 When a space is required it's best to put it right after the backslash. A |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
353 space at the end of a line is hard to see and may be accidentally deleted. > |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
354 :syn match Comment |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
355 \ "very long regexp" |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
356 \ keepend |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
357 |
7 | 358 There is a problem with the ":append" and ":insert" commands: > |
359 :1append | |
360 \asdf | |
361 . | |
362 The backslash is seen as a line-continuation symbol, thus this results in the | |
363 command: > | |
364 :1appendasdf | |
365 . | |
366 To avoid this, add the 'C' flag to the 'cpoptions' option: > | |
367 :set cpo+=C | |
368 :1append | |
369 \asdf | |
370 . | |
371 :set cpo-=C | |
372 | |
373 Note that when the commands are inside a function, you need to add the 'C' | |
374 flag 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 | |
383 Rationale: | |
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 ============================================================================== | |
391 5. Debugging scripts *debug-scripts* | |
392 | |
393 Besides the obvious messages that you can add to your scripts to find out what | |
394 they are doing, Vim offers a debug mode. This allows you to step through a | |
395 sourced file or user function and set breakpoints. | |
396 | |
397 NOTE: The debugging mode is far from perfect. Debugging will have side | |
398 effects on how Vim works. You cannot use it to debug everything. For | |
399 example, the display is messed up by the debugging messages. | |
400 {Vi does not have a debug mode} | |
401 | |
402 An alternative to debug mode is setting the 'verbose' option. With a bigger | |
403 number it will give more verbose messages about what Vim is doing. | |
404 | |
405 | |
406 STARTING DEBUG MODE *debug-mode* | |
407 | |
408 To enter debugging mode use one of these methods: | |
409 1. 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* | |
419 2. 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 | |
424 3. 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 | |
430 In debugging mode every executed command is displayed before it is executed. | |
431 Comment lines, empty lines and lines that are not executed are skipped. When | |
432 a line contains two commands, separated by "|", each command will be displayed | |
433 separately. | |
434 | |
435 | |
436 DEBUG MODE | |
437 | |
438 Once in debugging mode, the usual Ex commands can be used. For example, to | |
439 inspect the value of a variable: > | |
440 echo idx | |
441 When 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 | |
444 All commands are executed in the context of the current function or script. | |
445 You can also set options, for example setting or resetting 'verbose' will show | |
446 what happens, but you might want to set it just before executing the lines you | |
447 are interested in: > | |
448 :set verbose=20 | |
449 | |
450 Commands that require updating the screen should be avoided, because their | |
451 effect won't be noticed until after leaving debug mode. For example: > | |
452 :help | |
453 won't be very helpful. | |
454 | |
455 There is a separate command-line history for debug mode. | |
456 | |
457 The line number for a function line is relative to the start of the function. | |
458 If you have trouble figuring out where you are, edit the file that defines | |
459 the function in another Vim, search for the start of the function and do | |
460 "99j". Replace "99" with the line number. | |
461 | |
462 Additionally, 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. | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
486 *>bt* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
487 *>backtrace* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
488 *>where* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
489 backtrace Show the call stacktrace for current debugging session. |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
490 bt |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
491 where |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
492 *>frame* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
493 frame N Goes to N bactrace level. + and - signs make movement |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
494 relative. E.g., ":frame +3" goes three frames up. |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
495 *>up* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
496 up Goes one level up from call stacktrace. |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
497 *>down* |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
498 down Goes one level down from call stacktrace. |
7 | 499 |
500 About 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. | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
503 - You can shorten them, up to a single character, unless more then one command |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
504 starts with the same letter. "f" stands for "finish", use "fr" for "frame". |
7 | 505 - 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 | |
7605
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
510 The backtrace shows the hierarchy of function calls, e.g.: |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
511 >bt ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
512 3 function One[3] ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
513 2 Two[3] ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
514 ->1 Three[3] ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
515 0 Four ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
516 line 1: let four = 4 ~ |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
517 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
518 The "->" points to the current frame. Use "up", "down" and "frame N" to |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
519 select another frame. |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
520 |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
521 In the current frame you can evaluate the local function variables. There is |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
522 no way to see the command at the current line yet. |
8fc60af6dbf5
commit https://github.com/vim/vim/commit/f1f60f859cdbb2638b3662ccf7b1d179865fe7dc
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
523 |
7 | 524 |
525 DEFINING 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 | |
10 | 537 :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 | |
7 | 544 The [lnum] is the line number of the breakpoint. Vim will stop at or after |
545 this line. When omitted line 1 is used. | |
546 | |
170 | 547 *:debug-name* |
7 | 548 {name} is a pattern that is matched with the file or function name. The |
549 pattern is like what is used for autocommands. There must be a full match (as | |
550 if the pattern starts with "^" and ends in "$"). A "*" matches any sequence | |
551 of characters. 'ignorecase' is not used, but "\c" can be used in the pattern | |
552 to ignore case |/\c|. Don't include the () for the function name! | |
553 | |
11 | 554 The match for sourced scripts is done against the full file name. If no path |
555 is specified the current directory is used. Examples: > | |
556 breakadd file explorer.vim | |
557 matches "explorer.vim" in the current directory. > | |
7 | 558 breakadd file *explorer.vim |
11 | 559 matches ".../plugin/explorer.vim", ".../plugin/iexplorer.vim", etc. > |
7 | 560 breakadd file */explorer.vim |
11 | 561 matches ".../plugin/explorer.vim" and "explorer.vim" in any other directory. |
7 | 562 |
563 The match for functions is done against the name as it's shown in the output | |
564 of ":function". For local functions this means that something like "<SNR>99_" | |
565 is prepended. | |
566 | |
148 | 567 Note that functions are first loaded and later executed. When they are loaded |
568 the "file" breakpoints are checked, when they are executed the "func" | |
569 breakpoints. | |
570 | |
7 | 571 |
572 DELETING BREAKPOINTS | |
573 *:breakd* *:breakdel* *E161* | |
574 :breakd[el] {nr} | |
575 Delete breakpoint {nr}. Use |:breaklist| to see the number of | |
576 each breakpoint. | |
577 | |
359 | 578 :breakd[el] * |
579 Delete all breakpoints. | |
580 | |
7 | 581 :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 | |
10 | 587 :breakd[el] here |
588 Delete a breakpoint at the current line of the current file. | |
589 | |
7 | 590 When [lnum] is omitted, the first breakpoint in the function or file is |
591 deleted. | |
592 The {name} must be exactly the same as what was typed for the ":breakadd" | |
593 command. "explorer", "*explorer.vim" and "*explorer*" are different. | |
594 | |
595 | |
596 LISTING BREAKPOINTS | |
597 *:breakl* *:breaklist* | |
598 :breakl[ist] | |
599 List all breakpoints. | |
600 | |
601 | |
602 OBSCURE | |
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 | |
170 | 615 ============================================================================== |
616 6. Profiling *profile* *profiling* | |
617 | |
2283
7e1bd501306d
Mainly documentation updates.
Bram Moolenaar <bram@vim.org>
parents:
2207
diff
changeset
|
618 Profiling means that Vim measures the time that is spent on executing |
170 | 619 functions and/or scripts. The |+profile| feature is required for this. |
620 It is only included when Vim was compiled with "huge" features. | |
621 {Vi does not have profiling} | |
622 | |
794 | 623 You can also use the |reltime()| function to measure time. This only requires |
624 the |+reltime| feature, which is present more often. | |
625 | |
5244 | 626 For profiling syntax highlighting see |:syntime|. |
627 | |
5763 | 628 For 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 | |
5244 | 634 |
170 | 635 :prof[ile] start {fname} *:prof* *:profile* *E750* |
636 Start profiling, write the output in {fname} upon exit. | |
6757 | 637 "~/" and environment variables in {fname} will be expanded. |
790 | 638 If {fname} already exists it will be silently overwritten. |
170 | 639 The variable |v:profiling| is set to one. |
640 | |
790 | 641 :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 | |
170 | 649 :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 | |
5763 | 659 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. | |
170 | 663 |
664 | |
364 | 665 :profd[el] ... *:profd* *:profdel* |
666 Stop profiling for the arguments specified. See |:breakdel| | |
667 for the arguments. | |
668 | |
669 | |
170 | 670 You must always start with a ":profile start fname" command. The resulting |
671 file is written when Vim exits. Here is an example of the output, with line | |
672 numbers 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) ~ | |
856 | 680 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: ") ~ | |
170 | 685 |
686 The header (lines 1-4) gives the time for the whole function. The "Total" | |
687 time is the time passed while the function was executing. The "Self" time is | |
688 the "Total" time reduced by time spent in: | |
689 - other user defined functions | |
690 - sourced scripts | |
691 - executed autocommands | |
692 - external (shell) commands | |
693 | |
694 Lines 7-11 show the time spent in each executed line. Lines that are not | |
695 executed do not count. Thus a comment line is never counted. | |
696 | |
697 The 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. | |
699 That is because the line is also executed to detect the end of the loop. | |
700 | |
701 The time Vim spends waiting for user input isn't counted at all. Thus how | |
702 long you take to respond to the input() prompt is irrelevant. | |
703 | |
704 Profiling should give a good indication of where time is spent, but keep in | |
705 mind 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: > | |
856 | 723 :if !v:profiling |
170 | 724 : delfunc MyFunc |
725 :endif | |
726 < | |
177 | 727 - Profiling may give weird results on multi-processor systems, when sleep |
728 mode kicks in or the processor frequency is reduced to save power. | |
170 | 729 |
1125 | 730 - The "self" time is wrong when a function is used recursively. |
731 | |
732 | |
7 | 733 vim:tw=78:ts=8:ft=help:norl: |