Skip to content

Instantly share code, notes, and snippets.

@seanh
Last active November 10, 2024 02:18
Show Gist options
  • Save seanh/3c32f6d4f1e27669c4d8a1d3ce3c215b to your computer and use it in GitHub Desktop.
Save seanh/3c32f6d4f1e27669c4d8a1d3ce3c215b to your computer and use it in GitHub Desktop.
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

@archae0pteryx
Copy link

You should add a bunch more? Make an actual cheat sheet?. It would be helpful. I did learn that :E also opens netrw... I've been using :Ex forever and it's annoying! never thought there was another way... So thanks for that one! cheers.

@seanh
Copy link
Author

seanh commented Nov 11, 2023

@archae0pteryx You're weclome! Yeah I'd like to turn this into a more complete guide / cheatsheet. Maybe one day

@SrslyJosh
Copy link

Going to add this here, because it doesn't seem obvious:

To close a netrw buffer:

  1. Switch to another buffer
  2. Find the netrw buffer's number with :ls
  3. Run either :bdelete<number> (:bd<number> for short) or :bwipe (:bw` for short)

For some reason, it seems like you cannot actually delete/wipe a netrw buffer while it is active, you've gotta switch to a different buffer. (At least with my versions of nvim and vinegar.)

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