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 LIST OF FILES
You can redefine the list of files without the need to exit Vim and start it
again. Use this command to edit three other files: >
:args five.c six.c seven.h
Or use a wildcard, like it's used in the shell: >
:args *.txt
Vim will take you to the first file in the list. Again, if the current file
has changes, you can either write the file first, or use ":args!" (with !
added) to abandon the changes.
DID YOU EDIT THE LAST FILE?
*arglist-quit*
When you use a list of files, Vim assumes you want to edit them all. To
protect you from exiting too early, you will get this error when you didn't
edit the last file in the list yet:
E173: 46 more files to edit ~
If you really want to exit, just do it again. Then it will work (but not when
you did other commands in between).
==============================================================================
*07.3* Jumping from file to file
To quickly jump between two files, press CTRL-^ (on English-US keyboards the ^
is above the 6 key). Example: >
:args one.c two.c three.c
You are now in one.c. >
:next
Now you are in two.c. Now use CTRL-^ to go back to one.c. Another CTRL-^ and
you are back in two.c. Another CTRL-^ and you are in one.c again. If you now
do: >
:next
You are in three.c. Notice that the CTRL-^ command does not change the idea
of where you are in the list of files. Only commands like ":next" and
":previous" do that.
The file you were previously editing is called the "alternate" file. When you
just started Vim CTRL-^ will not work, since there isn't a previous file.
PREDEFINED MARKS
After jumping to another file, you can use two predefined marks which are very
useful: >
`"
This takes you to the position where the cursor was when you left the file.
Another mark that is remembered is the position where you made the last
change: >
`.
Suppose you are editing the file "one.txt". Somewhere halfway through the
file you use "x" to delete a character. Then you go to the last line with "G"
and write the file with ":w". You edit several other files, and then use
":edit one.txt" to come back to "one.txt". If you now use `" Vim jumps to the
last line of the file. Using `. takes you to the position where you deleted
the character. Even when you move around in the file `" and `. will take you
to the remembered position. At least until you make another change or leave
the file.
FILE MARKS
In section |03.10| was explained how you can place a mark in a file with "mx"
and jump to that position with "`x". That works within one file. If you edit
another file and place marks there, these are specific for that file. Thus
each file has its own set of marks, they are local to the file.
So far we were using marks with a lowercase letter. There are also marks
with an uppercase letter. These are global, they can be used from any file.
For example suppose that we are editing the file "foo.txt". Go to halfway
down the file ("50%") and place the