Lines Matching refs:file
5 Editing more than one file
10 from one file and put it in another one.
12 |07.1| Edit another file
14 |07.3| Jumping from file to file
17 |07.6| Viewing a file
18 |07.7| Changing the file name
25 *07.1* Edit another file
27 So far you had to start Vim for every file you wanted to edit. There is a
28 simpler way. To start editing another file, use this command: >
32 You can use any file name instead of "foo.txt". Vim will close the current
33 file and open the new one. If the current file has unsaved changes, however,
34 Vim displays an error message and does not open the new file:
45 At this point, you have a number of alternatives. You can write the file
50 Or you can force Vim to discard your changes and edit the new file, using the
55 If you want to edit another file, but not write the changes in the current
56 file yet, you can make it hidden: >
71 Vim displays just the first file. After you have done your thing in this
72 file, to edit the next file you use this command: >
76 If you have unsaved changes in the current file, you will get an error
82 But mostly you want to save the changes and move on to the next file. There
95 To see which file in the argument list you are editing, look in the window
97 the second file out of three files.
112 To go back one file: >
118 file first: >
122 To move to the very last file in the list: >
146 When you are editing a file which you may not want to write, switch it off
163 Vim will take you to the first file in the list. Again, if the current file
164 has changes, you can either write the file first, or use ":args!" (with !
172 edit the last file in the list yet:
180 *07.3* Jumping from file to file
201 The file you were previously editing is called the "alternate" file. When you
202 just started Vim CTRL-^ will not work, since there isn't a previous file.
207 After jumping to another file, you can use two predefined marks which are very
212 This takes you to the position where the cursor was when you left the file.
218 Suppose you are editing the file "one.txt". Somewhere halfway through the
219 file you use "x" to delete a character. Then you go to the last line with "G"
220 and write the file with ":w". You edit several other files, and then use
222 last line of the file. Using `. takes you to the position where you deleted
223 the character. Even when you move around in the file `" and `. will take you
225 the file.
230 In section |03.10| was explained how you can place a mark in a file with "mx"
231 and jump to that position with "`x". That works within one file. If you edit
232 another file and place marks there, these are specific for that file. Thus
233 each file has its own set of marks, they are local to the file.
235 with an uppercase letter. These are global, they can be used from any file.
236 For example suppose that we are editing the file "foo.txt". Go to halfway
237 down the file ("50%") and place the F mark there (F for foo): >
241 Now edit the file "bar.txt" and place the B mark (B for bar) at its last line:
246 another file, type "'B" and you are at the end of bar.txt again.
248 The file marks are remembered until they are placed somewhere else. Thus you
252 and where it is placed. For example, use the H mark in a header file, M in
253 a Makefile and C in a C code file.
269 Usually Vim does not produce a backup file. If you want to have one, all you
274 The name of the backup file is the original file with a ~ added to the end.
275 If your file is named data.txt, for example, the backup file name is
284 backup file is written. The default, to write the backup in the same
285 directory as the original file, will mostly be the right thing.
289 still create a backup file. However, it is deleted as soon as writing
290 the file was completed successfully. This functions as a safety
291 against losing your original file when writing fails in some way (disk
298 If you are editing source files, you might want to keep the file before you
299 make any changes. But the backup file will be overwritten each time you write
300 the file. Thus it only contains the previous version, not the first one.
301 To make Vim keep the original file, set the 'patchmode' option. This
302 specifies the extension used for the first backup of a changed file. Usually
307 When you now edit the file data.txt for the first time, make changes and write
308 the file, Vim will keep a copy of the unchanged file under the name
310 If you make further changes to the file, Vim will notice that
313 If you leave 'patchmode' empty (that is the default), the original file
319 This explains how to copy text from one file to another. Let's start with a
320 simple example. Edit the file that contains the text you want to copy. Move
330 Now edit the file you want to put the text in. Move the cursor to the
348 When you want to copy several pieces of text from one file to another, having
349 to switch between the files and writing the target file takes a lot of time.
373 another file, move around and place the text where you want it: >
393 When collecting lines of text into one file, you can use this command: >
397 This will write the text of the current file to the end of "logfile". Thus it
398 is appended. This avoids that you have to copy the lines, edit the log file
400 end of a file.
405 *07.6* Viewing a file
407 Sometimes you only want to see what a file contains, without the intention to
409 overwrite the original file anyway. To avoid this, edit the file read-only.
412 vim -R file
416 view file
418 You are now editing "file" in read-only mode. When you try using ":w" you
419 will get an error message and the file won't be written.
420 When you try to make a change to the file Vim will give you a warning:
422 W10: Warning: Changing a readonly file ~
424 The change will be done though. This allows for formatting the file, for
426 If you make changes to a file and forgot that it was read-only, you can
429 If you really want to forbid making changes in a file, do this: >
431 vim -M file
445 *07.7* Changing the file name
447 A clever way to start editing a new file is by using an existing file that
449 to move a file. You know that you already have a program that copies a file,
454 You can delete the stuff you don't need. Now you need to save the file under
459 Vim will write the file under the given name, and edit that file. Thus the
462 When you want to change the name of the file you are editing, but don't
463 want to write the file, you can use this command: >
465 :file move.c
467 Vim will mark the file as "not edited". This means that Vim knows this is not
468 the file you started editing. When you try to write the file, you might get
473 This protects you from accidentally overwriting another file.