1*usr_22.txt*	For Vim version 7.3.  Last change: 2010 Feb 21
2
3		     VIM USER MANUAL - by Bram Moolenaar
4
5			   Finding the file to edit
6
7
8Files can be found everywhere.  So how do you find them?  Vim offers various
9ways to browse the directory tree.  There are commands to jump to a file that
10is mentioned in another.  And Vim remembers which files have been edited
11before.
12
13|22.1|	The file browser
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
20Table of contents: |usr_toc.txt|
21
22==============================================================================
23*22.1*	The file browser
24
25Vim has a plugin that makes it possible to edit a directory.  Try this: >
26
27	:edit .
28
29Through the magic of autocommands and Vim scripts, the window will be filled
30with the contents of the directory.  It looks like this:
31
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./ ~
40check/ ~
41Makefile ~
42autocmd.txt ~
43change.txt ~
44eval.txt~ ~
45filetype.txt~ ~
46help.txt.info ~
47
48You can see these items:
49
501.  The name of the browsing tool and its version number
512.  The name of the browsing directory
523.  The method of sorting (may be by name, time, or size)
534.  How names are to be sorted (directories first, then *.h files,
54    *.c files, etc)
555.  How to get help (use the <F1> key), and an abbreviated listing
56    of available commands
576.  A listing of files, including "../", which allows one to list
58    the parent directory.
59
60If you have syntax highlighting enabled, the different parts are highlighted
61so as to make it easier to spot them.
62
63You can use Normal mode Vim commands to move around in the text.  For example,
64move the cursor atop a file and press <Enter>; you will then be editing that
65file.  To go back to the browser use ":edit ." again, or use ":Explore".
66CTRL-O also works.
67
68Try using <Enter> while the cursor is atop a directory name.  The result is
69that the file browser moves into that directory and displays the items found
70there.  Pressing <Enter> on the first directory "../" moves you one level
71higher.  Pressing "-" does the same thing, without the need to move to the
72"../" item first.
73
74You can press <F1> to get help on the things you can do in the netrw file
75browser.  This is what you get: >
76
77    9. Directory Browsing	 netrw-browse   netrw-dir   netrw-list   netrw-help 
78
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|
96     	 q................Listing Bookmarks and History..............|netrw-q|
97     	 r................Reversing Sorting Order....................|netrw-r|
98<    	(etc)
99
100The <F1> key thus brings you to a netrw directory browsing contents help page.
101It's a regular help page; use the usual |CTRL-]| to jump to tagged help items
102and |CTRL-O| to jump back.
103
104To select files for display and editing: (with the cursor is atop a filename)
105
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
113The following normal-mode commands may be used to control the browser display:
114
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
122As a sampling of extra normal-mode commands:
123
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
134One may also use command mode; again, just a sampling:
135
136	:Explore [directory]	Browse specified/current directory
137	:NetrwSettings		A comprehensive list of your current netrw
138				settings with help linkage.
139
140The netrw browser is not limited to just your local machine; one may use
141urls such as:    (that trailing / is important)
142
143	:Explore ftp://somehost/path/to/dir/
144	:e scp://somehost/path/to/dir/
145
146See |netrw-browse| for more.
147
148==============================================================================
149*22.2*	The current directory
150
151Just like the shell, Vim has the concept of a current directory.  Suppose you
152are 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
159To avoid much of the typing, do this: >
160
161	:cd VeryLongFileName
162	:edit file1.txt
163	:edit file2.txt
164	:edit file3.txt
165
166The ":cd" command changes the current directory.  You can see what the current
167directory is with the ":pwd" command: >
168
169	:pwd
170	/home/Bram/VeryLongFileName
171
172Vim remembers the last directory that you used.  Use "cd -" to go back to it.
173Example: >
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
188WINDOW LOCAL DIRECTORY
189
190When you split a window, both windows use the same current directory.  When
191you want to edit a number of files somewhere else in the new window, you can
192make it use a different directory, without changing the current directory in
193the 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
205So long as no ":lcd" command has been used, all windows share the same current
206directory.  Doing a ":cd" command in one window will also change the current
207directory of the other window.
208   For a window where ":lcd" has been used a different current directory is
209remembered.  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
211directory, it will go back to using the shared directory.
212
213==============================================================================
214*22.3*	Finding a file
215
216You are editing a C program that contains this line:
217
218	#include "inits.h" ~
219
220You want to see what is in that "inits.h" file.  Move the cursor on the name
221of the file and type: >
222
223	gf
224
225Vim will find the file and edit it.
226   What if the file is not in the current directory?  Vim will use the 'path'
227option to find the file.  This option is a list of directory names where to
228look for your file.
229   Suppose you have your include files located in "c:/prog/include".  This
230command will add it to the 'path' option: >
231
232	:set path+=c:/prog/include
233
234This directory is an absolute path.  No matter where you are, it will be the
235same place.  What if you have located files in a subdirectory, below where the
236file is?  Then you can specify a relative path name.  This starts with a dot:
237>
238	:set path+=./proto
239
240This tells Vim to look in the directory "proto", below the directory where the
241file in which you use "gf" is.  Thus using "gf" on "inits.h" will make Vim
242look for "proto/inits.h", starting in the directory of the file.
243   Without the "./", thus "proto", Vim would look in the "proto" directory
244below the current directory.  And the current directory might not be where the
245file that you are editing is located.
246
247The 'path' option allows specifying the directories where to search for files
248in many more ways.  See the help on the 'path' option.
249   The 'isfname' option is used to decide which characters are included in the
250file name, and which ones are not (e.g., the " character in the example
251above).
252
253When you know the file name, but it's not to be found in the file, you can
254type it: >
255
256	:find inits.h
257
258Vim will then use the 'path' option to try and locate the file.  This is the
259same as the ":edit" command, except for the use of 'path'.
260
261To open the found file in a new window use CTRL-W f instead of "gf", or use
262":sfind" instead of ":find".
263
264
265A nice way to directly start Vim to edit a file somewhere in the 'path': >
266
267	vim "+find stdio.h"
268
269This finds the file "stdio.h" in your value of 'path'.  The quotes are
270necessary to have one argument |-+c|.
271
272==============================================================================
273*22.4*	The buffer list
274
275The Vim editor uses the term buffer to describe a file being edited.
276Actually, a buffer is a copy of the file that you edit.  When you finish
277changing the buffer, you write the contents of the buffer to the file.
278Buffers not only contain file contents, but also all the marks, settings, and
279other stuff that goes with it.
280
281
282HIDDEN BUFFERS
283
284Suppose you are editing the file one.txt and need to edit the file two.txt.
285You could simply use ":edit two.txt", but since you made changes to one.txt
286that won't work.  You also don't want to write one.txt yet.  Vim has a
287solution for you: >
288
289	:hide edit two.txt
290
291The buffer "one.txt" disappears from the screen, but Vim still knows that you
292are editing this buffer, so it keeps the modified text.  This is called a
293hidden buffer: The buffer contains text, but you can't see it.
294   The argument of ":hide" is another command.  ":hide" makes that command
295behave as if the 'hidden' option was set.  You could also set this option
296yourself.  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
298without making sure you have saved all the buffers.
299
300
301INACTIVE BUFFERS
302
303   When a buffer has been used once, Vim remembers some information about it.
304When it is not displayed in a window and it is not hidden, it is still in the
305buffer 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
311The inactive buffers are remembered, because Vim keeps information about them,
312like marks.  And remembering the file name is useful too, so that you can see
313which files you have edited.  And edit them again.
314
315
316LISTING BUFFERS
317
318View the buffer list with this command: >
319
320	:buffers
321
322A command which does the same, is not so obvious to list buffers, but is much
323shorter to type: >
324
325	:ls
326
327The output could look like this:
328
329  1 #h	"help.txt"			line 62 ~
330  2 %a+	"usr_21.txt"			line 1 ~
331  3	"usr_toc.txt"			line 1 ~
332
333The first column contains the buffer number.  You can use this to edit the
334buffer without having to type the name, see below.
335   After the buffer number come the flags.  Then the name of the file
336and 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.
342	  a	Buffer is loaded and displayed.
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
349EDITING A BUFFER
350
351You can edit a buffer by its number.  That avoids having to type the file
352name: >
353
354	:buffer 2
355
356But the only way to know the number is by looking in the buffer list.  You can
357use the name, or part of it, instead: >
358
359	:buffer help
360
361Vim will find the best match for the name you type.  If there is only one
362buffer 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
367This works with a name as well.
368
369
370USING THE BUFFER LIST
371
372You 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
379To remove a buffer from the list, use this command: >
380
381	:bdelete 3
382
383Again, this also works with a name.
384   If you delete a buffer that was active (visible in a window), that window
385will be closed.  If you delete the current buffer, the current window will be
386closed.  If it was the last window, Vim will find another buffer to edit.  You
387can'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
398Next chapter: |usr_23.txt|  Editing other files
399
400Copyright: see |manual-copyright|  vim:tw=78:ts=8:ft=help:norl:
401