Nvim :help
pages, generated
from source
using the tree-sitter-vimdoc parser.
:edit .Through the magic of autocommands and Vim scripts, the window will be filled with the contents of the directory. It looks like this:
<F1>
:help -:go up dir D:delete R:rename s:sort-by x:exec*.h
files,
*.c
files, etc)
5. How to get help (use the <F1>
key), and an abbreviated listing
of available commands
6. A listing of files, including "../", which allows one to list
the parent directory.<Enter>
; you will then be editing that
file. To go back to the browser use ":edit ." again, or use ":Explore".
CTRL-O also works.<Enter>
while the cursor is atop a directory name. The result is
that the file browser moves into that directory and displays the items found
there. Pressing <Enter>
on the first directory "../" moves you one level
higher. Pressing "-" does the same thing, without the need to move to the
"../" item first.<F1>
to get help on the things you can do in the netrw file
browser. This is what you get:9. Directory Browsing netrw-browse netrw-dir netrw-list netrw-help MAPS netrw-maps <F1>.............Help.......................................|netrw-help| <cr>.............Browsing...................................|netrw-cr| <del>............Deleting Files or Directories..............|netrw-delete| -................Going Up...................................|netrw--| a................Hiding Files or Directories................|netrw-a| mb...............Bookmarking a Directory....................|netrw-mb| gb...............Changing to a Bookmarked Directory.........|netrw-gb| cd...............Make Browsing Directory The Current Dir....|netrw-c| d................Make A New Directory.......................|netrw-d| D................Deleting Files or Directories..............|netrw-D| <c-h>............Edit File/Directory Hiding List............|netrw-ctrl-h| i................Change Listing Style.......................|netrw-i| <c-l>............Refreshing the Listing.....................|netrw-ctrl-l| o................Browsing with a Horizontal Split...........|netrw-o| p................Use Preview Window.........................|netrw-p| P................Edit in Previous Window....................|netrw-p| q................Listing Bookmarks and History..............|netrw-qb| r................Reversing Sorting Order....................|netrw-r|
<F1>
key thus brings you to a netrw directory browsing contents help page.
It's a regular help page; use the usual CTRL-] to jump to tagged help items
and CTRL-O to jump back.<enter>
Open the file in the current window. netrw-cr
o Horizontally split window and display file netrw-o
v Vertically split window and display file netrw-v
p Use the preview-window netrw-p
P Edit in the previous window netrw-P
t Open file in a new tab netrw-t: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 current directory is with the ":pwd" command:
:pwd /home/Bram/VeryLongFileNameVim remembers the last directory that you used. Use "cd -" to go back to it. Example:
:pwd /home/Bram/VeryLongFileName :cd /etc :pwd /etc :cd - :pwd /home/Bram/VeryLongFileName :cd - :pwd /etc
:pwd /home/Bram/VeryLongFileName :split :lcd /etc :pwd /etc CTRL-W w :pwd /home/Bram/VeryLongFileNameSo long as no
:lcd
command has been used, all windows share the same current
directory. Doing a :cd
command in one window will also change the current
directory of the other window.
For a window where :lcd
has been used a different current directory is
remembered. Using :cd
or :lcd
in other windows will not change it.
When using a :cd
command in a window that uses a different current
directory, it will go back to using the shared directory.:tcd
command. All the windows in
a tab page share this directory except for windows with a window-local
directory. Any new windows opened in this tab page will use this directory as
the current working directory. Using a :cd
command in a tab page will not
change the working directory of tab pages which have a tab local directory.
When the global working directory is changed using the :cd
command in a tab
page, it will also change the current tab page working directory.gfVim will find the file and edit it. What if the file is not in the current directory? Vim will use the 'path' option to find the file. This option is a list of directory names where to look for your file. Suppose you have your include files located in "c:/prog/include". This command will add it to the 'path' option:
:set path+=c:/prog/includeThis directory is an absolute path. No matter where you are, it will be the same place. What if you have located files in a subdirectory, below where the file is? Then you can specify a relative path name. This starts with a dot:
:set path+=./protoThis tells Vim to look in the directory "proto", below the directory where the file in which you use "gf" is. Thus using "gf" on "inits.h" will make Vim look for "proto/inits.h", starting in the directory of the file. Without the "./", thus "proto", Vim would look in the "proto" directory below the current directory. And the current directory might not be where the file that you are editing is located.
:find inits.hVim will then use the 'path' option to try and locate the file. This is the same as the ":edit" command, except for the use of 'path'.
CTRL-W
f instead of "gf", or use
":sfind" instead of ":find".vim "+find stdio.h"This finds the file "stdio.h" in your value of 'path'. The quotes are necessary to have one argument -+c.
:hide edit two.txtThe buffer "one.txt" disappears from the screen, but Vim still knows that you are editing this buffer, so it keeps the modified text. This is called a hidden buffer: The buffer contains text, but you can't see it. The argument of ":hide" is another command. ":hide" makes that command behave as if the 'hidden' option was set. You could also set this option yourself. The effect is that when any buffer is abandoned, it becomes hidden. Be careful! When you have hidden buffers with changes, don't exit Vim without making sure you have saved all the buffers.
:buffersA command which does the same, is not so obvious to list buffers, but is much shorter to type:
:lsThe output could look like this:
:buffer 2But the only way to know the number is by looking in the buffer list. You can use the name, or part of it, instead:
:buffer helpVim will find the best match for the name you type. If there is only one buffer that matches the name, it will be used. In this case "help.txt". To open a buffer in a new window:
:sbuffer 3This works with a name as well.
:bdelete 3Again, this also works with a name. If you delete a buffer that was active (visible in a window), that window will be closed. If you delete the current buffer, the current window will be closed. If it was the last window, Vim will find another buffer to edit. You can't be editing nothing!