Home Explore Blog CI



neovim

6th chunk of `runtime/doc/repeat.txt`
cac8dfe2e9bdae64c21a20351a70f69a645fe941b6f88ae10000000100000fa1
 appending to the register (use an
  uppercase letter).
- Delete or yank the command sequence into the register.

Often used command sequences can be put under a function key with the ':map'
command.

An alternative is to put the commands in a file, and execute them with the
':source!' command.  Useful for long command sequences.  Can be combined with
the ':map' command to put complicated commands under a function key.

The ':source' command reads Ex commands from a file or a buffer line by line.
You will have to type any needed keyboard input.  The ':source!' command reads
from a script file character by character, interpreting each character as if
you typed it.

Example: When you give the ":!ls" command you get the |hit-enter| prompt.  If
you ':source' a file with the line "!ls" in it, you will have to type the
<Enter> yourself.  But if you ':source!' a file with the line ":!ls" in it,
the next characters from that file are read until a <CR> is found.  You will
not have to type <CR> yourself, unless ":!ls" was the last line in the file.

It is possible to put ':source[!]' commands in the script file, so you can
make a top-down hierarchy of script files.  The ':source' command can be
nested as deep as the number of files that can be opened at one time (about
15).  The ':source!' command can be nested up to 15 levels deep.

You can use the "<sfile>" string (literally, this is not a special key) inside
of the sourced file, in places where a file name is expected.  It will be
replaced by the file name of the sourced file.  For example, if you have a
"other.vimrc" file in the same directory as your |init.vim| file, you can
source it from your |init.vim| file with this command: >
	:source <sfile>:h/other.vimrc

In script files terminal-dependent key codes are represented by
terminal-independent two character codes.  This means that they can be used
in the same way on different kinds of terminals.  The first character of a
key code is 0x80 or 128, shown on the screen as "~@".  The second one can be
found in the list |key-notation|.  Any of these codes can also be entered
with CTRL-V followed by the three digit decimal code.

							*:source_crnl* *W15*
Windows: Files that are read with ":source" normally have <CR><NL> <EOL>s.
These always work.  If you are using a file with <NL> <EOL>s (for example, a
file made on Unix), this will be recognized if 'fileformats' is not empty and
the first line does not end in a <CR>.  This fails if the first line has
something like ":map <F1> :help^M", where "^M" is a <CR>.  If the first line
ends in a <CR>, but following ones don't, you will get an error message,
because the <CR> from the first lines will be lost.

On other systems, Vim expects ":source"ed files to end in a <NL>.  These
always work.  If you are using a file with <CR><NL> <EOL>s (for example, a
file made on MS-Windows), all lines will have a trailing <CR>.  This may cause
problems for some commands (e.g., mappings).  There is no automatic <EOL>
detection, because it's common to start with a line that defines a mapping
that ends in a <CR>, which will confuse the automaton.

							*line-continuation*
Long lines in a ":source"d Ex command script file can be split by inserting
a line continuation symbol "\" (backslash) at the start of the next line.
There can be white space before the backslash, which is ignored.

Example: the lines >
	:set comments=sr:/*,mb:*,el:*/,
		     \://,
		     \b:#,
		     \:%,
		     \n:>,
		     \fb:-
are interpreted as if they were given in one line: >
	:set comments=sr:/*,mb:*,el:*/,://,b:#,:%,n:>,fb:-

All leading whitespace characters in the line before a backslash are ignored.
Note however that trailing whitespace in the line before it cannot be
inserted freely; it depends on the position where a command is split up
whether additional whitespace is allowed or not.

When a space is required it's best to put it right after the backslash.  A
space at the end of a line is hard to see and may be accidentally

Title: :source and Command Repetition Continued, <sfile> Usage, Windows vs Unix EOL, and Line Continuation
Summary
This section expands on using ':source' and ':source!', emphasizing the character-by-character interpretation of ':source!' and nesting capabilities. It introduces the '<sfile>' string for referencing the sourced file's name and explains how Vim handles different end-of-line characters (EOL) in Windows and Unix systems. Finally, it details how to use line continuation '\' for long lines in sourced files.