Netrw Vim Nav Basics

Mon, Jan 23, 2023 2-minute read

Netrw is a built-in plugin in Vim that lets you explore filesystems and network protocols such as ssh, ftp, http, etc. It’s a highly useful tool for browsing your local files or remote servers right from your Vim editor. Here’s how you can use it:

  1. To open Netrw:

    You can open netrw by typing :Explore, :E or :Ex from within Vim. This will open a file explorer in the current directory.

  2. To navigate in Netrw:

    • You can move up and down the file list using the arrow keys or j and k.
    • Press Enter or o to open a file or directory.
    • Press - to move up to the parent directory.
  3. Creating, renaming, and deleting files:

    • To create a directory, press d and enter the directory name.
    • To create a file, press % and enter the file name.
    • To rename a file or directory, place the cursor over it, press R, and enter the new name.
    • To delete a file or directory, place the cursor over it and press D.
  4. To navigate between multiple directories:

    You can split the screen into multiple windows, each viewing a different directory:

    • :Vex or :Vexplore to open a vertical split
    • :Sex or :Sexplore to open a horizontal split
    • :Te or :Texplore to open in a new tab
  5. Accessing remote directories:

    You can open remote directories by typing the following command:

    • :e scp://user@host//path/to/directory for SSH
    • :e ftp://user@host/path/to/directory for FTP

    You’ll need to replace user, host, and /path/to/directory with the username, host address, and path of the directory you want to open, respectively.

  6. Sorting files:

    • Press s to sort files by name, date, size, or extension.
  7. File marking:

    • Press mf to mark a file.
    • Press mu to unmark a file.
    • Press ma to mark all files.
    • Press mr to remove all marks.

These are the basic features of netrw, but there are many more features you can discover by typing :help netrw within Vim, which will open up the full netrw documentation.

Remember that some functionality of netrw, like navigating remote systems, will require that you have the necessary packages installed on your system, like ssh for accessing remote systems via scp.