usr_22.txt ForVim version 9.2. Last change: 2026 Feb 14 VIM USER MANUALbyBramMoolenaar Finding the file to editFiles can be found everywhere. So howdo you find them? Vim offersvariousways to browse the directory tree. There are commands to jump toa file thatis mentioned in another. And Vim remembers which files have been editedbefore.22.1 The file browser22.2 The current directory22.3 Findinga file22.4 The bufferlist Next chapter:usr_23.txt Editing other files Previous chapter:usr_21.txt Go away and come backTable of contents:usr_toc.txt==============================================================================22.1 The file browserVim hasaplugin that makesit possible to edita directory. Try this::edit .Through the magic ofautocommands and Vim scripts, thewindow will be filledwith the contents of the directory. It looks like this (slightly cleaned upso thatit fits within 78 chars): " ========================================================================== " Netrw Directory Listing (netrw v184) " /path/to/vim/runtime/doc " Sorted by name " Sort sequence: [\/]$,*,\(\.bak\|\~\|\.o\|\.h\|\.info\|\.swp\)[*@]\=$ " Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:special " ========================================================================== ../ ./ check/ Makefile autocmd.txt change.txt eval.txt filetype.txt help.txt.infoYou can see these items:1. The name of the browsing tool and its version number2. The name of the browsing directory3. Themethod ofsorting (may be by name, time, or size)4. How names are to be sorted (directories first, then by extension, etc.)5. How to gethelp (the<F1> key), and an abridgedlist of available commands6.A listing of files, including "../" (it willlist the parent directory).If you havesyntax highlighting enabled, the different parts are highlightedsoas to makeit easier to spot them.You can useNormal mode Vim commands to move around in the text. For example,move the cursor atopa file and press<Enter>; you will then be editing thatfile. Togo back to the browser use ":edit." again, or use ":Explore".CTRL-O also works.Try using<Enter> while the cursoris atopa directory name. The resultisthat the file browser moves into that directory and displays the items foundthere. Pressing<Enter> on the first directory "../" moves you one levelhigher. Pressing "-" does the same thing, without the need to move to the"../" item first.You can press<F1> to gethelp on the things you cando in thenetrw filebrowser. Thisis what you get: QUICK HELPnetrw-quickhelp (Use ctrl-] to select a topic)Intro to Browsing...............................netrw-intro-browse Quick Reference: Maps.........................netrw-quickmap Quick Reference: Commands.....................netrw-browse-cmdsThe<F1> key thus brings you toanetrw directory browsing contentshelp page.It'sa regularhelp page; use the usualCTRL-] to jump to taggedhelp itemsandCTRL-O to jump back. So, if youCTRL-] onnetrw-quickmap you willjump to this:netrw-quickmap netrw-quickmaps QUICK REFERENCE: MAPSnetrw-browse-maps ------------------------ MapQuick ExplanationLink ------------------------ <F1>Causes Netrw to issue help <cr>Netrw will enter the directory or read the file netrw-cr <del>Netrw will attempt to remove the file/directory netrw-del (etc.)To select files for display and editing (with the cursor atopa filename): oEnter the file/directory under the cursor in a new netrw-obrowser window. A horizontal split is used. OObtain a file specified by cursor netrw-O pPreview the file netrw-p PBrowse in the previously used window netrw-P vEnter the file/directory under the cursor in a new netrw-vbrowser window. A vertical split is used.The following normal-mode commands may be used tocontrol the browser display: iCycle between thin, long, wide, and tree listings netrw-i rReverse sorting order netrw-r sSelect sorting style: by name, time, or file size netrw-sAsa sampling of extra normal-mode commands: cdMake browsing directory the current directory netrw-cd DAttempt to remove the file(s)/directory(ies) netrw-D gbGo to previous bookmarked directory netrw-gb mbBookmark current directory netrw-mb RRename the designated file(s)/directory(ies) netrw-ROne may also use command mode; again, justa sampling: :Explore[!] [dir] Explore directory of current file......netrw-explore :Hexplore[!] [dir] Horizontal Split & Explore.............netrw-exploreThenetrw browseris not limited to just your local machine; one may use URLssuch as::Explore ftp://somehost/path/to/dir/:e scp://somehost/path/to/dir/Note: The trailing "/"is important.Seenetrw-browse for more.==============================================================================22.2 The current directoryJust like the shell, Vim has the concept ofa current directory. Suppose youare in yourhome directory and want to edit several files ina directory"VeryLongFileName". You could do::edit VeryLongFileName/file1.txt:edit VeryLongFileName/file2.txt:edit VeryLongFileName/file3.txtTo avoid much of the typing,do this::cd VeryLongFileName:edit file1.txt:edit file2.txt:edit file3.txtThe ":cd" command changes the current directory. You can see what the currentdirectoryis with the ":pwd" command::pwd/home/Bram/VeryLongFileNameVim remembers the last directory that you used. Use "cd-" togo back to it.Example::pwd/home/Bram/VeryLongFileName:cd /etc:pwd/etc:cd -:pwd/home/Bram/VeryLongFileName:cd -:pwd/etcWINDOW LOCAL DIRECTORYWhen you splita window, bothwindows use the same current directory. Whenyou want to edita number of files somewhere else in the new window, you canmakeit usea different directory, withoutchanging the current directory inthe other window. Thisis calleda local directory.:pwd/home/Bram/VeryLongFileName:split:lcd /etc:pwd/etcCTRL-W w:pwd/home/Bram/VeryLongFileNameSo longas no:lcd command has been used, allwindows share the same currentdirectory. Doinga:cd command in onewindow will also change the currentdirectory of the other window. Forawindow where:lcd has been useda different current directoryisremembered. Using:cd or:lcd in otherwindows will not change it. When usinga:cd command inawindow that usesa different currentdirectory,it willgo back to using the shared directory.TAB LOCAL DIRECTORYWhen you opena newtab page,it uses the directory of thewindow in theprevioustab page from which the newtab page was opened. You can change thedirectory of the currenttab page using the:tcd command. All thewindowsinatab page share this directory except forwindows witha window-localdirectory. Any newwindows opened in thistab page will use this directoryasthe current working directory. Usinga:cd command inatab page will notchange the working directory oftab pages which haveatab local directory.When the global working directoryis changed using the:cd command inatabpage,it will also change the currenttab page working directory.==============================================================================22.3 Findinga fileYou are editingaC program that contains this line:#include "inits.h"You want to see whatis in that "inits.h" file. Move the cursor on the nameof the file and type:gfVim will find the file and edit it. What if the fileis not in the current directory? Vim will use the'path'option to find the file. This optionisalist of directory names where tolook for your file. Suppose you have your include files located in "c:/prog/include". Thiscommand will addit to the'path' option::set path+=c:/prog/includeThis directoryis an absolute path. No matter where you are,it will be thesame place. What if you have located files ina subdirectory, below where thefile is? Then you can specifya relative path name. This starts witha dot::set path+=./protoThis tells Vim to look in the directory "proto", below the directory where thefile in which you use "gf" is. Thus using "gf" on "inits.h" will make Vimlook for "proto/inits.h",starting in the directory of the file. Without the "./", thus "proto", Vim would look in the "proto" directorybelow the current directory. And the current directory might not be where thefile that you are editingis located.The'path' option allows specifying the directories where to search for filesin many more ways. See thehelp on the'path' option. The'isfname' optionis used to decide which characters are included in thefile name, and which ones are not (e.g., the " character in the exampleabove).When you know the file name, but it's not to be found in the file, you cantype it::find inits.hVim will then use the'path' option to try and locate the file. Thisis thesameas the ":edit" command, except for the use of'path'.To open the found file ina newwindow useCTRL-Wf instead of "gf", or use":sfind" instead of ":find".A nice way to directly start Vim to edita file somewhere in the'path':vim "+find stdio.h"This finds the file "stdio.h" in your value of'path'. Thequotes arenecessary to have one argument-+c.==============================================================================22.4 The bufferlistThe Vim editor uses the term buffer to describea file being edited.Actually,a bufferisa copy of the file that you edit. When you finishchanging the buffer, you write the contents of the buffer to the file.Buffers not only contain file contents, but also all the marks, settings, andother stuff that goes with it.HIDDEN BUFFERSSuppose you are editing the file one.txt and need to edit the file two.txt.You could simply use ":edit two.txt", but since you made changes to one.txtthat won't work. You also don't want to write one.txt yet. Vim hasasolution for you::hide edit two.txtThe buffer "one.txt" disappears from the screen, but Vim still knows that youare editing this buffer, soit keeps the modified text. Thisis calledahidden buffer: The buffer contains text, but you can't see it. The argument of ":hide"is another command. ":hide" makes that commandbehaveas if the'hidden' option was set. You could also set this optionyourself. The effectis that when any bufferis abandoned,it becomes hidden. Be careful! When you have hiddenbuffers with changes, don't exit Vimwithout making sure you have saved all the buffers.INACTIVE BUFFERSWhena buffer has been used once, Vim remembers some information about it.Whenitis not displayed inawindow anditis not hidden,itis still in thebuffer list. Thisis called an inactive buffer. Overview:ActiveAppears ina window, text loaded.HiddenNot ina window, text loaded.InactiveNot ina window, no text loaded.The inactivebuffers are remembered, because Vim keeps information about them,like marks. And remembering the file nameis useful too, so that you can seewhich files you have edited. And edit them again.LISTING BUFFERSView the bufferlist with this command::buffersA command which does the same,is not so obvious tolist buffers, butis muchshorter to type::lsThe output could look like this: 1 #h "help.txt"line 62 2 %a + "usr_21.txt"line 1 3 "usr_toc.txt"line 1The first column contains the buffer number. You can use this to edit thebuffer without having to type the name, see below. After the buffer number come the flags. Then the name of the fileand the line number where the cursor was the last time. The flags that can appear are these (from left to right):uBufferis unlistedunlisted-buffer.%Current buffer.#Alternate buffer.aBufferis loaded and displayed.hBufferis loaded but hidden.=Bufferis read-only.-Bufferis not modifiable, the'modifiable' optionis off.+Buffer has been modified.EDITING A BUFFERYou can edita buffer by its number. That avoids having to type the filename::buffer 2But the only way to know the numberis by looking in the buffer list. You canuse the name, or part of it, instead::buffer helpVim will find the best match for the name you type. If thereis only onebuffer that matches the name,it will be used. In thiscase "help.txt". To opena buffer ina new window::sbuffer 3This works witha nameas well.USING THE BUFFER LISTYou can move around in the bufferlist with these commands::bnextgo to next buffer:bpreviousgo to previous buffer:bfirstgo to the first buffer:blastgo to the last bufferTo removea buffer from the list, use this command::bdelete 3Again, this also works witha name. If you deletea buffer that was active (visible ina window), thatwindowwill be closed. If you delete the current buffer, the currentwindow will beclosed. Ifit was the last window, Vim will find another buffer to edit. Youcan't be editing nothing!Note: Even after removing the buffer with ":bdelete" Vim stillremembers it. It's actually made "unlisted",it no longer appears inthelist from ":buffers". The ":buffers!" command willlist unlistedbuffers (yes, Vim cando the impossible). To really make Vim forgetabouta buffer, use ":bwipe". Also see the'buflisted' option.==============================================================================Next chapter:usr_23.txt Editing other filesCopyright: seemanual-copyright vim:tw=78:ts=8:noet:ft=help:norl: