Mercurial > vim
annotate runtime/doc/usr_22.txt @ 12337:040a892d0eed v8.0.1048
patch 8.0.1048: no test for what 8.0.1020 fixes
commit https://github.com/vim/vim/commit/5e80de3f3e572805fe734b66bc42c13303ad9bdb
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Sep 3 15:48:12 2017 +0200
patch 8.0.1048: no test for what 8.0.1020 fixes
Problem: No test for what 8.0.1020 fixes.
Solution: Add test_feedinput(). Add a test. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/2046)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 03 Sep 2017 16:00:05 +0200 |
parents | 883396809b45 |
children | 1174611ad715 |
rev | line source |
---|---|
10498
883396809b45
commit https://github.com/vim/vim/commit/bc2eada5424bff06f7eb77c032ecc067da52b846
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
1 *usr_22.txt* For Vim version 8.0. Last change: 2016 Dec 13 |
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 | |
77 9. Directory Browsing netrw-browse netrw-dir netrw-list netrw-help | |
7 | 78 |
1618 | 79 MAPS netrw-maps |
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| | |
87 c................Make Browsing Directory The Current Dir....|netrw-c| | |
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 |
1618 | 124 c Change Vim's notion of the current directory to be |
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 | |
205 So long as no ":lcd" command has been used, all windows share the same current | |
206 directory. Doing a ":cd" command in one window will also change the current | |
207 directory of the other window. | |
208 For a window where ":lcd" has been used a different current directory is | |
209 remembered. Using ":cd" or ":lcd" in other windows will not change it. | |
210 When using a ":cd" command in a window that uses a different current | |
211 directory, it will go back to using the shared directory. | |
212 | |
213 ============================================================================== | |
214 *22.3* Finding a file | |
215 | |
216 You are editing a C program that contains this line: | |
217 | |
218 #include "inits.h" ~ | |
219 | |
220 You want to see what is in that "inits.h" file. Move the cursor on the name | |
221 of the file and type: > | |
222 | |
223 gf | |
224 | |
225 Vim will find the file and edit it. | |
226 What if the file is not in the current directory? Vim will use the 'path' | |
227 option to find the file. This option is a list of directory names where to | |
228 look for your file. | |
229 Suppose you have your include files located in "c:/prog/include". This | |
230 command will add it to the 'path' option: > | |
231 | |
232 :set path+=c:/prog/include | |
233 | |
234 This directory is an absolute path. No matter where you are, it will be the | |
235 same place. What if you have located files in a subdirectory, below where the | |
236 file is? Then you can specify a relative path name. This starts with a dot: | |
237 > | |
238 :set path+=./proto | |
239 | |
240 This tells Vim to look in the directory "proto", below the directory where the | |
241 file in which you use "gf" is. Thus using "gf" on "inits.h" will make Vim | |
242 look for "proto/inits.h", starting in the directory of the file. | |
243 Without the "./", thus "proto", Vim would look in the "proto" directory | |
244 below the current directory. And the current directory might not be where the | |
245 file that you are editing is located. | |
246 | |
247 The 'path' option allows specifying the directories where to search for files | |
248 in many more ways. See the help on the 'path' option. | |
249 The 'isfname' option is used to decide which characters are included in the | |
250 file name, and which ones are not (e.g., the " character in the example | |
251 above). | |
252 | |
253 When you know the file name, but it's not to be found in the file, you can | |
254 type it: > | |
255 | |
256 :find inits.h | |
257 | |
258 Vim will then use the 'path' option to try and locate the file. This is the | |
259 same as the ":edit" command, except for the use of 'path'. | |
260 | |
261 To open the found file in a new window use CTRL-W f instead of "gf", or use | |
262 ":sfind" instead of ":find". | |
263 | |
264 | |
265 A nice way to directly start Vim to edit a file somewhere in the 'path': > | |
266 | |
267 vim "+find stdio.h" | |
268 | |
269 This finds the file "stdio.h" in your value of 'path'. The quotes are | |
270 necessary to have one argument |-+c|. | |
271 | |
272 ============================================================================== | |
273 *22.4* The buffer list | |
274 | |
275 The Vim editor uses the term buffer to describe a file being edited. | |
276 Actually, a buffer is a copy of the file that you edit. When you finish | |
277 changing the buffer, you write the contents of the buffer to the file. | |
278 Buffers not only contain file contents, but also all the marks, settings, and | |
279 other stuff that goes with it. | |
280 | |
281 | |
282 HIDDEN BUFFERS | |
283 | |
284 Suppose you are editing the file one.txt and need to edit the file two.txt. | |
285 You could simply use ":edit two.txt", but since you made changes to one.txt | |
286 that won't work. You also don't want to write one.txt yet. Vim has a | |
287 solution for you: > | |
288 | |
289 :hide edit two.txt | |
290 | |
291 The buffer "one.txt" disappears from the screen, but Vim still knows that you | |
292 are editing this buffer, so it keeps the modified text. This is called a | |
293 hidden buffer: The buffer contains text, but you can't see it. | |
1618 | 294 The argument of ":hide" is another command. ":hide" makes that command |
295 behave as if the 'hidden' option was set. You could also set this option | |
7 | 296 yourself. The effect is that when any buffer is abandoned, it becomes hidden. |
297 Be careful! When you have hidden buffers with changes, don't exit Vim | |
298 without making sure you have saved all the buffers. | |
299 | |
300 | |
301 INACTIVE BUFFERS | |
302 | |
303 When a buffer has been used once, Vim remembers some information about it. | |
304 When it is not displayed in a window and it is not hidden, it is still in the | |
305 buffer list. This is called an inactive buffer. Overview: | |
306 | |
307 Active Appears in a window, text loaded. | |
308 Hidden Not in a window, text loaded. | |
309 Inactive Not in a window, no text loaded. | |
310 | |
311 The inactive buffers are remembered, because Vim keeps information about them, | |
312 like marks. And remembering the file name is useful too, so that you can see | |
313 which files you have edited. And edit them again. | |
314 | |
315 | |
316 LISTING BUFFERS | |
317 | |
318 View the buffer list with this command: > | |
319 | |
320 :buffers | |
321 | |
322 A command which does the same, is not so obvious to list buffers, but is much | |
323 shorter to type: > | |
324 | |
325 :ls | |
326 | |
327 The output could look like this: | |
328 | |
3920 | 329 1 #h "help.txt" line 62 ~ |
330 2 %a + "usr_21.txt" line 1 ~ | |
331 3 "usr_toc.txt" line 1 ~ | |
7 | 332 |
333 The first column contains the buffer number. You can use this to edit the | |
334 buffer without having to type the name, see below. | |
335 After the buffer number come the flags. Then the name of the file | |
336 and the line number where the cursor was the last time. | |
337 The flags that can appear are these (from left to right): | |
338 | |
339 u Buffer is unlisted |unlisted-buffer|. | |
340 % Current buffer. | |
341 # Alternate buffer. | |
236 | 342 a Buffer is loaded and displayed. |
7 | 343 h Buffer is loaded but hidden. |
344 = Buffer is read-only. | |
345 - Buffer is not modifiable, the 'modifiable' option is off. | |
346 + Buffer has been modified. | |
347 | |
348 | |
349 EDITING A BUFFER | |
350 | |
351 You can edit a buffer by its number. That avoids having to type the file | |
352 name: > | |
353 | |
354 :buffer 2 | |
355 | |
356 But the only way to know the number is by looking in the buffer list. You can | |
357 use the name, or part of it, instead: > | |
358 | |
359 :buffer help | |
360 | |
2207
b17bbfa96fa0
Add the settabvar() and gettabvar() functions.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
361 Vim will find the best match for the name you type. If there is only one |
7 | 362 buffer that matches the name, it will be used. In this case "help.txt". |
363 To open a buffer in a new window: > | |
364 | |
365 :sbuffer 3 | |
366 | |
367 This works with a name as well. | |
368 | |
369 | |
370 USING THE BUFFER LIST | |
371 | |
372 You can move around in the buffer list with these commands: | |
373 | |
374 :bnext go to next buffer | |
375 :bprevious go to previous buffer | |
376 :bfirst go to the first buffer | |
377 :blast go to the last buffer | |
378 | |
379 To remove a buffer from the list, use this command: > | |
380 | |
381 :bdelete 3 | |
382 | |
383 Again, this also works with a name. | |
384 If you delete a buffer that was active (visible in a window), that window | |
385 will be closed. If you delete the current buffer, the current window will be | |
386 closed. If it was the last window, Vim will find another buffer to edit. You | |
387 can't be editing nothing! | |
388 | |
389 Note: | |
390 Even after removing the buffer with ":bdelete" Vim still remembers it. | |
391 It's actually made "unlisted", it no longer appears in the list from | |
392 ":buffers". The ":buffers!" command will list unlisted buffers (yes, | |
393 Vim can do the impossible). To really make Vim forget about a buffer, | |
394 use ":bwipe". Also see the 'buflisted' option. | |
395 | |
396 ============================================================================== | |
397 | |
398 Next chapter: |usr_23.txt| Editing other files | |
399 | |
400 Copyright: see |manual-copyright| vim:tw=78:ts=8:ft=help:norl: |