Using Vim as a File Browser

One of the lesser-known features of Vim is its file browsing capabilities, which are very useful if you want to edit or look at a file that’s either in another directory or that you’ve forgotten the filename or location for. When we hit Ctrl+O in a graphical text editor like Notepad, it brings up a temporary window that lets us browse our filesystem, and often we want our text-mode editor whether that’s Vim or something else to have the same thing. Well, it turns out Vim allows you to do just that, and in this tutorial I will show you how.

There are three commands in Vim that allow you to browse files within the text editor. They are Explore, Vexplore, and Sexplore. Explore changes the current window to a file browser window, Vexplore splits the current window vertically and shows your files in a sidebar, and Sexplore splits the current window horizontally and lists the files up top.

Here’s what you get when you type :Explore in Vim:

Full-screen Explore file browsing window in Vim

Here’s what you get when you type :Vexplore:

Vexplore file browsing window in Vim

And here’s what you get when you type :Sexplore:

Sexplore file browsing window in Vim

These are all functionally the same but with different layouts. You can use the regular Vim movement keys such as J and K to move up and down the list of files. There are also special keystroke commands that you can use within the file browsing window, which are listed up top. Moving the cursor over a filename and hitting Enter opens that file for editing in that window. It does not, however, add it to the buffer of open files in Vim, so if you close that window, you can’t just go back and edit the file using Vim’s native :n and :N commands. You will have to explicitly open it again.

One thing that I often use Explore windows for, aside from regular file browsing within Vim, is getting rid of swap file left behind by system crashes. The Explore window conveniently shows all of these, and you can move the cursor over the swap file and type Shift+D to delete it.


2 thoughts on “Using Vim as a File Browser

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s