robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesdocs: misc, cwd, vimscript.txt #41356b107154ba2

master
27.3 KiB723 linesraw
1*vimscript.txt*    Nvim
2
3
4                            NVIM REFERENCE MANUAL
5
6
7Vimscript and debugging						*vimscript*
8
9This reference describes commands for running and debugging Vimscript.
10For details on authoring Vimscript, see: |expression| |vimscript-functions|
11
12                                      Type |gO| to see the table of contents.
13
14==============================================================================
15Using Vimscript						*using-scripts*
16
17For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
18
19					*:so* *:source*
20:so[urce] {file}	Runs |Ex-command|s or Lua code (".lua" files) from
21			{file}. Triggers the |SourcePre| autocommand.
22
23:[range]so[urce]	Read Ex commands or Lua code from the [range] of lines
24			in the current buffer.  When [range] is omitted read
25			all lines.  The buffer is treated as Lua code if its
26			'filetype' is "lua" or its filename ends with ".lua".
27
28			When sourcing commands or Lua code from the current
29			buffer, the same script-ID |<SID>| is used even if the
30			buffer is sourced multiple times.  If a buffer is
31			sourced more than once, then the functions in the
32			buffer are defined again.
33
34			Implementation detail: When sourcing a [range] of
35			lines that falls inside a folded region, the range
36			will be adjusted to the start and end of the fold,
37			but only if a two line specifiers range was used.
38
39							*:source!*
40:so[urce]! {file}	Runs |Normal-mode| commands from {file}. When used
41			after |:global|, |:argdo|, |:windo|, |:bufdo|, in
42			a loop or when another command follows the display
43			won't be updated while executing the commands.
44
45							*:ru* *:runtime*
46:ru[ntime][!] [where] {file} ..
47			Sources |Ex| commands or Lua code (".lua" files) read
48			from {file} (a relative path) in each directory given
49			by 'runtimepath' and/or 'packpath'.
50			Ignores non-existing files.
51
52			Example: >
53				:runtime syntax/c.vim
54				:runtime syntax/c.lua
55
56<			There can be multiple space-separated {file}
57			arguments. Each {file} is searched for in the first
58			directory from 'runtimepath', then in the second
59			directory, etc.
60
61			When [!] is included, all found files are sourced.
62			Else only the first found file is sourced.
63
64			When [where] is omitted only 'runtimepath' is used.
65			Other values:
66				START	search only under "start" in 'packpath'
67				OPT	search only under "opt" in 'packpath'
68				PACK	search under "start" and "opt" in
69					'packpath'
70				ALL	first use 'runtimepath', then search
71					under "start" and "opt" in 'packpath'
72
73			When {file} contains wildcards it is expanded to all
74			matching files.  Example: >
75				:runtime! plugin/**/*.{vim,lua}
76<			This is what Nvim uses to load the plugin files when
77			starting up.  This similar command: >
78				:runtime plugin/**/*.{vim,lua}
79<			would source the first file only.
80
81			For each {file} pattern, if two `.vim` and `.lua` file
82			names match and differ only in extension, the `.vim`
83			file is sourced first.
84
85			When 'verbose' is one or higher, there is a message
86			when no file could be found.
87			When 'verbose' is two or higher, there is a message
88			about each searched file.
89
90							*:pa* *:packadd* *E919*
91:pa[ckadd][!] {name}	|pack-add| Search for an optional plugin directory in
92			'packpath', source any plugin files found, and add it
93			to 'runtimepath'.  The directory must match: >
94				pack/*/opt/{name}
95<			If the directory pack/*/opt/{name}/after exists it is
96			added at the end of 'runtimepath'.
97
98			Note: Use |vim.pack.add()| to install from a URL.
99
100			If loading packages from "pack/*/start" was skipped,
101			then this directory is searched first: >
102				pack/*/start/{name}
103<
104			Note that {name} is the directory name, not the name
105			of the .vim file.  All files matching the patterns >
106				pack/*/opt/{name}/plugin/**/*.vim
107				pack/*/opt/{name}/plugin/**/*.lua
108<			will be sourced.  This allows for using subdirectories
109			below "plugin", just like with plugins in
110			'runtimepath'.
111
112			If the filetype detection was already enabled (this
113			is usually done with a `syntax enable` or `filetype on`
114			command in your |vimrc|, or automatically during
115			|initialization|), and the package was found in
116			"pack/*/opt/{name}", this command will also look
117			for "{name}/ftdetect/*.vim" files.
118
119			When the optional "!" is given, no plugin/ files or
120			ftdetect/ scripts are loaded, only the matching
121			directories are added to 'runtimepath'.  This is
122			useful in your |init.vim|.  The plugins will then be
123			loaded during the |load-plugins| |initialization| step
124			(note that the loading order will be reversed because
125			each directory is inserted before others), after
126			loading the ftdetect scripts.
127
128			To programmatically decide if `!` is needed during
129			startup, check |v:vim_did_init|: use `!` if 0 (to not
130			duplicate |load-plugins| step), no `!` otherwise (to
131			force load plugin files as otherwise they won't be
132			loaded automatically).
133
134						*:packl* *:packloadall*
135:packl[oadall][!]	Load all packages in the "start" directory under each
136			entry in 'packpath'.
137
138			First all the directories found are added to
139			'runtimepath', then the plugins found in the
140			directories are sourced.  This allows for a plugin to
141			depend on something of another plugin, e.g. an
142			"autoload" directory.  See |packload-two-steps| for
143			how this can be useful.
144
145			This is normally done automatically during startup,
146			after loading your |vimrc| file.  With this command it
147			can be done earlier.
148
149			Packages will be loaded only once.  Using
150			`:packloadall` a second time will have no effect.
151			When the optional ! is added this command will load
152			packages even when done before.
153
154			Note that when using `:packloadall` in the |vimrc|
155			file, the 'runtimepath' option is updated, and later
156			all plugins in 'runtimepath' will be loaded, which
157			means they are loaded again.  Plugins are expected to
158			handle that.
159
160			An error only causes sourcing the script where it
161			happens to be aborted, further plugins will be loaded.
162			See |packages|.
163
164:scripte[ncoding] [encoding]		*:scripte* *:scriptencoding* *E167*
165			Specify the character encoding used in the script.
166			The following lines will be converted from [encoding]
167			to the value of the 'encoding' option, if they are
168			different.  Examples: >
169				scriptencoding iso-8859-5
170				scriptencoding cp932
171<
172			When [encoding] is empty, no conversion is done.  This
173			can be used to restrict conversion to a sequence of
174			lines: >
175				scriptencoding euc-jp
176				... lines to be converted ...
177				scriptencoding
178				... not converted ...
179
180<			When conversion isn't supported by the system, there
181			is no error message and no conversion is done.  When a
182			line can't be converted there is no error and the
183			original line is kept.
184
185			Don't use "ucs-2" or "ucs-4", scripts cannot be in
186			these encodings (they would contain NUL bytes).
187			When a sourced script starts with a BOM (Byte Order
188			Mark) in utf-8 format Vim will recognize it, no need
189			to use ":scriptencoding utf-8" then.
190
191						*:scr* *:scriptnames*
192:scr[iptnames]		List all sourced script names, in the order they were
193			first sourced.  The number is used for the script ID
194			|<SID>|.
195			Also see `getscriptinfo()`.
196
197:scr[iptnames][!] {scriptId}			*:script*
198			Edit script {scriptId}.  Although ":scriptnames name"
199			works, using ":script name" is recommended.
200			When the current buffer can't be |abandon|ed and the !
201			is not present, the command fails.
202
203						*:fini* *:finish* *E168*
204:fini[sh]		Stop sourcing a script.  Can only be used in a Vim
205			script file.  This is a quick way to skip the rest of
206			the file.  If it is used after a |:try| but before the
207			matching |:finally| (if present), the commands
208			following the ":finally" up to the matching |:endtry|
209			are executed first.  This process applies to all
210			nested ":try"s in the script.  The outermost ":endtry"
211			then stops sourcing the script.
212
213All commands and command sequences can be repeated by putting them in a named
214register and then executing it.  There are two ways to get the commands in the
215register:
216- Use the record command "q".  You type the commands once, and while they are
217  being executed they are stored in a register.  Easy, because you can see
218  what you are doing.  If you make a mistake, "p"ut the register into the
219  file, edit the command sequence, and then delete it into the register
220  again.  You can continue recording by appending to the register (use an
221  uppercase letter).
222- Delete or yank the command sequence into the register.
223
224Often used command sequences can be put under a function key with the ':map'
225command.
226
227An alternative is to put the commands in a file, and execute them with the
228':source!' command.  Useful for long command sequences.  Can be combined with
229the ':map' command to put complicated commands under a function key.
230
231The ':source' command reads Ex commands from a file or a buffer line by line.
232You will have to type any needed keyboard input.  The ':source!' command reads
233from a script file character by character, interpreting each character as if
234you typed it.
235
236Example: When you give the ":!ls" command you get the |hit-enter| prompt.  If
237you ':source' a file with the line "!ls" in it, you will have to type the
238<Enter> yourself.  But if you ':source!' a file with the line ":!ls" in it,
239the next characters from that file are read until a <CR> is found.  You will
240not have to type <CR> yourself, unless ":!ls" was the last line in the file.
241
242It is possible to put ':source[!]' commands in the script file, so you can
243make a top-down hierarchy of script files.  The ':source' command can be
244nested as deep as the number of files that can be opened at one time (about
24515).  The ':source!' command can be nested up to 15 levels deep.
246
247You can use the "<script>" string (literally, this is not a special key) inside
248of the sourced file, in places where a file name is expected.  It will be
249replaced by the file name of the sourced file.  For example, if you have a
250"other.vimrc" file in the same directory as your |init.vim| file, you can
251source it from your |init.vim| file with this command: >
252	:source <script>:h/other.vimrc
253
254In script files terminal-dependent key codes are represented by
255terminal-independent two character codes.  This means that they can be used
256in the same way on different kinds of terminals.  The first character of a
257key code is 0x80 or 128, shown on the screen as "~@".  The second one can be
258found in the list |key-notation|.  Any of these codes can also be entered
259with CTRL-V followed by the three digit decimal code.
260
261							*:source_crnl* *W15*
262Windows: Files that are read with ":source" normally have <CR><NL> <EOL>s.
263These always work.  If you are using a file with <NL> <EOL>s (for example, a
264file made on Unix), this will be recognized if 'fileformats' is not empty and
265the first line does not end in a <CR>.  This fails if the first line has
266something like ":map <F1> :help^M", where "^M" is a <CR>.  If the first line
267ends in a <CR>, but following ones don't, you will get an error message,
268because the <CR> from the first lines will be lost.
269
270On other systems, Vim expects ":source"ed files to end in a <NL>.  These
271always work.  If you are using a file with <CR><NL> <EOL>s (for example, a
272file made on MS-Windows), all lines will have a trailing <CR>.  This may cause
273problems for some commands (e.g., mappings).  There is no automatic <EOL>
274detection, because it's common to start with a line that defines a mapping
275that ends in a <CR>, which will confuse the automaton.
276
277							*line-continuation*
278Long lines in a ":source"d Ex command script file can be split by inserting
279a line continuation symbol "\" (backslash) at the start of the next line.
280There can be white space before the backslash, which is ignored.
281
282Example: the lines >
283	:set comments=sr:/*,mb:*,el:*/,
284		     \://,
285		     \b:#,
286		     \:%,
287		     \n:>,
288		     \fb:-
289are interpreted as if they were given in one line: >
290	:set comments=sr:/*,mb:*,el:*/,://,b:#,:%,n:>,fb:-
291
292All leading whitespace characters in the line before a backslash are ignored.
293Note however that trailing whitespace in the line before it cannot be
294inserted freely; it depends on the position where a command is split up
295whether additional whitespace is allowed or not.
296
297When a space is required it's best to put it right after the backslash.  A
298space at the end of a line is hard to see and may be accidentally deleted. >
299	:syn match Comment
300		\ "very long regexp"
301		\ keepend
302
303There is a problem with the ":append" and ":insert" commands: >
304   :1append
305   \asdf
306   .
307The backslash is seen as a line-continuation symbol, thus this results in the
308command: >
309   :1appendasdf
310   .
311To avoid this, add the 'C' flag to the 'cpoptions' option: >
312   :set cpo+=C
313   :1append
314   \asdf
315   .
316   :set cpo-=C
317
318Note that when the commands are inside a function, you need to add the 'C'
319flag when defining the function, it is not relevant when executing it. >
320   :set cpo+=C
321   :function Foo()
322   :1append
323   \asdf
324   .
325   :endfunction
326   :set cpo-=C
327<
328					*line-continuation-comment*
329To add a comment in between the lines start with `'"\ '`.  Notice the space
330after the backslash.  Example: >
331	let array = [
332		"\ first entry comment
333		\ 'first',
334		"\ second entry comment
335		\ 'second',
336		\ ]
337
338Rationale:
339	Most programs work with a trailing backslash to indicate line
340	continuation.  Using this in Vim would cause incompatibility with Vi.
341	For example for this Vi mapping: >
342		:map xx  asdf\
343<	Therefore the unusual leading backslash is used.
344
345	Starting a comment in a continuation line results in all following
346	continuation lines to be part of the comment.  Since it was like this
347	for a long time, when making it possible to add a comment halfway a
348	sequence of continuation lines, it was not possible to use \", since
349	that was a valid continuation line.  Using `'"\ '` comes closest, even
350	though it may look a bit weird.  Requiring the space after the
351	backslash is to make it very unlikely this is a normal comment line.
352
353==============================================================================
354Debugging scripts					*debug-scripts*
355
356Besides the obvious messages that you can add to your scripts to find out what
357they are doing, Vim offers a debug mode.  This allows you to step through a
358sourced file or user function and set breakpoints.
359
360NOTE: The debugging mode is far from perfect.  Debugging will have side
361effects on how Vim works.  You cannot use it to debug everything.  For
362example, the display is messed up by the debugging messages.
363
364An alternative to debug mode is setting the 'verbose' option.  With a bigger
365number it will give more verbose messages about what Vim is doing.
366
367
368STARTING DEBUG MODE						*debug-mode*
369
370To enter debugging mode use one of these methods:
3711. Start Vim with the |-D| argument: >
372	vim -D file.txt
373<  Debugging will start as soon as the first vimrc file is sourced.  This is
374   useful to find out what is happening when Vim is starting up.  A side
375   effect is that Vim will switch the terminal mode before initialisations
376   have finished, with unpredictable results.
377   For a GUI-only version (Windows) the debugging will start as
378   soon as the GUI window has been opened.  To make this happen early, add a
379   ":gui" command in the vimrc file.
380								*:debug*
3812. Run a command with ":debug" prepended.  Debugging will only be done while
382   this command executes.  Useful for debugging a specific script or user
383   function.  And for scripts and functions used by autocommands.  Example: >
384	:debug edit test.txt.gz
385
3863. Set a breakpoint in a sourced file or user function.  You could do this in
387   the command line: >
388	vim -c "breakadd file */explorer.vim" .
389<  This will run Vim and stop in the first line of the "explorer.vim" script.
390   Breakpoints can also be set while in debugging mode.
391
392In debugging mode every executed command is displayed before it is executed.
393Comment lines, empty lines and lines that are not executed are skipped.  When
394a line contains two commands, separated by "|", each command will be displayed
395separately.
396
397
398DEBUG MODE
399
400Once in debugging mode, the usual Ex commands can be used.  For example, to
401inspect the value of a variable: >
402	echo idx
403When inside a user function, this will print the value of the local variable
404"idx".  Prepend "g:" to get the value of a global variable: >
405	echo g:idx
406All commands are executed in the context of the current function or script.
407You can also set options, for example setting or resetting 'verbose' will show
408what happens, but you might want to set it just before executing the lines you
409are interested in: >
410	:set verbose=20
411
412Commands that require updating the screen should be avoided, because their
413effect won't be noticed until after leaving debug mode.  For example: >
414	:help
415won't be very helpful.
416
417There is a separate command-line history for debug mode.
418
419The line number for a function line is relative to the start of the function.
420If you have trouble figuring out where you are, edit the file that defines
421the function in another Vim, search for the start of the function and do
422"99j".  Replace "99" with the line number.
423
424Additionally, these commands can be used:
425							*>cont*
426	cont		Continue execution until the next breakpoint is hit.
427							*>quit*
428	quit		Abort execution.  This is like using CTRL-C, some
429			things might still be executed, doesn't abort
430			everything.  Still stops at the next breakpoint.
431							*>next*
432	next		Execute the command and come back to debug mode when
433			it's finished.  This steps over user function calls
434			and sourced files.
435							*>step*
436	step		Execute the command and come back to debug mode for
437			the next command.  This steps into called user
438			functions and sourced files.
439							*>interrupt*
440	interrupt	This is like using CTRL-C, but unlike ">quit" comes
441			back to debug mode for the next command that is
442			executed.  Useful for testing |:finally| and |:catch|
443			on interrupt exceptions.
444							*>finish*
445	finish		Finish the current script or user function and come
446			back to debug mode for the command after the one that
447			sourced or called it.
448							*>bt*
449							*>backtrace*
450							*>where*
451	backtrace	Show the call stacktrace for current debugging
452			session.
453	bt
454	where
455							*>frame*
456	frame N		Goes to N backtrace level. + and - signs make movement
457			relative.  E.g., ":frame +3" goes three frames up.
458							*>up*
459	up		Goes one level up from call stacktrace.
460							*>down*
461	down		Goes one level down from call stacktrace.
462
463About the additional commands in debug mode:
464- There is no command-line completion for them, you get the completion for the
465  normal Ex commands only.
466- You can shorten them, up to a single character, unless more than one command
467  starts with the same letter.  "f" stands for "finish", use "fr" for "frame".
468- Hitting <CR> will repeat the previous one.  When doing another command, this
469  is reset (because it's not clear what you want to repeat).
470- When you want to use the Ex command with the same name, prepend a colon:
471  ":cont", ":next", ":finish" (or shorter).
472
473The backtrace shows the hierarchy of function calls, e.g.:
474	>bt ~
475	  3 function One[3] ~
476	  2 Two[3] ~
477	->1 Three[3] ~
478	  0 Four ~
479	line 1: let four = 4 ~
480
481The "->" points to the current frame.  Use "up", "down" and "frame N" to
482select another frame.
483
484In the current frame you can evaluate the local function variables.  There is
485no way to see the command at the current line yet.
486
487
488DEFINING BREAKPOINTS
489							*:breaka* *:breakadd*
490:breaka[dd] func [lnum] {name}
491		Set a breakpoint in a function.  Example: >
492			:breakadd func Explore
493<		Doesn't check for a valid function name, thus the breakpoint
494		can be set before the function is defined.
495
496:breaka[dd] file [lnum] {name}
497		Set a breakpoint in a sourced file.  Example: >
498			:breakadd file 43 init.vim
499
500:breaka[dd] here
501		Set a breakpoint in the current line of the current file.
502		Like doing: >
503			:breakadd file <cursor-line> <current-file>
504<		Note that this only works for commands that are executed when
505		sourcing the file, not for a function defined in that file.
506
507:breaka[dd] expr {expression}
508		Sets a breakpoint, that will break whenever the {expression}
509		evaluates to a different value.  Example: >
510			:breakadd expr g:lnum
511<		Will break, whenever the global variable lnum changes.
512
513		Errors in evaluation are suppressed, you can use the name of a
514		variable that does not exist yet.  This also means you will
515		not notice anything if the expression has a mistake.
516
517		Note if you watch a |script-variable| this will break
518		when switching scripts, since the script variable is only
519		valid in the script where it has been defined and if that
520		script is called from several other scripts, this will stop
521		whenever that particular variable will become visible or
522		inaccessible again.
523
524The [lnum] is the line number of the breakpoint.  Vim will stop at or after
525this line.  When omitted line 1 is used.
526
527							*:debug-name*
528{name} is a pattern that is matched with the file or function name.  The
529pattern is like what is used for autocommands.  There must be a full match (as
530if the pattern starts with "^" and ends in "$").  A "*" matches any sequence
531of characters.  'ignorecase' is not used, but "\c" can be used in the pattern
532to ignore case |/\c|.  Don't include the () for the function name!
533
534The match for sourced scripts is done against the full file name.  If no path
535is specified the current directory is used.  Examples: >
536	breakadd file explorer.vim
537matches "explorer.vim" in the current directory. >
538	breakadd file *explorer.vim
539matches ".../plugin/explorer.vim", ".../plugin/iexplorer.vim", etc. >
540	breakadd file */explorer.vim
541matches ".../plugin/explorer.vim" and "explorer.vim" in any other directory.
542
543The match for functions is done against the name as it's shown in the output
544of ":function".  For local functions this means that something like "<SNR>99_"
545is prepended.
546
547Note that functions are first loaded and later executed.  When they are loaded
548the "file" breakpoints are checked, when they are executed the "func"
549breakpoints.
550
551
552DELETING BREAKPOINTS
553						*:breakd* *:breakdel* *E161*
554:breakd[el] {nr}
555		Delete breakpoint {nr}.  Use |:breaklist| to see the number of
556		each breakpoint.
557
558:breakd[el] *
559		Delete all breakpoints.
560
561:breakd[el] func [lnum] {name}
562		Delete a breakpoint in a function.
563
564:breakd[el] file [lnum] {name}
565		Delete a breakpoint in a sourced file.
566
567:breakd[el] here
568		Delete a breakpoint at the current line of the current file.
569
570When [lnum] is omitted, the first breakpoint in the function or file is
571deleted.
572The {name} must be exactly the same as what was typed for the ":breakadd"
573command.  "explorer", "*explorer.vim" and "*explorer*" are different.
574
575
576LISTING BREAKPOINTS
577							*:breakl* *:breaklist*
578:breakl[ist]
579		List all breakpoints.
580
581
582OBSCURE
583
584						*:debugg* *:debuggreedy*
585:debugg[reedy]
586		Read debug mode commands from the normal input stream, instead
587		of getting them directly from the user.  Only useful for test
588		scripts.  Example: >
589		  echo 'q^Mq' | vim -e -s -c debuggreedy -c 'breakadd file script.vim' -S script.vim
590
591:0debugg[reedy]
592		Undo ":debuggreedy": get debug mode commands directly from the
593		user, don't use typeahead for debug commands.
594
595==============================================================================
596Profiling						*profile* *profiling*
597
598Profiling means that Vim measures the time that is spent on executing
599functions and/or scripts.
600
601You can also use the |reltime()| function to measure time.
602
603For profiling syntax highlighting see |:syntime|.
604
605For example, to profile the one_script.vim script file: >
606	:profile start /tmp/one_script_profile
607	:profile file one_script.vim
608	:source one_script.vim
609	:exit
610
611
612:prof[ile] start {fname}			*:prof* *:profile* *E750*
613		Start profiling, write the output in {fname} upon exit or when
614		a `:profile stop` or `:profile dump` command is invoked.
615		"~/" and environment variables in {fname} will be expanded.
616		If {fname} already exists it will be silently overwritten.
617		The variable |v:profiling| is set to one.
618
619:prof[ile] stop
620		Write the collected profiling information to the logfile and
621		stop profiling.  You can use the `:profile start` command to
622		clear the profiling statistics and start profiling again.
623
624:prof[ile] pause
625		Stop profiling until the next `:profile continue` command.
626		Can be used when doing something that should not be counted
627		(e.g., an external command).  Does not nest.
628
629:prof[ile] continue
630		Continue profiling after `:profile pause`.
631
632:prof[ile] func {pattern}
633		Profile function that matches the pattern {pattern}.
634		See |:debug-name| for how {pattern} is used.
635
636:prof[ile][!] file {pattern}
637		Profile script file that matches the pattern {pattern}.
638		See |:debug-name| for how {pattern} is used.
639		This only profiles the script itself, not the functions
640		defined in it.
641		When the [!] is added then all functions defined in the script
642		will also be profiled.
643		Note that profiling only starts when the script is loaded
644		after this command.  A :profile command in the script itself
645		won't work.
646
647:prof[ile] dump
648		Write the current state of profiling to the logfile
649		immediately.  After running this command, Vim continues to
650		collect the profiling statistics.
651
652:profd[el] ...						*:profd* *:profdel*
653		Stop profiling for the arguments specified.  See |:breakdel|
654		for the arguments.  Examples: >
655			profdel func MyFunc
656			profdel file MyScript.vim
657			profdel here
658
659You must always start with a ":profile start fname" command.  The resulting
660file is written when Vim exits.  For example, to profile one specific
661function: >
662	profile start /tmp/vimprofile
663	profile func MyFunc
664
665Here is an example of the output, with line
666numbers prepended for the explanation:
667
668  1 FUNCTION  Test2() ~
669  2 Called 1 time ~
670  3 Total time:   0.155251 ~
671  4  Self time:   0.002006 ~
672  5  ~
673  6 count  total (s)   self (s) ~
674  7	9	       0.000096   for i in range(8) ~
675  8	8   0.153655   0.000410     call Test3() ~
676  9	8	       0.000070   endfor ~
677 10				  " Ask a question ~
678 11	1	       0.001341   echo input("give me an answer: ") ~
679
680The header (lines 1-4) gives the time for the whole function.  The "Total"
681time is the time passed while the function was executing.  The "Self" time is
682the "Total" time reduced by time spent in:
683- other user defined functions
684- sourced scripts
685- executed autocommands
686- external (shell) commands
687
688Lines 7-11 show the time spent in each executed line.  Lines that are not
689executed do not count.  Thus a comment line is never counted.
690
691The Count column shows how many times a line was executed.  Note that the
692"for" command in line 7 is executed one more time as the following lines.
693That is because the line is also executed to detect the end of the loop.
694
695The time Vim spends waiting for user input isn't counted at all.  Thus how
696long you take to respond to the input() prompt is irrelevant.
697
698Profiling should give a good indication of where time is spent, but keep in
699mind there are various things that may clobber the results:
700
701- Real elapsed time is measured, if other processes are busy they may cause
702  delays at unpredictable moments.  You may want to run the profiling several
703  times and use the lowest results.
704
705- If you have several commands in one line you only get one time.  Split the
706  line to see the time for the individual commands.
707
708- The time of the lines added up is mostly less than the time of the whole
709  function.  There is some overhead in between.
710
711- Functions that are deleted before Vim exits will not produce profiling
712  information.  You can check the |v:profiling| variable if needed: >
713	:if !v:profiling
714	:   delfunc MyFunc
715	:endif
716<
717- Profiling may give weird results on multi-processor systems, when sleep
718  mode kicks in or the processor frequency is reduced to save power.
719
720- The "self" time is wrong when a function is used recursively.
721
722
723 vim:tw=78:ts=8:noet:ft=help:norl: