Home Explore Blog CI



neovim

29th chunk of `runtime/doc/insert.txt`
5dc33cc3e03f6363da077fab0e2ea76c5f04bb0f452534bc000000010000082c
 cursor.
			See |++opt| for the possible values of [++opt].

:{range}r[ead] [++opt] [name]
			Insert the file [name] (default: current file) below
			the specified line.
			See |++opt| for the possible values of [++opt].

							*:r!* *:read!*
:[range]r[ead] [++opt] !{cmd}
			Execute {cmd} and insert its standard output below
			the cursor or the specified line.  A temporary file is
			used to store the output of the command which is then
			read into the buffer.  'shellredir' is used to save
			the output of the command, which can be set to include
			stderr or not.  {cmd} is executed like with ":!{cmd}",
			any '!' is replaced with the previous command |:!|.
			See |++opt| for the possible values of [++opt].

These commands insert the contents of a file, or the output of a command,
into the buffer.  They can be undone.  They cannot be repeated with the "."
command.  They work on a line basis, insertion starts below the line in which
the cursor is, or below the specified line.  To insert text above the first
line use the command ":0r {name}".

After the ":read" command, the cursor is left on the first non-blank in the
first new line.  If in Ex mode, then the cursor is left on the last new
line (sorry, this is Vi compatible).

If a file name is given with ":r", it becomes the alternate file.  This can be
used, for example, when you want to edit that file instead: ":e! #".  This can
be switched off by removing the 'a' flag from the 'cpoptions' option.

Of the [++opt] arguments one is specifically for ":read", the ++edit argument.
This is useful when the ":read" command is actually used to read a file into
the buffer as if editing that file.  Use this command in an empty buffer: >
	:read ++edit filename
The effect is that the 'fileformat', 'fileencoding', 'bomb', etc. options are
set to what has been detected for "filename".  Note that a single empty line
remains, you may want to delete it.

							*file-read*
The 'fileformat' option sets the <EOL> style for a file:
'fileformat'    characters	   name				~
  "dos"		<CR><NL> or <NL>   DOS format
  "unix"	<NL>	

Title: Details of the ':read' Command for File Insertion
Summary
This section provides details on the ':read' command, which is used to insert the content of a file or the output of a command into the current buffer. It explains how to specify a file, execute a command and insert its output, and how the cursor position is affected after the operation. It also discusses how the ':read' command interacts with the alternate file and the 'cpoptions' setting. It covers the '++edit' option, which allows treating the read file as if it were being edited, and explains how the 'fileformat' option influences the End-of-Line (EOL) style of the inserted file.