DEV Community

Cover image for A Quick Guide to the Vim Text Editor
Harvey
Harvey

Posted on

A Quick Guide to the Vim Text Editor

Vim is a text editor which is highly efficient. It is an improved variant of the vi editor, that is distributed with UNIX systems.

Vim is often called a "programmer's editor," and so useful for programming that many consider it an entire IDE. It's not just for programmers, though. Vim is perfect for all kinds of text editing, from composing email to editing configuration files.

The vim text editor is an extremely powerful tool for developers, but it can be difficult to master. If you are new to vim, I recommend these exercises

Install vim

If you're using a Mac or a Linux machine, it's likely that your terminal has vim built in, so it's worth being familiar with to work on those systems.

If not, you can install vim with your package manager or test if vi is installed.

To install vim for Ubuntu, follow these instructions.

1: Open a terminal window and type sudo apt-get install vim

sudo apt-get install vim
Enter fullscreen mode Exit fullscreen mode

2: If you want to get updated version of vim, open a terminal window and type sudo apt-get update

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

3: Then type sudo apt-get install vim

sudo apt-get install vim
Enter fullscreen mode Exit fullscreen mode

The installation process will take some time, after which all the commands of vim will be available.

apt-get install vim

Basics

To start vim, just type vim in the command line

vim
Enter fullscreen mode Exit fullscreen mode

Then you can type ESC followed by :e filename to open filename.

To open a vim directly from the command line, type:

vim filename
Enter fullscreen mode Exit fullscreen mode

Press ZQ to quit vim without saving. Press ZZ to save and exit.

To move the cursor, you can press ESC and use the keys h,j,k,l. You can also use the arrow keys in vim.

vim cursor keys

Vim has modes. To switch to writing mode, press the i key or the insert key. To switch to command mode, press the ESC key.

To save your file press ESC followed by :w.

Press :Explore to open the file explorer. Use the j and k keys and press enter to open the file. You can also use :LExplore

Top comments (0)