->Title Page
->Intro
->Unix
->Vi editor
-->Basics
-->Vi reference
--->Move commands
--->Search
--->Undo
--->Insert
--->Delete
--->Changing text
--->Substitution
--->Yanking
--->Insert mode
--->Display commands
->Files
--->Macros
--->Shell commands
--->Vi Startup
--->Important options
-->Miscellaneous tips
->Mirror sites
->Further reading

[ Up ]
[Prev][Home][Next]
[Author]

Vi ---> Writing, editing other files, and quitting vi

In ":" "ex" commands "%" denotes the current file, "#" is a synonym for the alternate file (which normally is the previous file). Marks can be used for line numbers too: '<a-z>. In the :w, :f, :cd, :e, and :n commands, shell meta-characters can be used.

                                    
    :q                      | Quit vi, unless the buffer has been changed.
    :q!                     | Quit vi without writing.
    ^Z                      | Suspend vi.
    :w                      | Write the file.
    :w <name>               | Write to the file <name>.
    :w >> <name>            | Append the buffer to the file <name>.
    :w! <name>              | Overwrite the file <name>.
    :x,y w <name>           | Write lines x through y to the file <name>.
    :wq                     | Write the file and quit vi; some versions quit
                            |   even if the write was unsuccessful!
                            |   Use `ZZ' instead.
    ZZ                      | Write if the buffer has been changed, and
                            |   quit vi.  If you have invoked vi with the `-r'
                            |   option, you'd better write the file
                            |   explicitly (`w' or `w!'), or quit the
                            |   editor explicitly (`q!') if you don't want
                            |   to overwrite the file - some versions of vi
                            |   don't handle the `recover' option very well.
    :x [<file>]             | Idem [but write to <file>].
    :x! [<file>]            | `:w![<file>]' and `:q'.
    :pre                    | Preserve the file - the buffer is saved as if
                            |   the system had just crashed; for emergencies,
                            |   when a `:w' command has failed and you don't
                            |   know how to save your work (see `vi -r').
    :f <name>               | Set the current filename to <name>.
    :cd [<dir>]             | Set the working directory to <dir>
                            |   (default home directory).
    :cd! [<dir>]            | Idem, but don't save changes.
    :e [+<cmd>] <file>      | Edit another file without quitting vi - the
                            |   buffers are not changed (except the undo
                            |   buffer), so text can be copied from one file to
                            |   another this way.  [Execute the `ex' command
                            |   <cmd> (default `$') when the new file has been
                            |   read into the buffer.]  <cmd> must contain no
                            |   <sp> or <ht>.  See `vi startup'.
    :e! [+<cmd>] <file>     | Idem, without writing the current buffer.
    ^^                      | Edit the alternate (normally the previous) file.
    :rew                    | Rewind the argument list, edit the first file.
    :rew!                   | Idem, without writing the current buffer.
    :n [+<cmd>] [<files>]   | Edit next file or specify a new argument list.
    :n! [+<cmd>] [<files>]  | Idem, without writing the current buffer.
    :args                   | Give the argument list, with the current file
                            |   between `[' and `]'.

Please notify owners of webpages with outdated links to these pages

This section is based on "Vi Reference" by Maarten Litmaath et al.

Find this site useful? Want to give something back?

© 1993-2001 Christopher C. Taylor