How to View Files and Directories Within Vim Editor

At face value, Vim is regarded as an exceptional text editor. However, there is more to this supposed ‘text editor‘ when it comes to implementing some file management footprints.

Vim might not seem user-friendly in the eyes of a new Linux user but once you get a grip on its usage, there is no turning back. This article will walk us through the use of Vim as a file manager, but first, we will appreciate some unique features that classify it as a reputable text editor.

Some Notable Vim Features

It is worth mentioning the following unique features associated with Vim editor.

Vim Help

The following command ensures that you are never stuck while using Vim. Through its extensive online help system, users have access to the needed Vim-related resources.

:help

Optional Features

Vim does not automatically enable all its features. It is up to the user to turn on the feature that fits their text editing need. To turn on and explore these features, you first need to create the $HOME/.vimrc file.

$ nano $HOME/.vimrc

Multiple Windows

If you need the split the current window you are working on into two, implement the vim command:

:split

Afterward, the command Ctrl-w k can be used to move the cursor down a window and Ctrl-w j can be used to move the cursor up a window.

Supposing the below Vim command is executed while working on another file, the Vim window will split to enable the editing of another referenced file.

:split your_file.txt 

To quit a window, we will use the usual Vim command:

:q!

Make Command

If you have a Makefile of a program you are working on, you can compile it under Vim with the command:

:make

To fix an error on your program file, navigate to the erroneous line(s) with the vim command:

:cn

To preview the current error message:

:cc

Word Completion

When keying in a partial phrase in Vim, use ^P for previous match word completion and ^N for next matching word completion.

Install Vim Editor in Linux

The vim installation guide on various Linux operation system distributions is as follows:

$ sudo apt install vim            [On Debian, Ubuntu and Mint]
$ sudo yum install vim            [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
$ sudo emerge -a app-editors/vim  [On Gentoo Linux]
$ sudo pacman -S vim              [On Arch Linux]
$ sudo zypper install vim         [On OpenSUSE]    

Using Vim to Browse/Explore Directories

First, launch Vim on your Linux operating system.

$ vim

The next step is to access the file explorer window, this can be done by executing the following vim command:

:Explore
Vim Explore File Manager
Vim Explorer File Manager

Hit [Enter] on your keyboard to explore Linux files and directories as shown:

Vim Directory Listing
Vim Directory Listing

From here, you can use the search panel or the keyboard arrow key to navigate to the targeted file.

Vim File Editing
Vim File Editing

Vim also provides Quick Help shortcut keys (as per the following screen capture) to help with the usage of file explorer.

Vim File Explorer Usage
Vim File Explorer Usage

Vim’s file exploration features make it easy to access different files from the terminal window instead of using the traditional approach:

$ vim file_to_open.txt

For more vim tips, read the following articles:

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.