Introduction to Vim

A developer’s choice of text editor is usually one that is fairly easy to learn and one that they’re most familiar with. With that said, a lot of users would avoid Vim as it requires a more steep learning curve than other editors. A quick introduction to Vim below will outline the benefits that this text editor has, such as there being many more commands available than other editors, such as mass copying and pasting.

Difference between Vi and Vim

Users may have heard of Vi and Vim. Are they the same thing? No.

Vi is an text editor from the early days of Unix and is available on most Unix systems. Vim stands for Vi improved and adds new commands and features to the original vi interface.

One of the benefits of learning Vim is that no matter what Unix system you work on, there will be some similarities when using commands on either the Vi or Vim editors.

Vim Basic Usage

To open up the editor and begin writing to a new file, within your terminal, type vim testing.txt.

The terminal screen will more than likely look like the below image, and you’ll notice you won’t be able to start typing anything within the editor.

Introduction to Vim

This is because Vim is not in insert mode. To enter insert mode, press the i key. After doing so, you should now see some -- INSERT -- text at the bottom of the editor, which signifies the editor is in insert mode. You should now notice that you’ll be able to type within the file!

To exit insert mode, hit the esc key. You’ll need to be out of this mode and save the file, and quit the editor.

Saving the file can be performed by typing :w whilst not in insert mode. You can also save and quit the editor be typing in :wq.

Similarly, you can simply quit the editor with :q and force quit with unsaved changes using :q!.

Now here’s where Vim really separates itself from other editors. To select a line of text, make sure you’re not in insert mode and press uppercase V and use the up and down arrows to select further lines of text within the file.

You can use press lowercase v to select characters.

When you have text selected, press d to cut, or y to copy. In Vim, d stands for delete and y stands for yank.

You can then press uppercase P to paste before the cursor, or lowercase p to paste after.