Home Explore Blog CI



neovim

7th chunk of `runtime/doc/editing.txt`
b47ac6160c37eb1bc3c00c4494adb7d78491b8d17b73ec580000000100000fa4
 fileformat   overrides 'fileformat'
    enc    or  encoding	    overrides 'fileencoding'
    bin    or  binary	    sets 'binary'
    nobin  or  nobinary	    resets 'binary'
    bad			    specifies behavior for bad characters
    edit		    for |:read|: keeps options as if editing a file
    p			    for |:write|: creates the file's parent directory

{value} cannot contain whitespace.  It can be any valid value for the options.
Examples: >
	:e ++ff=unix
This edits the same file again with 'fileformat' set to "unix". >

	:w ++enc=latin1 newfile
This writes the current buffer to "newfile" in latin1 format.

The message given when writing a file will show "[converted]" when
'fileencoding' or the value specified with ++enc differs from 'encoding'.

There may be several ++opt arguments, separated by whitespace.  They must all
appear before any |+cmd| argument.

								*++p*
The "++p" flag creates the parent directory of the file if it does not exist.
For example if you edit "foo/bar/file.txt", the ":write ++p" command creates
"foo/bar/" if necessary before writing the file. >

	:edit foo/bar/file.txt
	:write ++p

If you want :write (without "++p") to always create missing parent
directories, add this autocmd to your config: >

	" Auto-create parent directories (except for URIs "://").
	au BufWritePre,FileWritePre * if @% !~# '\(://\)' | call mkdir(expand('<afile>:p:h'), 'p') | endif
<

								*++bad*
The argument of "++bad=" specifies what happens with characters that can't be
converted and illegal bytes.  It can be one of three things:
    ++bad=X      A single-byte character that replaces each bad character.
    ++bad=keep   Keep bad characters without conversion.  Note that this may
		 result in illegal bytes in your text!
    ++bad=drop   Remove the bad characters.

The default is like "++bad=?": Replace each bad character with a question
mark.  In some places an inverted question mark is used (0xBF).

Note that not all commands use the ++bad argument, even though they do not
give an error when you add it.  E.g. |:write|.

Note that when reading, the 'fileformat' and 'fileencoding' options will be
set to the used format.  When writing this doesn't happen, thus a next write
will use the old value of the option.  Same for the 'binary' option.


							*+cmd* *[+cmd]*
The [+cmd] argument can be used to position the cursor in the newly opened
file, or execute any other command:
	+		Start at the last line.
	+{num}		Start at line {num}.
	+/{pat}		Start at first line containing {pat}.
	+{command}	Execute {command} after opening the new file.
			{command} is any Ex command.
To include a white space in the {pat} or {command}, precede it with a
backslash.  Double the number of backslashes. >
	:edit  +/The\ book	     file
	:edit  +/dir\ dirname\\      file
	:edit  +set\ dir=c:\\\\temp  file
Note that in the last example the number of backslashes is halved twice: Once
for the "+cmd" argument and once for the ":set" command.

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

When reading a file, the mentioned characters are interpreted as the <EOL>.
In DOS format (default for Windows), <CR><NL> and <NL> are both interpreted as
the <EOL>. Note that when writing the file in DOS format, <CR> characters will
be added for each single <NL>.  Also see |file-read|.

When writing a file, the mentioned characters are used for <EOL>.  For DOS
format <CR><NL> is used.  Also see |DOS-format-write|.

You can read a file in DOS format and write it in Unix format.  This will
replace all <CR><NL> pairs by <NL> (assuming 'fileformats' includes "dos"): >
	:e file
	:set fileformat=unix
	:w
If you read a file in Unix format and write with DOS format, all <NL>
characters will be replaced with <CR><NL> (assuming 'fileformats' includes
"unix"): >
	:e file
	:set

Title: Detailed Explanation of ++opt, ++bad, +cmd, and File Formats in Vim
Summary
This passage provides a comprehensive explanation of several advanced Vim features. It elaborates on the usage of '++opt' arguments for overriding file options like 'fileformat' and 'fileencoding', including how to handle bad characters with '++bad'. It details the '+cmd' argument for positioning the cursor or executing commands upon file opening. Finally, it describes the 'fileformat' option and its impact on end-of-line (EOL) characters for different operating systems (DOS, Unix, Mac), offering examples of how to convert between these formats.