neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

repeat.txt (35890B)


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