robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
6576e75eeb
master
1*usr_22.txt* Nvim 2 3 4 VIM USER MANUAL by Bram Moolenaar 5 6 7 Finding the file to edit 8 9 10Files can be found everywhere. So how do you find them? Vim offers various 11ways to browse the directory tree. There are commands to jump to a file that 12is mentioned in another. And Vim remembers which files have been edited 13before. 14 15|22.1| The file browser 16|22.2| The current directory 17|22.3| Finding a file 18|22.4| The buffer list 19 20 Next chapter: |usr_23.txt| Editing other files 21 Previous chapter: |usr_21.txt| Go away and come back 22Table of contents: |usr_toc.txt| 23 24============================================================================== 25*22.1* The file browser 26 27Nvim can edit a directory. Try this: > 28 29 :edit . 30 31The window will be filled with a directory listing. It looks like this: > 32 33 check/ 34 autoload.txt 35 change.txt 36 eval.txt 37 filetype.txt 38 help.txt 39< 40 41Directories end in "/". 42 43You can use Normal mode Vim commands to move around in the text. For example, 44move the cursor atop a file and press <Enter>; you will then be editing that 45file. Press "-" to open the parent directory of the current file or 46directory. CTRL-O also works. 47 48Try using <Enter> while the cursor is atop a directory name. The result is 49that the file browser moves into that directory and displays the items found 50there. Pressing "-" moves you one level higher, to the parent directory. "R" 51reloads the listing. 52 53The directory listing opened by ":edit ." is a viewer, not a file manager. For 54netrw's browser, file operations, and remote directories, use ":Explore": > 55 56 :Explore . 57< 58 59The netrw browser may also use URLs such as: > 60 61 :Explore ftp://somehost/path/to/dir/ 62 :e scp://somehost/path/to/dir/ 63< 64 Note: The trailing "/" is important. 65 66See |netrw-browse| for more. 67 68============================================================================== 69*22.2* The current directory 70 71Just like the shell, Vim has the concept of a current directory. Suppose you 72are in your home directory and want to edit several files in a directory 73"VeryLongFileName". You could do: > 74 75 :edit VeryLongFileName/file1.txt 76 :edit VeryLongFileName/file2.txt 77 :edit VeryLongFileName/file3.txt 78 79To avoid much of the typing, do this: > 80 81 :cd VeryLongFileName 82 :edit file1.txt 83 :edit file2.txt 84 :edit file3.txt 85 86The ":cd" command changes the current directory. You can see what the current 87directory is with the ":pwd" command: > 88 89 :pwd 90 /home/Bram/VeryLongFileName 91 92Vim remembers the last directory that you used. Use "cd -" to go back to it. 93Example: > 94 95 :pwd 96 /home/Bram/VeryLongFileName 97 :cd /etc 98 :pwd 99 /etc 100 :cd - 101 :pwd 102 /home/Bram/VeryLongFileName 103 :cd - 104 :pwd 105 /etc 106 107 108WINDOW LOCAL DIRECTORY 109 110When you split a window, both windows use the same current directory. When 111you want to edit a number of files somewhere else in the new window, you can 112make it use a different directory, without changing the current directory in 113the other window. This is called a local directory. > 114 115 :pwd 116 /home/Bram/VeryLongFileName 117 :split 118 :lcd /etc 119 :pwd 120 /etc 121 CTRL-W w 122 :pwd 123 /home/Bram/VeryLongFileName 124 125So long as no `:lcd` command has been used, all windows share the same current 126directory. Doing a `:cd` command in one window will also change the current 127directory of the other window. 128 For a window where `:lcd` has been used a different current directory is 129remembered. Using `:cd` or `:lcd` in other windows will not change it. 130 When using a `:cd` command in a window that uses a different current 131directory, it will go back to using the shared directory. 132 133 134TAB LOCAL DIRECTORY 135 136When you open a new tabpage, it uses the directory of the window in the 137previous tabpage from which the new tabpage was opened. You can change the 138directory of the current tabpage using the `:tcd` command. All the windows 139in a tabpage share this directory except for windows with a window-local 140directory. Any new windows opened in this tabpage will use this directory as 141the current working directory. Using a `:cd` command in a tabpage will not 142change the working directory of tabpages which have a tab local directory. 143When the global working directory is changed using the `:cd` command in a tab 144page, it will also change the current tabpage working directory. 145 146 147============================================================================== 148*22.3* Finding a file 149 150You are editing a C program that contains this line: 151 152 #include "inits.h" ~ 153 154You want to see what is in that "inits.h" file. Move the cursor on the name 155of the file and type: > 156 157 gf 158 159Vim will find the file and edit it. 160 What if the file is not in the current directory? Vim will use the 'path' 161option to find the file. This option is a list of directory names where to 162look for your file. 163 Suppose you have your include files located in "c:/prog/include". This 164command will add it to the 'path' option: > 165 166 :set path+=c:/prog/include 167 168This directory is an absolute path. No matter where you are, it will be the 169same place. What if you have located files in a subdirectory, below where the 170file is? Then you can specify a relative path name. This starts with a dot: 171> 172 :set path+=./proto 173 174This tells Vim to look in the directory "proto", below the directory where the 175file in which you use "gf" is. Thus using "gf" on "inits.h" will make Vim 176look for "proto/inits.h", starting in the directory of the file. 177 Without the "./", thus "proto", Vim would look in the "proto" directory 178below the current directory. And the current directory might not be where the 179file that you are editing is located. 180 181The 'path' option allows specifying the directories where to search for files 182in many more ways. See the help on the 'path' option. 183 The 'isfname' option is used to decide which characters are included in the 184file name, and which ones are not (e.g., the " character in the example 185above). 186 187When you know the file name, but it's not to be found in the file, you can 188type it: > 189 190 :find inits.h 191 192Vim will then use the 'path' option to try and locate the file. This is the 193same as the ":edit" command, except for the use of 'path'. 194 195To open the found file in a new window use CTRL-W f instead of "gf", or use 196":sfind" instead of ":find". 197 198 199A nice way to directly start Vim to edit a file somewhere in the 'path': > 200 201 vim "+find stdio.h" 202 203This finds the file "stdio.h" in your value of 'path'. The quotes are 204necessary to have one argument |-+c|. 205 206============================================================================== 207*22.4* The buffer list 208 209The Vim editor uses the term buffer to describe a file being edited. 210Actually, a buffer is a copy of the file that you edit. When you finish 211changing the buffer, you write the contents of the buffer to the file. 212Buffers not only contain file contents, but also all the marks, settings, and 213other stuff that goes with it. 214 215 216HIDDEN BUFFERS 217 218Suppose you are editing the file one.txt and need to edit the file two.txt. 219You could simply use ":edit two.txt", but since you made changes to one.txt 220that won't work. You also don't want to write one.txt yet. Vim has a 221solution for you: > 222 223 :hide edit two.txt 224 225The buffer "one.txt" disappears from the screen, but Vim still knows that you 226are editing this buffer, so it keeps the modified text. This is called a 227hidden buffer: The buffer contains text, but you can't see it. 228 The argument of ":hide" is another command. ":hide" makes that command 229behave as if the 'hidden' option was set. You could also set this option 230yourself. The effect is that when any buffer is abandoned, it becomes hidden. 231 Be careful! When you have hidden buffers with changes, don't exit Vim 232without making sure you have saved all the buffers. 233 234 235INACTIVE BUFFERS 236 237When a buffer has been used once, Vim remembers some information about it. 238When it is not displayed in a window and it is not hidden, it is still in the 239buffer list. This is called an inactive buffer. Overview: 240 241 Active Appears in a window, text loaded. 242 Hidden Not in a window, text loaded. 243 Inactive Not in a window, no text loaded. 244 245The inactive buffers are remembered, because Vim keeps information about them, 246like marks. And remembering the file name is useful too, so that you can see 247which files you have edited. And edit them again. 248 249 250LISTING BUFFERS 251 252View the buffer list with this command: > 253 254 :buffers 255 256A command which does the same, is not so obvious to list buffers, but is much 257shorter to type: > 258 259 :ls 260 261The output could look like this: 262 263 1 #h "help.txt" line 62 ~ 264 2 %a + "usr_21.txt" line 1 ~ 265 3 "usr_toc.txt" line 1 ~ 266 267The first column contains the buffer number. You can use this to edit the 268buffer without having to type the name, see below. 269 After the buffer number come the flags. Then the name of the file 270and the line number where the cursor was the last time. 271 The flags that can appear are these (from left to right): 272 273 u Buffer is unlisted |unlisted-buffer|. 274 % Current buffer. 275 # Alternate buffer. 276 a Buffer is loaded and displayed. 277 h Buffer is loaded but hidden. 278 = Buffer is read-only. 279 - Buffer is not modifiable, the 'modifiable' option is off. 280 + Buffer has been modified. 281 282 283EDITING A BUFFER 284 285You can edit a buffer by its number. That avoids having to type the file 286name: > 287 288 :buffer 2 289 290But the only way to know the number is by looking in the buffer list. You can 291use the name, or part of it, instead: > 292 293 :buffer help 294 295Vim will find the best match for the name you type. If there is only one 296buffer that matches the name, it will be used. In this case "help.txt". 297 To open a buffer in a new window: > 298 299 :sbuffer 3 300 301This works with a name as well. 302 303 304USING THE BUFFER LIST 305 306You can move around in the buffer list with these commands: 307 308 :bnext go to next buffer 309 :bprevious go to previous buffer 310 :bfirst go to the first buffer 311 :blast go to the last buffer 312 313To remove a buffer from the list, use this command: > 314 315 :bdelete 3 316 317Again, this also works with a name. 318 If you delete a buffer that was active (visible in a window), that window 319will be closed. If you delete the current buffer, the current window will be 320closed. If it was the last window, Vim will find another buffer to edit. You 321can't be editing nothing! 322 323 Note: Even after removing the buffer with ":bdelete" Vim still 324 remembers it. It's actually made "unlisted", it no longer appears in 325 the list from ":buffers". The ":buffers!" command will list unlisted 326 buffers (yes, Vim can do the impossible). To really make Vim forget 327 about a buffer, use ":bwipe". Also see the 'buflisted' option. 328 329============================================================================== 330 331Next chapter: |usr_23.txt| Editing other files 332 333Copyright: see |manual-copyright| 334 335vim:tw=78:ts=8:noet:ft=help:norl: