Skip to content

Instantly share code, notes, and snippets.

@seanh
Last active February 19, 2023 01:53
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Netrw Cheatsheet (Vim's Built-in Directory Browser)

Netrw Cheatsheet (Vim's File Browser)

See also:

  • vinegar.vim, which makes - open netrw in the directory of the current file, with the cursor on the current file (and pressing - again goes up a directory). Vinegar also hides a bunch of junk that's normally at the top of netrw windows, changes the default order of files, and hides files that match wildignore.

    With vinegar, . in netrw opens Vim's command line with the path to the file under the cursor at the end of the command. ! does the same but also prepends ! at the start of the command. y. copies the absolute path of the file under the cursor. ~ goes to your home dir. Ctrl+6 goes back to the file (buffer) that you had open before you opened netrw.

To launch netrw:

  • Run vim with a directory as the command-line argument
  • :edit path/to/a/directory Enter (or :e <path/to/a/directory)
  • :e . to open the current working directory
  • :Explore or :Eopens netrw in the directory of the current file
  • :Sexplore or :Sex launches netrw in a new split window below the current window (:split . or :sp . will do the same, but open the current working directory instead of the directory of the current file)
  • :Vexplore or :Vex launches netrw in a new split window left of the current window (:vsplit . or :vs . will do the same, but open the current working directory instead of the directory of the current file, and to the right instead of to the left for some reason)

You can use all the normal vim movement commands to move around within a netrw buffer, including search! And you Enter to open the file or directory under the cursor.

Other netrw commands:

  • % creates a new file (not saved to the filesystem until you save it)
  • d creates a new directory (immediately)
  • See netrw's quick help menu (I) for deleting and renaming files

See Also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment