*editing.txt* For Vim version 7.0aa. Last change: 2004 Aug 29
VIM REFERENCE MANUAL by Bram Moolenaar
Editing files *edit-files*
1. Introduction |edit-intro|
2. Editing a file |edit-a-file|
3. Dialogs |edit-dialogs|
4. The current directory |current-directory|
5. The argument list |argument-list|
6. Writing |writing|
7. Writing and quitting |write-quit|
8. Editing binary files |edit-binary|
9. Encryption |encryption|
10. Timestamps |timestamps|
==============================================================================
1. Introduction *edit-intro*
Editing a file with Vim means:
1. reading the file into the internal buffer
2. changing the buffer with editor commands
3. writing the buffer into a file
*current-file*
As long as you don't write the buffer, the original file remains unchanged.
If you start editing a file (read a file into the buffer), the file name is
remembered as the "current file name". This is also known as the name of the
current buffer.
*alternate-file*
If there already was a current file name, then that one becomes the alternate
file name. It can later be used with "#" on the command line |:_#|. However,
the alternate file name is not changed when |:keepalt| is used.
*:keepalt* *:keepa*
:keepalt {cmd} Execute {cmd} while keeping the current alternate file
name. Note that commands invoked indirectly (e.g.,
with a function) may still set the alternate file
name. {not in Vi}
All file names are remembered in the file list. When you enter a file name,
for editing (e.g., with ":e filename") or writing (e.g., with (:w file name"),
the file name is added to the list. You can use this list to remember which
files you edited and to quickly switch from one file to another with the
CTRL-^ command (e.g., to copy text). First type the number of the file and
then hit CTRL-^. {Vi: only one alternate file name}
CTRL-G or *CTRL-G* *:f* *:fi* *:file*
:f[ile] Prints the current file name (as typed), the
cursor position (unless the 'ruler' option is set),
and the file status (readonly, modified, read errors,
new file)). See the 'shortmess' option about how tho
make this message shorter. {Vi does not include
column number}
:f[ile]! like |:file|, but don't truncate the name even when
'shortmess' indicates this.
{count}CTRL-G Like CTRL-G, but prints the current file name with
full path. If the count is higher than 1 the current
buffer number is also given. {not in Vi}
*g_CTRL-G* *word-count* *byte-count*
g CTRL-G Prints the current position of the cursor in four
ways: Column, Line, Word and Byte. If there are
characters in the line that take more than one
position on the screen (<Tab> or special character),
both the "real" column and the screen column are
shown, separated with a dash. See also 'ruler'
option. {not in Vi}
*v_g_CTRL-G*
{Visual}g CTRL-G Similar to "g CTRL-G", but Word, Line, and Byte counts
for the visually selected region are displayed. In
Blockwise mode, Column count is also shown. (For
{Visual} see |Visual-mode|.)
{not in VI}
*:file_f*
:f[ile][!] {name} Sets the current file name to {name}. The optional !
avoids truncating the message, as with |:file|.
:0f[ile][!] Remove the name of the current buffer. The optional !
avoids truncating the message, as with |:file|. {not
in Vi}
:buffers
:files
:ls List all the currently known file names. See
'windows.txt' |:files| |:buffers| |:ls|. {not in
Vi}
Vim will remember the full path name of a file name that you enter. In most
cases when the file name is displayed only the name you typed is shown, but
the full path name is being used if you used the ":cd" command |:cd|.
*home-replace*
If the environment variable $HOME is set, and the file name starts with that
string, it is often displayed with HOME replaced with "~". This was done to
keep file names short. When reading or writing files the full name is still
used, the "~" is only used when displaying file names. When replacing the
file name would result in just "~", "~/" is used instead (to avoid confusion
with 'backupext' set to "~").
When writing the buffer, the default is to use the current file name. Thus
when you give the "ZZ" or ":wq" command, the original file will be
overwritten. If you do not want this, the buffer can be written into another
file by giving a file name argument to the ":write" command. For example: >
vim testfile
[change the buffer with editor commands]
:w newfile
:q
This will create a file "newfile", that is a modified copy of "testfile".
The file "testfile" will remain unchanged. Anyway, if the 'backup' option is
set, Vim renames or copies the original file before it will be overwritten.
You can use this file if you discover that you need the original file. See
also the 'patchmode' option. The name of the backup file is normally the same
as the original file with 'backupext' appended. The default "~" is a bit
strange to avoid accidentally overwriting existing files. If you prefer ".bak"
change the 'backupext' option. Extra dots are replaced with '_' on MS-DOS
machines, when Vim has detected that an MS-DOS-like filesystem is being used
(e.g., messydos or crossdos) or when the 'shortname' option is on. The
backup file can be placed in another directory by setting 'backupdir'.
*auto-shortname*
Technical: On the Amiga you can use 30 characters for a file name. But on an
MS-DOS-compatible filesystem only 8 plus 3 characters are
available. Vim tries to detect the type of filesystem when it is
creating the .swp file. If an MS-DOS-like filesystem is suspected,
a flag is set that has the same effect as setting the 'shortname'
option. This flag will be reset as soon as you start editing a
new file. The flag will be used when making the file name for the
".swp" and ".~" files for the current file. But when you are
editing a file in a normal filesystem and write to an