Home Explore Blog CI



neovim

13th chunk of `runtime/doc/editing.txt`
c65efe62050852ce3a98184eccb5d82990b0ac7e1786b6200000000100000fa9
	{cmd} must not change the argument list.
			Note: While this command is executing, the Syntax
			autocommand event is disabled by adding it to
			'eventignore'.  This considerably speeds up editing
			each file.
			Also see |:windo|, |:tabdo|, |:bufdo|, |:cdo|, |:ldo|,
			|:cfdo| and |:lfdo|.

Example: >
	:args *.c
	:argdo set ff=unix | update
This sets the 'fileformat' option to "unix" and writes the file if it is now
changed.  This is done for all `*.c` files.

Example: >
	:args *.[ch]
	:argdo %s/\<my_foo\>/My_Foo/ge | update
This changes the word "my_foo" to "My_Foo" in all "*.c" and "*.h" files.  The "e"
flag is used for the ":substitute" command to avoid an error for files where
"my_foo" isn't used.  ":update" writes the file only if changes were made.

==============================================================================
4. Writing					*writing* *save-file*

Note: When the 'write' option is off, you are not able to write any file.

							*:w* *:write*
					*E502* *E503* *E504* *E505*
					*E512* *E514* *E667* *E949*
:w[rite] [++opt]	Write the whole buffer to the current file.  This is
			the normal way to save changes to a file.  Fails when
			'readonly' is set or when there is another reason why
			the file can't be written, such as when the parent
			directory doesn't exist (use |++p| to avoid that).
			For ++opt see |++opt|, but only ++p, ++bin, ++nobin,
			++ff and ++enc are effective.


:w[rite]! [++opt]	Like ":write", but forcefully write when 'readonly' is
			set or there is another reason why writing was
			refused.
			Note: This may change the permission and ownership of
			the file and break (symbolic) links.  Add the 'W' flag
			to 'cpoptions' to avoid this.

:[range]w[rite][!] [++opt]
			Write the specified lines to the current file.  This
			is unusual, because the file will not contain all
			lines in the buffer.

							*:w_f* *:write_f*
:[range]w[rite] [++opt]	{file}
			Write the specified lines to {file}, unless it
			already exists and the 'writeany' option is off.

							*:w!*
:[range]w[rite]! [++opt] {file}
			Write the specified lines to {file}.  Overwrite an
			existing file.

						*:w_a* *:write_a* *E494*
:[range]w[rite][!] [++opt] >>
			Append the specified lines to the current file.

:[range]w[rite][!] [++opt] >> {file}
			Append the specified lines to {file}.  '!' forces the
			write even if file does not exist.

							*:w_c* *:write_c*
:[range]w[rite] [++opt] !{cmd}
			Execute {cmd} with [range] lines as standard input
			(note the space in front of the '!').  {cmd} is
			executed like with ":!{cmd}", any '!' is replaced with
			the previous command |:!|.

The default [range] for the ":w" command is the whole buffer (1,$).  The |'[|
and |']| marks will be set to the [range] being used for the write command.
If you write the whole buffer, it is no longer considered changed.  When you
write it to a different file with ":w somefile" it depends on the "+" flag in
'cpoptions'.  When included, the write command will reset the 'modified' flag,
even though the buffer itself may still be different from its file.

If a file name is given with ":w" it becomes the alternate file.  This can be
used, for example, when the write fails and you want to try again later with
":w #".  This can be switched off by removing the 'A' flag from the
'cpoptions' option.

Note that the 'fsync' option matters here.  If it's set it may make writes
slower (but safer).

							*:sav* *:saveas*
:sav[eas][!] [++opt] {file}
			Save the current buffer under the name {file} and set
			the filename of the current buffer to {file}.  The
			previous name is used for the alternate file name.
			The [!] is needed to overwrite an existing file.
			When 'filetype' is empty filetype detection is done
			with the new name, before the file is written.
			When the write was successful 'readonly' is reset.

							*:up* *:update*
:[range]up[date][!] [++opt] [>>] [file]
			Like ":write", but only write when the buffer has been
			modified.

Title: Writing Files in Vim: Commands and Options
Summary
This section details the writing commands in Vim, focusing on `:w` (write), `:sav[eas]`, and `:up[date]`. It explains the different options available with the `:w` command, such as writing to a specific file, appending to a file, and executing a command with the buffer content as input. It covers the use of `!` to force overwrites and the implications of the 'readonly' and 'writeany' options. The `:saveas` command is discussed for saving the current buffer under a new name, and the `:update` command for writing only when the buffer has been modified.