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 (slightly cleaned up so that it 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.info
<F1> key), and an abridged list of available commands
<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:
QUICK HELP netrw-quickhelp
(Use ctrl-] to select a topic)
Intro to Browsing...............................netrw-intro-browse
Quick Reference: Maps.........................netrw-quickmap
Quick Reference: Commands.....................netrw-browse-cmds<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. So, if you CTRL-] on netrw-quickmap you will
jump to this:
netrw-quickmap netrw-quickmaps
QUICK REFERENCE: MAPS netrw-browse-maps
--- ----------------- ----
Map Quick Explanation Link
--- ----------------- ----
<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-delo Enter the file/directory under the cursor in a new netrw-o
browser window. A horizontal split is used.
O Obtain a file specified by cursor netrw-O
p Preview the file netrw-p
P Browse in the previously used window netrw-P
v Enter the file/directory under the cursor in a new netrw-v
browser window. A vertical split is used.i Cycle between thin, long, wide, and tree listings netrw-i r Reverse sorting order netrw-r s Select sorting style: by name, time, or file size netrw-s
cd Make browsing directory the current directory netrw-cd D Attempt to remove the file(s)/directory(ies) netrw-D gb Go to previous bookmarked directory netrw-gb mb Bookmark current directory netrw-mb R Rename the designated file(s)/directory(ies) netrw-R
:Explore[!] [dir] Explore directory of current file......netrw-explore :Hexplore[!] [dir] Horizontal Split & Explore.............netrw-explore
:Explore ftp://somehost/path/to/dir/ :e scp://somehost/path/to/dir/
: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!