*usr_23.txt* Nvim
VIM USER MANUAL - by Bram Moolenaar
Editing other files
This chapter is about editing files that are not ordinary files. With Vim you
can edit files that are compressed. Some files need to be accessed over the
internet. With some restrictions, binary files can be edited as well.
|23.1| DOS, Mac and Unix files
|23.2| Files on the internet
|23.3| Binary files
|23.4| Compressed files
Next chapter: |usr_24.txt| Inserting quickly
Previous chapter: |usr_22.txt| Finding the file to edit
Table of contents: |usr_toc.txt|
==============================================================================
*23.1* DOS, Mac and Unix files
Back in the early days, the old Teletype machines used two characters to
start a new line. One to move the carriage back to the first position
(carriage return, <CR>), another to move the paper up (line feed, <LF>).
When computers came out, storage was expensive. Some people decided that
they did not need two characters for end-of-line. The Unix people decided
they could use <New Line> or <NL> only for end-of-line. The Apple people
standardized on <CR>. The Microsoft Windows folks decided to keep the old
<CR><NL> (we use <NL> for line feed in the help text).
This means that if you try to move a file from one system to another, you
have line-break problems. The Vim editor automatically recognizes the
different file formats and handles things properly behind your back.
The option 'fileformats' contains the various formats that will be tried
when a new file is edited. The following command, for example, tells Vim to
try Unix format first and MS-DOS format second: >
:set fileformats=unix,dos
You will notice the format in the message you get when editing a file. You
don't see anything if you edit a native file format. Thus editing a Unix file
on Unix won't result in a remark. But when you edit a dos file, Vim will
notify you of this:
"/tmp/test" [dos] 3L, 71C ~
For a Mac file you would see "[mac]".
The detected file format is stored in the 'fileformat' option. To see
which format you have, execute the following command: >
:set fileformat?
The three names that Vim uses are:
unix <NL>
dos <CR><NL>
mac <CR>
USING THE MAC FORMAT
On Unix, <NL> is used to break a line. It's not unusual to have a <CR>
character halfway in a line. Incidentally, this happens quite often in Vi
(and Vim) scripts.
On the Macintosh, where <CR> is the line break character, it's possible to
have a <NL> character halfway in a line.
The result is that it's not possible to be 100% sure whether a file
containing both <CR> and <NL> characters is a Mac or a Unix file. Therefore,
Vim assumes that on Unix you probably won't edit a Mac file, and doesn't check
for this type of file. To check for this format anyway, add "mac" to
'fileformats': >
:set fileformats+=mac
Then Vim will take a guess at the file format. Watch out for situations where
Vim guesses wrong.
OVERRULING THE FORMAT
If you use the good old Vi and try to edit an MS-DOS format file, you will
find that each line ends with a ^M character. (^M is <CR>). The automatic
detection avoids this. Suppose you do want to edit the file that way? Then
you need to overrule the format: >
:edit ++ff=unix file.txt
The "++" string is an item that tells Vim that an option name follows, which
overrules the default for this single command. "++ff" is used for
'fileformat'. You could also use "++ff=mac" or "++ff=dos".
This doesn't work for any option, only "++ff" and "++enc" are currently
implemented. The full names "++fileformat" and "++encoding" also work.
CONVERSION
You can use the 'fileformat' option to convert from one file format to
another. Suppose, for example, that you have an MS-DOS file named README.TXT
that you want to convert to Unix format. Start by editing the MS-DOS format
file: >
vim README.TXT
Vim will recognize this as a dos format file. Now change the file format to
Unix: