annotate runtime/doc/usr_22.txt @ 846:db44f7b81373 v7.0f03

updated for version 7.0f03
author vimboss
date Thu, 27 Apr 2006 21:47:44 +0000
parents a209672376fd
children 8cd729851562
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
842
a209672376fd updated for version 7.0f
vimboss
parents: 834
diff changeset
1 *usr_22.txt* For Vim version 7.0f. 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 Finding the file to edit
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 Files can be found everywhere. So how do you find them? Vim offers various
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 ways to browse the directory tree. There are commands to jump to a file that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 is mentioned in another. And Vim remembers which files have been edited
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 before.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 |22.1| The file explorer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |22.2| The current directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 |22.3| Finding a file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 |22.4| The buffer list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 Next chapter: |usr_23.txt| Editing other files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 Previous chapter: |usr_21.txt| Go away and come back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 Table of contents: |usr_toc.txt|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 *22.1* The file explorer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 Vim has a plugin that makes it possible to edit a directory. Try this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 :edit .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 Through the magic of autocommands and Vim scripts, the window will be filled
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 with the contents of the directory. It looks like this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 " Press ? for keyboard shortcuts ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 " Sorted by name (.bak,~,.o,.h,.info,.swp,.obj,.orig,.rej at end of list) ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 "= /home/mool/vim/vim6/runtime/doc/ ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 ../ ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 check/ ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 Makefile ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 autocmd.txt ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 change.txt ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 eval.txt~ ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 filetype.txt~ ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 help.txt.info ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 You can see these items:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 1. A comment about using ? to get help for the functionality of the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 explorer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 2. The second line mentions how the items in the directory are listed. They
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 can be sorted in several ways.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 3. The third line is the name of the current directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 4. The "../" directory item. This is the parent directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 5. The directory names.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 6. The ordinary file names. As mentioned in the second line, some are not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 here but "at the end of the list".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 7. The less ordinary file names. You are expected to use these less often,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 therefore they have been moved to the end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 If you have syntax highlighting enabled, the different parts are highlighted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 to make it easier to spot them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 You can use Normal mode Vim commands to move around in the text. For example,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 move to a file and press <Enter>. Now you are editing that file. To go back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 to the explorer use ":edit ." again. CTRL-O also works.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 Try using <Enter> while the cursor is on a directory name. The result is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 that the explorer moves into that directory and displays the items found
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 there. Pressing <Enter> on the first directory "../" moves you one level
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 higher. Pressing "-" does the same thing, without the need to move to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 "../" item first.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 You can press ? to get short help on the things you can do in the explorer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 This is what you get:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 " <enter> : open file or directory ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 " o : open new window for file/directory ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 " O : open file in previously visited window ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 " p : preview the file ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 " i : toggle size/date listing ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 " s : select sort field r : reverse sort ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 " - : go up one level c : cd to this dir ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 " R : rename file D : delete file ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 " :help file-explorer for detailed help ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 The first few commands are for selecting a file to display. Depending on what
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 command you use, the file appears somewhere:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 <Enter> Uses the current window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 o Opens a new window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 O Uses the previously visited window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 p Uses the preview window, and moves the cursor back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 into the explorer window. |preview-window|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 The following commands are used to display other information:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 i Display the size and date for the file. Using i again
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 will hide the information.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 s Use the field the cursor is in to sort on. First
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 display the size and date with i. Then Move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 cursor to the size of any file and press s. The files
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
98 will now be sorted on size. Press s while the cursor
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 is on a date and the items will be sorted on date.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 r reverse the sorting order (either size or date)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 There are a few extra commands:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 c Change the current directory to the displayed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 directory. You can then type an ":edit" command for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 one of the files without prepending the path.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 R Rename the file under the cursor. You will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 prompted for the new name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 D Delete the file under the cursor. You will get a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 prompt to confirm this.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 *22.2* The current directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 Just like the shell, Vim has the concept of a current directory. Suppose you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 are in your home directory and want to edit several files in a directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 "VeryLongFileName". You could do: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 :edit VeryLongFileName/file1.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 :edit VeryLongFileName/file2.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 :edit VeryLongFileName/file3.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 To avoid much of the typing, do this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 :cd VeryLongFileName
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 :edit file1.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 :edit file2.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 :edit file3.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 The ":cd" command changes the current directory. You can see what the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 directory is with the ":pwd" command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 :pwd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 /home/Bram/VeryLongFileName
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 Vim remembers the last directory that you used. Use "cd -" to go back to it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 :pwd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 /home/Bram/VeryLongFileName
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 :cd /etc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 :pwd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 /etc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 :cd -
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 :pwd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 /home/Bram/VeryLongFileName
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 :cd -
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 :pwd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 /etc
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 WINDOW LOCAL DIRECTORY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 When you split a window, both windows use the same current directory. When
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 you want to edit a number of files somewhere else in the new window, you can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 make it use a different directory, without changing the current directory in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 the other window. This is called a local directory. >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 :pwd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 /home/Bram/VeryLongFileName
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 :split
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 :lcd /etc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 :pwd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 /etc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 CTRL-W w
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 :pwd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 /home/Bram/VeryLongFileName
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 So long as no ":lcd" command has been used, all windows share the same current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 directory. Doing a ":cd" command in one window will also change the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 directory of the other window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 For a window where ":lcd" has been used a different current directory is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 remembered. Using ":cd" or ":lcd" in other windows will not change it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 When using a ":cd" command in a window that uses a different current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 directory, it will go back to using the shared directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 *22.3* Finding a file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 You are editing a C program that contains this line:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 #include "inits.h" ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 You want to see what is in that "inits.h" file. Move the cursor on the name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 of the file and type: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 gf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 Vim will find the file and edit it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 What if the file is not in the current directory? Vim will use the 'path'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 option to find the file. This option is a list of directory names where to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 look for your file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 Suppose you have your include files located in "c:/prog/include". This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 command will add it to the 'path' option: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 :set path+=c:/prog/include
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 This directory is an absolute path. No matter where you are, it will be the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 same place. What if you have located files in a subdirectory, below where the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 file is? Then you can specify a relative path name. This starts with a dot:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 :set path+=./proto
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 This tells Vim to look in the directory "proto", below the directory where the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 file in which you use "gf" is. Thus using "gf" on "inits.h" will make Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 look for "proto/inits.h", starting in the directory of the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 Without the "./", thus "proto", Vim would look in the "proto" directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 below the current directory. And the current directory might not be where the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 file that you are editing is located.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 The 'path' option allows specifying the directories where to search for files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 in many more ways. See the help on the 'path' option.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 The 'isfname' option is used to decide which characters are included in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 file name, and which ones are not (e.g., the " character in the example
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 above).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 When you know the file name, but it's not to be found in the file, you can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 type it: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 :find inits.h
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 Vim will then use the 'path' option to try and locate the file. This is the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 same as the ":edit" command, except for the use of 'path'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 To open the found file in a new window use CTRL-W f instead of "gf", or use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 ":sfind" instead of ":find".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 A nice way to directly start Vim to edit a file somewhere in the 'path': >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 vim "+find stdio.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 This finds the file "stdio.h" in your value of 'path'. The quotes are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 necessary to have one argument |-+c|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 *22.4* The buffer list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 The Vim editor uses the term buffer to describe a file being edited.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 Actually, a buffer is a copy of the file that you edit. When you finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 changing the buffer, you write the contents of the buffer to the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 Buffers not only contain file contents, but also all the marks, settings, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 other stuff that goes with it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 HIDDEN BUFFERS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 Suppose you are editing the file one.txt and need to edit the file two.txt.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 You could simply use ":edit two.txt", but since you made changes to one.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 that won't work. You also don't want to write one.txt yet. Vim has a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 solution for you: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 :hide edit two.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 The buffer "one.txt" disappears from the screen, but Vim still knows that you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 are editing this buffer, so it keeps the modified text. This is called a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 hidden buffer: The buffer contains text, but you can't see it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 The ":hide" command argument is another command. It makes that command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 behave like the 'hidden' option was set. You could also set this option
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 yourself. The effect is that when any buffer is abandoned, it becomes hidden.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 Be careful! When you have hidden buffers with changes, don't exit Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 without making sure you have saved all the buffers.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 INACTIVE BUFFERS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 When a buffer has been used once, Vim remembers some information about it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 When it is not displayed in a window and it is not hidden, it is still in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 buffer list. This is called an inactive buffer. Overview:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 Active Appears in a window, text loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 Hidden Not in a window, text loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 Inactive Not in a window, no text loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 The inactive buffers are remembered, because Vim keeps information about them,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 like marks. And remembering the file name is useful too, so that you can see
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 which files you have edited. And edit them again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 LISTING BUFFERS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 View the buffer list with this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 :buffers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 A command which does the same, is not so obvious to list buffers, but is much
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 shorter to type: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 :ls
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 The output could look like this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 1 #h "help.txt" line 62 ~
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 9
diff changeset
294 2 %a+ "usr_21.txt" line 1 ~
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 3 "usr_toc.txt" line 1 ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 The first column contains the buffer number. You can use this to edit the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 buffer without having to type the name, see below.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 After the buffer number come the flags. Then the name of the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 and the line number where the cursor was the last time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 The flags that can appear are these (from left to right):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 u Buffer is unlisted |unlisted-buffer|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 % Current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 # Alternate buffer.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 9
diff changeset
306 a Buffer is loaded and displayed.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 h Buffer is loaded but hidden.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 = Buffer is read-only.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 - Buffer is not modifiable, the 'modifiable' option is off.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 + Buffer has been modified.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 EDITING A BUFFER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 You can edit a buffer by its number. That avoids having to type the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 name: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 :buffer 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 But the only way to know the number is by looking in the buffer list. You can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 use the name, or part of it, instead: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 :buffer help
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 Vim will find a best match for the name you type. If there is only one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 buffer that matches the name, it will be used. In this case "help.txt".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 To open a buffer in a new window: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 :sbuffer 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 This works with a name as well.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 USING THE BUFFER LIST
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 You can move around in the buffer list with these commands:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 :bnext go to next buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 :bprevious go to previous buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 :bfirst go to the first buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 :blast go to the last buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 To remove a buffer from the list, use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 :bdelete 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 Again, this also works with a name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 If you delete a buffer that was active (visible in a window), that window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 will be closed. If you delete the current buffer, the current window will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 closed. If it was the last window, Vim will find another buffer to edit. You
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 can't be editing nothing!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 Even after removing the buffer with ":bdelete" Vim still remembers it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 It's actually made "unlisted", it no longer appears in the list from
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 ":buffers". The ":buffers!" command will list unlisted buffers (yes,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 Vim can do the impossible). To really make Vim forget about a buffer,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 use ":bwipe". Also see the 'buflisted' option.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 Next chapter: |usr_23.txt| Editing other files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 Copyright: see |manual-copyright| vim:tw=78:ts=8:ft=help:norl: