*usr_07.txt* Nvim
VIM USER MANUAL - by Bram Moolenaar
Editing more than one file
No matter how many files you have, you can edit them without leaving Vim.
Define a list of files to work on and jump from one to the other. Copy text
from one file and put it in another one.
|07.1| Edit another file
|07.2| A list of files
|07.3| Jumping from file to file
|07.4| Backup files
|07.5| Copy text between files
|07.6| Viewing a file
|07.7| Changing the file name
Next chapter: |usr_08.txt| Splitting windows
Previous chapter: |usr_06.txt| Using syntax highlighting
Table of contents: |usr_toc.txt|
==============================================================================
*07.1* Edit another file
So far you had to start Vim for every file you wanted to edit. There is a
simpler way. To start editing another file, use this command: >
:edit foo.txt
You can use any file name instead of "foo.txt". Vim will close the current
file and open the new one. If the current file has unsaved changes, however,
Vim displays an error message and does not open the new file:
E37: No write since last change (use ! to override) ~
Note:
Vim puts an error ID at the start of each error message. If you do
not understand the message or what caused it, look in the help system
for this ID. In this case: >
:help E37
At this point, you have a number of alternatives. You can write the file
using this command: >
:write
Or you can force Vim to discard your changes and edit the new file, using the
force (!) character: >
:edit! foo.txt
If you want to edit another file, but not write the changes in the current
file yet, you can make it hidden: >
:hide edit foo.txt
The text with changes is still there, but you can't see it. This is further
explained in section |22.4|: The buffer list.
==============================================================================
*07.2* A list of files
You can start Vim to edit a sequence of files. For example: >
vim one.c two.c three.c
This command starts Vim and tells it that you will be editing three files.
Vim displays just the first file. After you have done your thing in this
file, to edit the next file you use this command: >
:next
If you have unsaved changes in the current file, you will get an error
message and the ":next" will not work. This is the same problem as with
":edit" mentioned in the previous section. To abandon the changes: >
:next!
But mostly you want to save the changes and move on to the next file. There
is a special command for this: >
:wnext
This does the same as using two separate commands: >
:write
:next
WHERE AM I?
To see which file in the argument list you are editing, look in the window
title. It should show something like "(2 of 3)". This means you are editing
the second file out of three files.
If you want to see the list of files, use this command: >
:args
This is short for "arguments". The output might look like this:
one.c [two.c] three.c ~
These are the files you started Vim with. The one you are currently editing,
"two.c", is in square brackets.
MOVING TO OTHER ARGUMENTS
To go back one file: >
:previous
This is just like the ":next" command, except that it moves in the other
direction. Again, there is a shortcut command for when you want to write the
file first: >
:wprevious
To move to the very last file in the list: >
:last
And to move back to the first one again: >
:first
There is no ":wlast" or ":wfirst" command though!
You can use a count for ":next" and ":previous". To skip two files forward: >
:2next
AUTOMATIC WRITING
When moving around the files and making changes, you have to remember to use
":write". Otherwise you will get an error message. If you are sure you
always want to write modified files, you can tell Vim to automatically write
them: >
:set autowrite
When you are editing a file which you may not want to write, switch it off
again: >
:set noautowrite
EDITING ANOTHER