Mercurial > vim
annotate runtime/doc/usr_22.txt @ 25944:837198c91a25
Added tag v8.2.3505 for changeset dbf6a2066091b681ca3e885206b0dbf3743963d1
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 13 Oct 2021 16:45:04 +0200 |
parents | 1908e92b02fd |
children | f8116058ca76 |
rev | line source |
---|---|
19968 | 1 *usr_22.txt* For Vim version 8.2. Last change: 2020 Mar 28 |
7 | 2 |
3 VIM USER MANUAL - by Bram Moolenaar | |
4 | |
5 Finding the file to edit | |
6 | |
7 | |
8 Files can be found everywhere. So how do you find them? Vim offers various | |
9 ways to browse the directory tree. There are commands to jump to a file that | |
10 is mentioned in another. And Vim remembers which files have been edited | |
11 before. | |
12 | |
1618 | 13 |22.1| The file browser |
7 | 14 |22.2| The current directory |
15 |22.3| Finding a file | |
16 |22.4| The buffer list | |
17 | |
18 Next chapter: |usr_23.txt| Editing other files | |
19 Previous chapter: |usr_21.txt| Go away and come back | |
20 Table of contents: |usr_toc.txt| | |
21 | |
22 ============================================================================== | |
1618 | 23 *22.1* The file browser |
7 | 24 |
25 Vim has a plugin that makes it possible to edit a directory. Try this: > | |
26 | |
27 :edit . | |
28 | |
29 Through the magic of autocommands and Vim scripts, the window will be filled | |
30 with the contents of the directory. It looks like this: | |
31 | |
1618 | 32 " ============================================================================ ~ |
33 " Netrw Directory Listing (netrw v109) ~ | |
34 " Sorted by name ~ | |
35 " Sort sequence: [\/]$,\.h$,\.c$,\.cpp$,*,\.info$,\.swp$,\.o$\.obj$,\.bak$ ~ | |
36 " Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec ~ | |
37 " ============================================================================ ~ | |
38 ../ ~ | |
39 ./ ~ | |
40 check/ ~ | |
41 Makefile ~ | |
42 autocmd.txt ~ | |
43 change.txt ~ | |
44 eval.txt~ ~ | |
45 filetype.txt~ ~ | |
46 help.txt.info ~ | |
7 | 47 |
48 You can see these items: | |
1618 | 49 |
50 1. The name of the browsing tool and its version number | |
51 2. The name of the browsing directory | |
52 3. The method of sorting (may be by name, time, or size) | |
53 4. How names are to be sorted (directories first, then *.h files, | |
54 *.c files, etc) | |
55 5. How to get help (use the <F1> key), and an abbreviated listing | |
56 of available commands | |
2098
3259c3923c1e
Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
57 6. A listing of files, including "../", which allows one to list |
1618 | 58 the parent directory. |
7 | 59 |
60 If you have syntax highlighting enabled, the different parts are highlighted | |
1618 | 61 so as to make it easier to spot them. |
7 | 62 |
63 You can use Normal mode Vim commands to move around in the text. For example, | |
1618 | 64 move the cursor atop a file and press <Enter>; you will then be editing that |
65 file. To go back to the browser use ":edit ." again, or use ":Explore". | |
66 CTRL-O also works. | |
67 | |
68 Try using <Enter> while the cursor is atop a directory name. The result is | |
69 that the file browser moves into that directory and displays the items found | |
7 | 70 there. Pressing <Enter> on the first directory "../" moves you one level |
71 higher. Pressing "-" does the same thing, without the need to move to the | |
72 "../" item first. | |
73 | |
1618 | 74 You can press <F1> to get help on the things you can do in the netrw file |
75 browser. This is what you get: > | |
76 | |
18831 | 77 9. Directory Browsing netrw-browse netrw-dir netrw-list netrw-help |
7 | 78 |
18831 | 79 MAPS netrw-maps |
1618 | 80 <F1>.............Help.......................................|netrw-help| |
81 <cr>.............Browsing...................................|netrw-cr| | |
82 <del>............Deleting Files or Directories..............|netrw-delete| | |
83 -................Going Up...................................|netrw--| | |
84 a................Hiding Files or Directories................|netrw-a| | |
85 mb...............Bookmarking a Directory....................|netrw-mb| | |
86 gb...............Changing to a Bookmarked Directory.........|netrw-gb| | |
19968 | 87 cd...............Make Browsing Directory The Current Dir....|netrw-c| |
1618 | 88 d................Make A New Directory.......................|netrw-d| |
89 D................Deleting Files or Directories..............|netrw-D| | |
90 <c-h>............Edit File/Directory Hiding List............|netrw-ctrl-h| | |
91 i................Change Listing Style.......................|netrw-i| | |
92 <c-l>............Refreshing the Listing.....................|netrw-ctrl-l| | |
93 o................Browsing with a Horizontal Split...........|netrw-o| | |
94 p................Use Preview Window.........................|netrw-p| | |
95 P................Edit in Previous Window....................|netrw-p| | |
10498
883396809b45
commit https://github.com/vim/vim/commit/bc2eada5424bff06f7eb77c032ecc067da52b846
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
96 q................Listing Bookmarks and History..............|netrw-qb| |
1618 | 97 r................Reversing Sorting Order....................|netrw-r| |
98 < (etc) | |
7 | 99 |
1618 | 100 The <F1> key thus brings you to a netrw directory browsing contents help page. |
2207
b17bbfa96fa0
Add the settabvar() and gettabvar() functions.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
101 It's a regular help page; use the usual |CTRL-]| to jump to tagged help items |
1618 | 102 and |CTRL-O| to jump back. |
103 | |
104 To select files for display and editing: (with the cursor is atop a filename) | |
7 | 105 |
1618 | 106 <enter> Open the file in the current window. |netrw-cr| |
107 o Horizontally split window and display file |netrw-o| | |
108 v Vertically split window and display file |netrw-v| | |
109 p Use the |preview-window| |netrw-p| | |
110 P Edit in the previous window |netrw-P| | |
111 t Open file in a new tab |netrw-t| | |
112 | |
113 The following normal-mode commands may be used to control the browser display: | |
7 | 114 |
1618 | 115 i Controls listing style (thin, long, wide, and tree). |
116 The long listing includes size and date information. | |
117 s Repeatedly pressing s will change the way the files | |
118 are sorted; one may sort on name, modification time, | |
119 or size. | |
120 r Reverse the sorting order. | |
121 | |
122 As a sampling of extra normal-mode commands: | |
7 | 123 |
19968 | 124 cd Change Vim's notion of the current directory to be |
1618 | 125 the same as the browser directory. (see |
126 |g:netrw_keepdir| to control this, too) | |
127 R Rename the file or directory under the cursor; a | |
128 prompt will be issued for the new name. | |
129 D Delete the file or directory under the cursor; a | |
130 confirmation request will be issued. | |
131 mb gb Make bookmark/goto bookmark | |
132 | |
133 | |
134 One may also use command mode; again, just a sampling: | |
7 | 135 |
1618 | 136 :Explore [directory] Browse specified/current directory |
137 :NetrwSettings A comprehensive list of your current netrw | |
138 settings with help linkage. | |
7 | 139 |
1618 | 140 The netrw browser is not limited to just your local machine; one may use |
141 urls such as: (that trailing / is important) | |
142 | |
143 :Explore ftp://somehost/path/to/dir/ | |
144 :e scp://somehost/path/to/dir/ | |
145 | |
146 See |netrw-browse| for more. | |
7 | 147 |
148 ============================================================================== | |
149 *22.2* The current directory | |
150 | |
151 Just like the shell, Vim has the concept of a current directory. Suppose you | |
152 are in your home directory and want to edit several files in a directory | |
153 "VeryLongFileName". You could do: > | |
154 | |
155 :edit VeryLongFileName/file1.txt | |
156 :edit VeryLongFileName/file2.txt | |
157 :edit VeryLongFileName/file3.txt | |
158 | |
159 To avoid much of the typing, do this: > | |
160 | |
161 :cd VeryLongFileName | |
162 :edit file1.txt | |
163 :edit file2.txt | |
164 :edit file3.txt | |
165 | |
166 The ":cd" command changes the current directory. You can see what the current | |
167 directory is with the ":pwd" command: > | |
168 | |
169 :pwd | |
170 /home/Bram/VeryLongFileName | |
171 | |
172 Vim remembers the last directory that you used. Use "cd -" to go back to it. | |
173 Example: > | |
174 | |
175 :pwd | |
176 /home/Bram/VeryLongFileName | |
177 :cd /etc | |
178 :pwd | |
179 /etc | |
180 :cd - | |
181 :pwd | |
182 /home/Bram/VeryLongFileName | |
183 :cd - | |
184 :pwd | |
185 /etc | |
186 | |
187 | |
188 WINDOW LOCAL DIRECTORY | |
189 | |
190 When you split a window, both windows use the same current directory. When | |
191 you want to edit a number of files somewhere else in the new window, you can | |
192 make it use a different directory, without changing the current directory in | |
193 the other window. This is called a local directory. > | |
194 | |
195 :pwd | |
196 /home/Bram/VeryLongFileName | |
197 :split | |
198 :lcd /etc | |
199 :pwd | |
200 /etc | |
201 CTRL-W w | |
202 :pwd | |
203 /home/Bram/VeryLongFileName | |
204 | |
16427
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
205 So long as no `:lcd` command has been used, all windows share the same current |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
206 directory. Doing a `:cd` command in one window will also change the current |
7 | 207 directory of the other window. |
16427
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
208 For a window where `:lcd` has been used a different current directory is |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
209 remembered. Using `:cd` or `:lcd` in other windows will not change it. |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
210 When using a `:cd` command in a window that uses a different current |
7 | 211 directory, it will go back to using the shared directory. |
212 | |
16427
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
213 |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
214 TAB LOCAL DIRECTORY |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
215 |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
216 When you open a new tab page, it uses the directory of the window in the |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
217 previous tab page from which the new tab page was opened. You can change the |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
218 directory of the current tab page using the `:tcd` command. All the windows in |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
219 a tab page share this directory except for windows with a window-local |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
220 directory. Any new windows opened in this tab page will use this directory as |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
221 the current working directory. Using a `:cd` command in a tab page will not |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
222 change the working directory of tab pages which have a tab local directory. |
16808 | 223 When the global working directory is changed using the `:cd` command in a tab |
16427
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
224 page, it will also change the current tab page working directory. |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
225 |
8c3a1bd270bb
patch 8.1.1218: cannot set a directory for a tab page
Bram Moolenaar <Bram@vim.org>
parents:
14519
diff
changeset
|
226 |
7 | 227 ============================================================================== |
228 *22.3* Finding a file | |
229 | |
230 You are editing a C program that contains this line: | |
231 | |
232 #include "inits.h" ~ | |
233 | |
234 You want to see what is in that "inits.h" file. Move the cursor on the name | |
235 of the file and type: > | |
236 | |
237 gf | |
238 | |
239 Vim will find the file and edit it. | |
240 What if the file is not in the current directory? Vim will use the 'path' | |
241 option to find the file. This option is a list of directory names where to | |
242 look for your file. | |
243 Suppose you have your include files located in "c:/prog/include". This | |
244 command will add it to the 'path' option: > | |
245 | |
246 :set path+=c:/prog/include | |
247 | |
248 This directory is an absolute path. No matter where you are, it will be the | |
249 same place. What if you have located files in a subdirectory, below where the | |
250 file is? Then you can specify a relative path name. This starts with a dot: | |
251 > | |
252 :set path+=./proto | |
253 | |
254 This tells Vim to look in the directory "proto", below the directory where the | |
255 file in which you use "gf" is. Thus using "gf" on "inits.h" will make Vim | |
256 look for "proto/inits.h", starting in the directory of the file. | |
257 Without the "./", thus "proto", Vim would look in the "proto" directory | |
258 below the current directory. And the current directory might not be where the | |
259 file that you are editing is located. | |
260 | |
261 The 'path' option allows specifying the directories where to search for files | |
262 in many more ways. See the help on the 'path' option. | |
263 The 'isfname' option is used to decide which characters are included in the | |
264 file name, and which ones are not (e.g., the " character in the example | |
265 above). | |
266 | |
267 When you know the file name, but it's not to be found in the file, you can | |
268 type it: > | |
269 | |
270 :find inits.h | |
271 | |
272 Vim will then use the 'path' option to try and locate the file. This is the | |
273 same as the ":edit" command, except for the use of 'path'. | |
274 | |
275 To open the found file in a new window use CTRL-W f instead of "gf", or use | |
276 ":sfind" instead of ":find". | |
277 | |
278 | |
279 A nice way to directly start Vim to edit a file somewhere in the 'path': > | |
280 | |
281 vim "+find stdio.h" | |
282 | |
283 This finds the file "stdio.h" in your value of 'path'. The quotes are | |
284 necessary to have one argument |-+c|. | |
285 | |
286 ============================================================================== | |
287 *22.4* The buffer list | |
288 | |
289 The Vim editor uses the term buffer to describe a file being edited. | |
290 Actually, a buffer is a copy of the file that you edit. When you finish | |
291 changing the buffer, you write the contents of the buffer to the file. | |
292 Buffers not only contain file contents, but also all the marks, settings, and | |
293 other stuff that goes with it. | |
294 | |
295 | |
296 HIDDEN BUFFERS | |
297 | |
298 Suppose you are editing the file one.txt and need to edit the file two.txt. | |
299 You could simply use ":edit two.txt", but since you made changes to one.txt | |
300 that won't work. You also don't want to write one.txt yet. Vim has a | |
301 solution for you: > | |
302 | |
303 :hide edit two.txt | |
304 | |
305 The buffer "one.txt" disappears from the screen, but Vim still knows that you | |
306 are editing this buffer, so it keeps the modified text. This is called a | |
307 hidden buffer: The buffer contains text, but you can't see it. | |
1618 | 308 The argument of ":hide" is another command. ":hide" makes that command |
309 behave as if the 'hidden' option was set. You could also set this option | |
7 | 310 yourself. The effect is that when any buffer is abandoned, it becomes hidden. |
311 Be careful! When you have hidden buffers with changes, don't exit Vim | |
312 without making sure you have saved all the buffers. | |
313 | |
314 | |
315 INACTIVE BUFFERS | |
316 | |
317 When a buffer has been used once, Vim remembers some information about it. | |
318 When it is not displayed in a window and it is not hidden, it is still in the | |
319 buffer list. This is called an inactive buffer. Overview: | |
320 | |
321 Active Appears in a window, text loaded. | |
322 Hidden Not in a window, text loaded. | |
323 Inactive Not in a window, no text loaded. | |
324 | |
325 The inactive buffers are remembered, because Vim keeps information about them, | |
326 like marks. And remembering the file name is useful too, so that you can see | |
327 which files you have edited. And edit them again. | |
328 | |
329 | |
330 LISTING BUFFERS | |
331 | |
332 View the buffer list with this command: > | |
333 | |
334 :buffers | |
335 | |
336 A command which does the same, is not so obvious to list buffers, but is much | |
337 shorter to type: > | |
338 | |
339 :ls | |
340 | |
341 The output could look like this: | |
342 | |
3920 | 343 1 #h "help.txt" line 62 ~ |
344 2 %a + "usr_21.txt" line 1 ~ | |
345 3 "usr_toc.txt" line 1 ~ | |
7 | 346 |
347 The first column contains the buffer number. You can use this to edit the | |
348 buffer without having to type the name, see below. | |
349 After the buffer number come the flags. Then the name of the file | |
350 and the line number where the cursor was the last time. | |
351 The flags that can appear are these (from left to right): | |
352 | |
353 u Buffer is unlisted |unlisted-buffer|. | |
354 % Current buffer. | |
355 # Alternate buffer. | |
236 | 356 a Buffer is loaded and displayed. |
7 | 357 h Buffer is loaded but hidden. |
358 = Buffer is read-only. | |
359 - Buffer is not modifiable, the 'modifiable' option is off. | |
360 + Buffer has been modified. | |
361 | |
362 | |
363 EDITING A BUFFER | |
364 | |
365 You can edit a buffer by its number. That avoids having to type the file | |
366 name: > | |
367 | |
368 :buffer 2 | |
369 | |
370 But the only way to know the number is by looking in the buffer list. You can | |
371 use the name, or part of it, instead: > | |
372 | |
373 :buffer help | |
374 | |
2207
b17bbfa96fa0
Add the settabvar() and gettabvar() functions.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
375 Vim will find the best match for the name you type. If there is only one |
7 | 376 buffer that matches the name, it will be used. In this case "help.txt". |
377 To open a buffer in a new window: > | |
378 | |
379 :sbuffer 3 | |
380 | |
381 This works with a name as well. | |
382 | |
383 | |
384 USING THE BUFFER LIST | |
385 | |
386 You can move around in the buffer list with these commands: | |
387 | |
388 :bnext go to next buffer | |
389 :bprevious go to previous buffer | |
390 :bfirst go to the first buffer | |
391 :blast go to the last buffer | |
392 | |
393 To remove a buffer from the list, use this command: > | |
394 | |
395 :bdelete 3 | |
396 | |
397 Again, this also works with a name. | |
398 If you delete a buffer that was active (visible in a window), that window | |
399 will be closed. If you delete the current buffer, the current window will be | |
400 closed. If it was the last window, Vim will find another buffer to edit. You | |
401 can't be editing nothing! | |
402 | |
403 Note: | |
404 Even after removing the buffer with ":bdelete" Vim still remembers it. | |
405 It's actually made "unlisted", it no longer appears in the list from | |
406 ":buffers". The ":buffers!" command will list unlisted buffers (yes, | |
407 Vim can do the impossible). To really make Vim forget about a buffer, | |
408 use ":bwipe". Also see the 'buflisted' option. | |
409 | |
410 ============================================================================== | |
411 | |
412 Next chapter: |usr_23.txt| Editing other files | |
413 | |
14519 | 414 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: |