1*repeat.txt* For Vim version 7.4. Last change: 2015 Apr 13 2 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| 166. Profiling |profiling| 17 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 24 included in 'cpoptions'. Does not repeat a 25 command-line command. 26 27Simple changes can be repeated with the "." command. Without a count, the 28count of the last change is used. If you enter a count, it will replace the 29last one. |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|. 37 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 60Instead of the '/' which surrounds the {pattern}, you can use any other 61single byte character, but not an alphabetic character, '\', '"' or '|'. 62This 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 67NOTE [cmd] may contain a range; see |collapse| and |edit-paragraph-join| for 68examples. 69 70The 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 99When 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. 104 105============================================================================== 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 112 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} 119 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 *@* 125@{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} [count] 126 times. Note that register '%' (name of the current 127 file) and '#' (name of the alternate file) cannot be 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} 135 136 *@@* *E748* 137@@ Repeat the previous @{0-9a-z":*} [count] times. 138 139:[addr]*{0-9a-z".=+} *:@* *:star* 140:[addr]@{0-9a-z".=*+} Execute the contents of register {0-9a-z".=*+} as an Ex 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============================================================================== 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 ":". 172 Triggers the |SourcePre| autocommand. 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 205 starting up. This similar command: > 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 237 Mark) in utf-8 format Vim will recognize it, no need 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 244 *:scr* *:scriptnames* 245:scr[iptnames] List all sourced script names, in the order they were 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 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 319Mac Classic: Files that are read with ":source" normally have <CR> <EOL>s. 320These 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 352When 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 358There 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. 486 487About the additional commands in debug mode: 488- There is no command-line completion for them, you get the completion for the 489 normal Ex commands only. 490- You can shorten them, up to a single character: "c", "n", "s" and "f". 491- Hitting <CR> will repeat the previous one. When doing another command, this 492 is reset (because it's not clear what you want to repeat). 493- When you want to use the Ex command with the same name, prepend a colon: 494 ":cont", ":next", ":finish" (or shorter). 495 496 497DEFINING BREAKPOINTS 498 *:breaka* *:breakadd* 499:breaka[dd] func [lnum] {name} 500 Set a breakpoint in a function. Example: > 501 :breakadd func Explore 502< Doesn't check for a valid function name, thus the breakpoint 503 can be set before the function is defined. 504 505:breaka[dd] file [lnum] {name} 506 Set a breakpoint in a sourced file. Example: > 507 :breakadd file 43 .vimrc 508 509:breaka[dd] here 510 Set a breakpoint in the current line of the current file. 511 Like doing: > 512 :breakadd file <cursor-line> <current-file> 513< Note that this only works for commands that are executed when 514 sourcing the file, not for a function defined in that file. 515 516The [lnum] is the line number of the breakpoint. Vim will stop at or after 517this line. When omitted line 1 is used. 518 519 *:debug-name* 520{name} is a pattern that is matched with the file or function name. The 521pattern is like what is used for autocommands. There must be a full match (as 522if the pattern starts with "^" and ends in "$"). A "*" matches any sequence 523of characters. 'ignorecase' is not used, but "\c" can be used in the pattern 524to ignore case |/\c|. Don't include the () for the function name! 525 526The match for sourced scripts is done against the full file name. If no path 527is specified the current directory is used. Examples: > 528 breakadd file explorer.vim 529matches "explorer.vim" in the current directory. > 530 breakadd file *explorer.vim 531matches ".../plugin/explorer.vim", ".../plugin/iexplorer.vim", etc. > 532 breakadd file */explorer.vim 533matches ".../plugin/explorer.vim" and "explorer.vim" in any other directory. 534 535The match for functions is done against the name as it's shown in the output 536of ":function". For local functions this means that something like "<SNR>99_" 537is prepended. 538 539Note that functions are first loaded and later executed. When they are loaded 540the "file" breakpoints are checked, when they are executed the "func" 541breakpoints. 542 543 544DELETING BREAKPOINTS 545 *:breakd* *:breakdel* *E161* 546:breakd[el] {nr} 547 Delete breakpoint {nr}. Use |:breaklist| to see the number of 548 each breakpoint. 549 550:breakd[el] * 551 Delete all breakpoints. 552 553:breakd[el] func [lnum] {name} 554 Delete a breakpoint in a function. 555 556:breakd[el] file [lnum] {name} 557 Delete a breakpoint in a sourced file. 558 559:breakd[el] here 560 Delete a breakpoint at the current line of the current file. 561 562When [lnum] is omitted, the first breakpoint in the function or file is 563deleted. 564The {name} must be exactly the same as what was typed for the ":breakadd" 565command. "explorer", "*explorer.vim" and "*explorer*" are different. 566 567 568LISTING BREAKPOINTS 569 *:breakl* *:breaklist* 570:breakl[ist] 571 List all breakpoints. 572 573 574OBSCURE 575 576 *:debugg* *:debuggreedy* 577:debugg[reedy] 578 Read debug mode commands from the normal input stream, instead 579 of getting them directly from the user. Only useful for test 580 scripts. Example: > 581 echo 'q^Mq' | vim -e -s -c debuggreedy -c 'breakadd file script.vim' -S script.vim 582 583:0debugg[reedy] 584 Undo ":debuggreedy": get debug mode commands directly from the 585 user, don't use typeahead for debug commands. 586 587============================================================================== 5886. Profiling *profile* *profiling* 589 590Profiling means that Vim measures the time that is spent on executing 591functions and/or scripts. The |+profile| feature is required for this. 592It is only included when Vim was compiled with "huge" features. 593{Vi does not have profiling} 594 595You can also use the |reltime()| function to measure time. This only requires 596the |+reltime| feature, which is present more often. 597 598For profiling syntax highlighting see |:syntime|. 599 600For example, to profile the one_script.vim script file: > 601 :profile start /tmp/one_script_profile 602 :profile file one_script.vim 603 :source one_script.vim 604 :exit 605 606 607:prof[ile] start {fname} *:prof* *:profile* *E750* 608 Start profiling, write the output in {fname} upon exit. 609 "~/" and environment variables in {fname} will be expanded. 610 If {fname} already exists it will be silently overwritten. 611 The variable |v:profiling| is set to one. 612 613:prof[ile] pause 614 Don't profile until the following ":profile continue". Can be 615 used when doing something that should not be counted (e.g., an 616 external command). Does not nest. 617 618:prof[ile] continue 619 Continue profiling after ":profile pause". 620 621:prof[ile] func {pattern} 622 Profile function that matches the pattern {pattern}. 623 See |:debug-name| for how {pattern} is used. 624 625:prof[ile][!] file {pattern} 626 Profile script file that matches the pattern {pattern}. 627 See |:debug-name| for how {pattern} is used. 628 This only profiles the script itself, not the functions 629 defined in it. 630 When the [!] is added then all functions defined in the script 631 will also be profiled. 632 Note that profiling only starts when the script is loaded 633 after this command. A :profile command in the script itself 634 won't work. 635 636 637:profd[el] ... *:profd* *:profdel* 638 Stop profiling for the arguments specified. See |:breakdel| 639 for the arguments. 640 641 642You must always start with a ":profile start fname" command. The resulting 643file is written when Vim exits. Here is an example of the output, with line 644numbers prepended for the explanation: 645 646 1 FUNCTION Test2() ~ 647 2 Called 1 time ~ 648 3 Total time: 0.155251 ~ 649 4 Self time: 0.002006 ~ 650 5 ~ 651 6 count total (s) self (s) ~ 652 7 9 0.000096 for i in range(8) ~ 653 8 8 0.153655 0.000410 call Test3() ~ 654 9 8 0.000070 endfor ~ 655 10 " Ask a question ~ 656 11 1 0.001341 echo input("give me an answer: ") ~ 657 658The header (lines 1-4) gives the time for the whole function. The "Total" 659time is the time passed while the function was executing. The "Self" time is 660the "Total" time reduced by time spent in: 661- other user defined functions 662- sourced scripts 663- executed autocommands 664- external (shell) commands 665 666Lines 7-11 show the time spent in each executed line. Lines that are not 667executed do not count. Thus a comment line is never counted. 668 669The Count column shows how many times a line was executed. Note that the 670"for" command in line 7 is executed one more time as the following lines. 671That is because the line is also executed to detect the end of the loop. 672 673The time Vim spends waiting for user input isn't counted at all. Thus how 674long you take to respond to the input() prompt is irrelevant. 675 676Profiling should give a good indication of where time is spent, but keep in 677mind there are various things that may clobber the results: 678 679- The accuracy of the time measured depends on the gettimeofday() system 680 function. It may only be as accurate as 1/100 second, even though the times 681 are displayed in micro seconds. 682 683- Real elapsed time is measured, if other processes are busy they may cause 684 delays at unpredictable moments. You may want to run the profiling several 685 times and use the lowest results. 686 687- If you have several commands in one line you only get one time. Split the 688 line to see the time for the individual commands. 689 690- The time of the lines added up is mostly less than the time of the whole 691 function. There is some overhead in between. 692 693- Functions that are deleted before Vim exits will not produce profiling 694 information. You can check the |v:profiling| variable if needed: > 695 :if !v:profiling 696 : delfunc MyFunc 697 :endif 698< 699- Profiling may give weird results on multi-processor systems, when sleep 700 mode kicks in or the processor frequency is reduced to save power. 701 702- The "self" time is wrong when a function is used recursively. 703 704 705 vim:tw=78:ts=8:ft=help:norl: 706