annotate runtime/doc/usr_07.txt @ 11763:21f3930dfe6e

Documentation updates. commit https://github.com/vim/vim/commit/b6e0ec6b71c45284d94f51728dbc33e5d3428ff4 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 23 22:12:20 2017 +0200 Documentation updates.
author Christian Brabandt <cb@256bit.org>
date Sun, 23 Jul 2017 22:15:06 +0200
parents 9f48eab77d62
children 444ad56c0cac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10198
9f48eab77d62 commit https://github.com/vim/vim/commit/bb76f24af2010943387ce696a7092175b4ecccf2
Christian Brabandt <cb@256bit.org>
parents: 5294
diff changeset
1 *usr_07.txt* For Vim version 8.0. Last change: 2006 Apr 24
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 VIM USER MANUAL - by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 Editing more than one file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 No matter how many files you have, you can edit them without leaving Vim.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 Define a list of files to work on and jump from one to the other. Copy text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 from one file and put it in another one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 |07.1| Edit another file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 |07.2| A list of files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |07.3| Jumping from file to file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 |07.4| Backup files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 |07.5| Copy text between files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 |07.6| Viewing a file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 |07.7| Changing the file name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 Next chapter: |usr_08.txt| Splitting windows
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 Previous chapter: |usr_06.txt| Using syntax highlighting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 Table of contents: |usr_toc.txt|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 *07.1* Edit another file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 So far you had to start Vim for every file you wanted to edit. There is a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 simpler way. To start editing another file, use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 :edit foo.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 You can use any file name instead of "foo.txt". Vim will close the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 file and open the new one. If the current file has unsaved changes, however,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 Vim displays an error message and does not open the new file:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 E37: No write since last change (use ! to override) ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 Vim puts an error ID at the start of each error message. If you do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 not understand the message or what caused it, look in the help system
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 for this ID. In this case: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 :help E37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 At this point, you have a number of alternatives. You can write the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 using this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 :write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 Or you can force Vim to discard your changes and edit the new file, using the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 force (!) character: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 :edit! foo.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 If you want to edit another file, but not write the changes in the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 file yet, you can make it hidden: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 :hide edit foo.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 The text with changes is still there, but you can't see it. This is further
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 explained in section |22.4|: The buffer list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 *07.2* A list of files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 You can start Vim to edit a sequence of files. For example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 vim one.c two.c three.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 This command starts Vim and tells it that you will be editing three files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 Vim displays just the first file. After you have done your thing in this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 file, to edit the next file you use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 :next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 If you have unsaved changes in the current file, you will get an error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 message and the ":next" will not work. This is the same problem as with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 ":edit" mentioned in the previous section. To abandon the changes: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 :next!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 But mostly you want to save the changes and move on to the next file. There
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 is a special command for this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 :wnext
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 This does the same as using two separate commands: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 :write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 :next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 WHERE AM I?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 To see which file in the argument list you are editing, look in the window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 title. It should show something like "(2 of 3)". This means you are editing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 the second file out of three files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 If you want to see the list of files, use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 :args
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 This is short for "arguments". The output might look like this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 one.c [two.c] three.c ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 These are the files you started Vim with. The one you are currently editing,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 "two.c", is in square brackets.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 MOVING TO OTHER ARGUMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 To go back one file: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 :previous
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 This is just like the ":next" command, except that it moves in the other
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 direction. Again, there is a shortcut command for when you want to write the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 file first: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 :wprevious
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 To move to the very last file in the list: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 :last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 And to move back to the first one again: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 :first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 There is no ":wlast" or ":wfirst" command though!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 You can use a count for ":next" and ":previous". To skip two files forward: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 :2next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 AUTOMATIC WRITING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 When moving around the files and making changes, you have to remember to use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 ":write". Otherwise you will get an error message. If you are sure you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 always want to write modified files, you can tell Vim to automatically write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 them: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 :set autowrite
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 When you are editing a file which you may not want to write, switch it off
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 again: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 :set noautowrite
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 EDITING ANOTHER LIST OF FILES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 You can redefine the list of files without the need to exit Vim and start it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 again. Use this command to edit three other files: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 :args five.c six.c seven.h
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 Or use a wildcard, like it's used in the shell: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 :args *.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 Vim will take you to the first file in the list. Again, if the current file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 has changes, you can either write the file first, or use ":args!" (with !
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 added) to abandon the changes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 DID YOU EDIT THE LAST FILE?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 *arglist-quit*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 When you use a list of files, Vim assumes you want to edit them all. To
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 protect you from exiting too early, you will get this error when you didn't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 edit the last file in the list yet:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 E173: 46 more files to edit ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 If you really want to exit, just do it again. Then it will work (but not when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 you did other commands in between).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 *07.3* Jumping from file to file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 To quickly jump between two files, press CTRL-^ (on English-US keyboards the ^
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 is above the 6 key). Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 :args one.c two.c three.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 You are now in one.c. >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 :next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 Now you are in two.c. Now use CTRL-^ to go back to one.c. Another CTRL-^ and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 you are back in two.c. Another CTRL-^ and you are in one.c again. If you now
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 do: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 :next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 You are in three.c. Notice that the CTRL-^ command does not change the idea
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 of where you are in the list of files. Only commands like ":next" and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 ":previous" do that.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 The file you were previously editing is called the "alternate" file. When you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 just started Vim CTRL-^ will not work, since there isn't a previous file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 PREDEFINED MARKS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 After jumping to another file, you can use two predefined marks which are very
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 useful: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 `"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 This takes you to the position where the cursor was when you left the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 Another mark that is remembered is the position where you made the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 change: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 `.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 Suppose you are editing the file "one.txt". Somewhere halfway the file you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 use "x" to delete a character. Then you go to the last line with "G" and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 write the file with ":w". You edit several other files, and then use ":edit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 one.txt" to come back to "one.txt". If you now use `" Vim jumps to the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 line of the file. Using `. takes you to the position where you deleted the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 character. Even when you move around in the file `" and `. will take you to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 the remembered position. At least until you make another change or leave the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 FILE MARKS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 In chapter 4 was explained how you can place a mark in a file with "mx" and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 jump to that position with "`x". That works within one file. If you edit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 another file and place marks there, these are specific for that file. Thus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 each file has its own set of marks, they are local to the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 So far we were using marks with a lowercase letter. There are also marks
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 with an uppercase letter. These are global, they can be used from any file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 For example suppose that we are editing the file "foo.txt". Go to halfway the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 file ("50%") and place the F mark there (F for foo): >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 50%mF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 Now edit the file "bar.txt" and place the B mark (B for bar) at its last line:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 GmB
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 Now you can use the "'F" command to jump back to halfway foo.txt. Or edit yet
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 another file, type "'B" and you are at the end of bar.txt again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 The file marks are remembered until they are placed somewhere else. Thus you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 can place the mark, do hours of editing and still be able to jump back to that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 mark.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 It's often useful to think of a simple connection between the mark letter
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 and where it is placed. For example, use the H mark in a header file, M in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 a Makefile and C in a C code file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 To see where a specific mark is, give an argument to the ":marks" command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 :marks M
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 You can also give several arguments: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 :marks MCP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 Don't forget that you can use CTRL-O and CTRL-I to jump to older and newer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 positions without placing marks there.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 *07.4* Backup files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268
237
73354c21f1e4 updated for version 7.0066
vimboss
parents: 7
diff changeset
269 Usually Vim does not produce a backup file. If you want to have one, all you
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 need to do is execute the following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 :set backup
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 The name of the backup file is the original file with a ~ added to the end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 If your file is named data.txt, for example, the backup file name is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 data.txt~.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 If you do not like the fact that the backup files end with ~, you can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 change the extension: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 :set backupext=.bak
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 This will use data.txt.bak instead of data.txt~.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 Another option that matters here is 'backupdir'. It specifies where the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 backup file is written. The default, to write the backup in the same
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 directory as the original file, will mostly be the right thing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 When the 'backup' option isn't set but the 'writebackup' is, Vim will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 still create a backup file. However, it is deleted as soon as writing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 the file was completed successfully. This functions as a safety
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 against losing your original file when writing fails in some way (disk
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 full is the most common cause; being hit by lightning might be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 another, although less common).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 KEEPING THE ORIGINAL FILE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 If you are editing source files, you might want to keep the file before you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 make any changes. But the backup file will be overwritten each time you write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 the file. Thus it only contains the previous version, not the first one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 To make Vim keep the original file, set the 'patchmode' option. This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 specifies the extension used for the first backup of a changed file. Usually
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 you would do this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 :set patchmode=.orig
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 When you now edit the file data.txt for the first time, make changes and write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 the file, Vim will keep a copy of the unchanged file under the name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 "data.txt.orig".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 If you make further changes to the file, Vim will notice that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 "data.txt.orig" already exists and leave it alone. Further backup files will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 then be called "data.txt~" (or whatever you specified with 'backupext').
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 If you leave 'patchmode' empty (that is the default), the original file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 will not be kept.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 *07.5* Copy text between files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 This explains how to copy text from one file to another. Let's start with a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 simple example. Edit the file that contains the text you want to copy. Move
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 the cursor to the start of the text and press "v". This starts Visual mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 Now move the cursor to the end of the text and press "y". This yanks (copies)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 the selected text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 To copy the above paragraph, you would do: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 :edit thisfile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 /This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 vjjjj$y
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 Now edit the file you want to put the text in. Move the cursor to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 character where you want the text to appear after. Use "p" to put the text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 there. >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 :edit otherfile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 /There
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 Of course you can use many other commands to yank the text. For example, to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 select whole lines start Visual mode with "V". Or use CTRL-V to select a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 rectangular block. Or use "Y" to yank a single line, "yaw" to yank-a-word,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 The "p" command puts the text after the cursor. Use "P" to put the text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 before the cursor. Notice that Vim remembers if you yanked a whole line or a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 block, and puts it back that way.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 USING REGISTERS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 When you want to copy several pieces of text from one file to another, having
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 to switch between the files and writing the target file takes a lot of time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 To avoid this, copy each piece of text to its own register.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 A register is a place where Vim stores text. Here we will use the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 registers named a to z (later you will find out there are others). Let's copy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 a sentence to the f register (f for First): >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 "fyas
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 The "yas" command yanks a sentence like before. It's the "f that tells Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 the text should be place in the f register. This must come just before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 yank command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 Now yank three whole lines to the l register (l for line): >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 "l3Y
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 The count could be before the "l just as well. To yank a block of text to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 b (for block) register: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 CTRL-Vjjww"by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 Notice that the register specification "b is just before the "y" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 This is required. If you would have put it before the "w" command, it would
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 not have worked.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 Now you have three pieces of text in the f, l and b registers. Edit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 another file, move around and place the text where you want it: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 "fp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 Again, the register specification "f comes before the "p" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 You can put the registers in any order. And the text stays in the register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 until you yank something else into it. Thus you can put it as many times as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 you like.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 When you delete text, you can also specify a register. Use this to move
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 several pieces of text around. For example, to delete-a-word and write it in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 the w register: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 "wdaw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 Again, the register specification comes before the delete command "d".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 APPENDING TO A FILE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 When collecting lines of text into one file, you can use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 :write >> logfile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 This will write the text of the current file to the end of "logfile". Thus it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 is appended. This avoids that you have to copy the lines, edit the log file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 and put them there. Thus you save two steps. But you can only append to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 end of a file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 To append only a few lines, select them in Visual mode before typing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 ":write". In chapter 10 you will learn other ways to select a range of lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 *07.6* Viewing a file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 Sometimes you only want to see what a file contains, without the intention to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 ever write it back. There is the risk that you type ":w" without thinking and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 overwrite the original file anyway. To avoid this, edit the file read-only.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 To start Vim in readonly mode, use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 vim -R file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 On Unix this command should do the same thing: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 view file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 You are now editing "file" in read-only mode. When you try using ":w" you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 will get an error message and the file won't be written.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 When you try to make a change to the file Vim will give you a warning:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 W10: Warning: Changing a readonly file ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 The change will be done though. This allows for formatting the file, for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 example, to be able to read it easily.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 If you make changes to a file and forgot that it was read-only, you can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 still write it. Add the ! to the write command to force writing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 If you really want to forbid making changes in a file, do this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 vim -M file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 Now every attempt to change the text will fail. The help files are like this,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 for example. If you try to make a change you get this error message:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 E21: Cannot make changes, 'modifiable' is off ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 You could use the -M argument to setup Vim to work in a viewer mode. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 only voluntary though, since these commands will remove the protection: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 :set modifiable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 :set write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 *07.7* Changing the file name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 A clever way to start editing a new file is by using an existing file that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 contains most of what you need. For example, you start writing a new program
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 to move a file. You know that you already have a program that copies a file,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 thus you start with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 :edit copy.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 You can delete the stuff you don't need. Now you need to save the file under
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 a new name. The ":saveas" command can be used for this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 :saveas move.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 Vim will write the file under the given name, and edit that file. Thus the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 next time you do ":write", it will write "move.c". "copy.c" remains
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 unmodified.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 When you want to change the name of the file you are editing, but don't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 want to write the file, you can use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 :file move.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 Vim will mark the file as "not edited". This means that Vim knows this is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 the file you started editing. When you try to write the file, you might get
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 this message:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 E13: File exists (use ! to override) ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 This protects you from accidentally overwriting another file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 Next chapter: |usr_08.txt| Splitting windows
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 Copyright: see |manual-copyright| vim:tw=78:ts=8:ft=help:norl: