1. Overview

In this article, we’ll look at the vi and vim text editors, which are available in the Linux command line, and the relationship between them. Moreover, we’ll discuss how to distinguish which one we’re using and which one to choose for each circumstance.

2. What Is vi?

vi (which stands for “visual interface”) is a standard command-line text editor. Its origins come from the Unix text editor for the command line, called ed, which evolved in different editors, eventually becoming vi.

To run vi, we can call it from the command line, appending the file that we want to edit:

$ vi /path/to/file/to/edit

vi is a modal text editor: It has multiple modes. When a file is opened, we’re not in Insert mode but Command mode. This is why we cannot yet write on the file! To enter the Insert mode, we have to press:

i

After performing the modifications, we can go back to Command mode with the Esc key. To save and quit, we use:

:wq

(followed by the Enter key). If no changes are to be saved, we can exit with:

:q

Some modes (the open and visual modes) of vi are described by the Single UNIX Specification and by the POSIX standard. This means that the vi editor is compatible with the devices that are compliant with these standards. Thus, we’ll most probably find vi in most of the devices we can work on.

3. What Is vim?

vim is another command line text editor and stands for “vi improved”. vim is an implementation of vi with extra features that improve the user experience and increase the effectiveness of the text editor. If installed in our system, we can launch vim in a similar way as vi:

$ vim /path/to/file/to/edit

We are presented with a very similar interface as for vi, which also has different modes. To edit a simple file, the procedure is the same as the one for vi. However, the improvements available in vim are in the details.

Some of the features that are in vim but not in vi are windows splitting and tabs, code highlighting, macros, undo and redo multiple times, command line history, pattern matching, and word completion. All these features help developers and writers boost their productivity.

4. How to Differentiate Between vi and vim?

From their definitions and their manual pages, it’s clear that vim is an editor that covers a superset of the possibilities available in vi. We can find vi in almost all Unix operating systems.

However, many operating systems have replaced the functionalities of vi with vim. In some of these OS, we can still run the command vi, as it’s a symbolic link pointing to vim! This is why, when opening vi, we might be presented with the vim splash window. We are indeed running vim in a minimal mode to mimic vi. The way to know if we have vi or a symbolic link pointing to vim is to invoke the help (which is only available in vim):

$ vi -h
vi: illegal option -- h
Usage: vi [- | -s] [-l] [-L] [-R] [-r [file]] [-t tag]
[-v] [-V] [-w size] [+cmd | -c cmd] file...

For comparison, let’s check the output of vim -h (which is similar to the output of vi -h if vi is pointing to vim):

$ vim -h
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr 25 2022 22:13:25)
Usage: vim [arguments] [file ..]       edit specified file(s)
   or: vim [arguments] -               read text from stdin
   or: vim [arguments] -t tag          edit file where tag is defined
   or: vim [arguments] -q [errorfile]  edit file with first error

Arguments:
...

We can also check within the editor itself. By typing :help in command mode, we are presented with an error in vi but with a help manual in vim.

5. Which One Should We Prefer?

For simple text editing tasks, both vi and vim will behave similarly. However, vi is preferred because we can expect it to be on POSIX compliant (or at least mostly compliant) systems. Moreover, regarding the performance, vim requires a little more resources than vi due to its more extensive features.

However, when dealing with longer snippets of code or more complex pieces, the features of vim come in handy. The learning curve to master vim (and vi) is steep, and it can look cumbersome at the beginning. But, in the long term, it may pay off, especially if we’re writing a lot of code. Even if the features of vim are indeed useful, some people still prefer vi because of its simplicity, which requires reducing the editing problem to the capabilities of vi.

Finally, it’s worth mentioning that there are other implementations of vi that provide even more features than vim. The most well-known is neovim. Moreover, there are implementations that have a graphical user interface while keeping the same underlying behavior as vim-gtk.

6. Conclusion

In this article, we first described what vi and vim are. Then, we discussed how to differentiate between them and how to choose if we need to use one over the other.

Comments are closed on this article!