Home Explore Blog CI



neovim

2nd chunk of `runtime/doc/repeat.txt`
d4f3690acb635fcc9e439d9f04d977757b7f4aae3375fb9f0000000100000fa0
	:g/found/v/notfound/{cmd}
This first finds all lines containing "found", but only executes {cmd} when
there is no match for "notfound".

Any Ex command can be used, see |ex-cmd-index|.  To execute a Normal mode
command, you can use the `:normal` command: >
	:g/pat/normal {commands}
Make sure that {commands} ends with a whole command, otherwise Vim will wait
for you to type the rest of the command for each match.  The screen will not
have been updated, so you don't know what you are doing.  See |:normal|.

The undo/redo command will undo/redo the whole global command at once.
The previous context mark will only be set once (with "''" you go back to
where the cursor was before the global command).

The global command sets both the last used search pattern and the last used
substitute pattern (this is vi compatible).  This makes it easy to globally
replace a string: >
	:g/pat/s//PAT/g
This replaces all occurrences of "pat" with "PAT".  The same can be done with: >
	:%s/pat/PAT/g
Which is two characters shorter!

When using "global" in Ex mode, a special case is using ":visual" as a
command.  This will move to a matching line, go to Normal mode to let you
execute commands there until you use |gQ| to return to Ex mode.  This will be
repeated for each matching line.  While doing this you cannot use ":global".
To abort this type CTRL-C twice.

==============================================================================
Complex repeats						*complex-repeat*

							*q* *recording* *macro*
q{0-9a-zA-Z"}		Record typed characters into register {0-9a-zA-Z"}
			(uppercase to append).  The 'q' command is disabled
			while executing a register, and it doesn't work inside
			a mapping and |:normal|.

			Note: If the register being used for recording is also
			used for |y| and |p| the result is most likely not
			what is expected, because the put will paste the
			recorded macro and the yank will overwrite the
			recorded macro.

			Note: The recording happens while you type, replaying
			the register happens as if the keys come from a
			mapping.  This matters, for example, for undo, which
			only syncs when commands were typed.

q			Stops recording.
			Implementation note: The 'q' that stops recording is
			not stored in the register, unless it was the result
			of a mapping

							*@*
@{0-9a-z".=*+}		Execute the contents of register {0-9a-z".=*+} [count]
			times.  Note that register '%' (name of the current
			file) and '#' (name of the alternate file) cannot be
			used.
			The register is executed like a mapping, that means
			that the difference between 'wildchar' and 'wildcharm'
			applies, and undo might not be synced in the same way.
			For "@=" you are prompted to enter an expression.  The
			result of the expression is then executed.
			See also |@:|.

							*@@* *E748*
@@			Repeat the previous @{0-9a-z":*} [count] times.

							*v_@-default*
{Visual}@{0-9a-z".=*+}	In linewise Visual mode, execute the contents of the
{Visual}@@		register for each selected line.
			See |visual-repeat|, |default-mappings|.

							*Q*
Q			Repeat the last recorded register [count] times.
			See |reg_recorded()|.

							*v_Q-default*
{Visual}Q		In linewise Visual mode, repeat the last recorded
			register for each selected line.
			See |visual-repeat|, |default-mappings|.

							*:@*
:[addr]@{0-9a-z".=*+}	Execute the contents of register {0-9a-z".=*+} as an Ex
			command.  First set cursor at line [addr] (default is
			current line).  When the last line in the register does
			not have a <CR> it will be added automatically when
			the 'e' flag is present in 'cpoptions'.
			For ":@=" the last used expression is used.  The
			result of evaluating the expression is executed as an
			Ex command.
			Mappings are not recognized in these commands.
			When the |line-continuation| character (\) is present
			at the beginning of a line in a linewise register,
			then it is combined with the previous line. This is
			useful for yanking and executing parts

Title: Complex Repeats and Macros in Vim
Summary
This section delves into complex repeating commands using the ':global' command with ':visual' in Ex mode, and recording and executing macros using registers. It details how to record keystrokes into registers, execute register contents as Normal mode commands or Ex commands, and repeat the last recorded register. It also explains the behavior of global commands with ':visual', and notes on using line continuations in linewise registers.