Two Reasons the vim Text Editor Really Is vi Improved!

The vi editor is one of the big hurdles in seriously using Linux or any other member of the UNIX family of operating systems. The operating system is configured and controlled almost entirely with simple text files. Until you can comfortably edit them, you have no hope of doing any system administration.

It’s not really that hard, but it does require both knowledge and skill. In Learning Tree’s Linux introduction course you are shown the basics in one exercise, and then you come back to it from time to time to learn more and get the essential practice.

Knowledge gives you the various commands — w to move forward a word at a time and b to move back a word at a time, plus general patterns like how a number before a command does it that many times and so 6dw means delete six words. You also need skill at the very fundamental task of touch-typing. I can tell you a list of commands very quickly, that’s knowledge. Skill comes with practice, time on the keyboard.

It takes work to learn vi, so let’s make sure we get the most for our effort. That’s why I suggest you use the vim text editor instead of vi!

vi versus vim

Editor session of vim text editor editing HTML file
vim modifying HTML in an xterm

Everything you know about vi works in vim, but vim really is vi Improved.” Here are my two favorite improvements of the vim text editor –

I think that the most important improvement is its understanding and highlighting of syntax. Start two terminal emulators side by side and edit similar files in both, using vi in one and vim in the other. Use files written in some computer language — HTML, C/C++, Perl, Python, a shell script, or one of the many configuration files in /etc. Look at what’s happening in the vim window!

It’s not as if I have memorized what each color means, I just need to see the patterns. Or more importantly, the lack of patterns when I don’t add the closing quote or parenthesis or curly bracket or angle bracket, and a long block is the same monotonous color.

My second favorite improvement is that I can use the Tab key for file name completion when I’m reading in the contents of another file. Let’s say I know that another file named fragment-with-css-example.html contains a useful block that I would like to insert into the middle of my new file, new.html. I simply start editing new.html and move my cursor to the line above where I would like to insert the other file’s contents. I could simply type the following and it will be inserted:

:r fragment-with-css-example.html

But that’s a long name! Let’s make things easy, fast, and typo-free. If that is the only file with a name starting with “f” I could simply type:

:r f<Tab>

If another file name starts “f” but none start “fr”, well, I’m sure you can see where this is going.

The Distinction Now Matters in Many Linux Distributions

I have gotten into the habit of always typing vim instead of just vi when I start the editor because I use operating systems other than Linux. On both Solaris and OpenBSD you definitely have vi, it is the standard UNIX-family editor. You have to go out of your way to add another package to get vim. Doing consulting work for people using Solaris (often the project has to do with migrating something from Solaris to Linux) and running OpenBSD on my server and laptop, the distinction has mattered to me.

It hasn’t mattered on most Linux distributions, at least not much. You get the vim program (and manual pages and so on) by installing a package named “vi-enhanced” or similar. Some distributions replace the vi program with a symbolic link pointing to the newly installed vim, others use a maze of symbolic links under /etc/alternatives to decide what really happens when you run commands for which there are multiple alternative versions installed.

The result on most Linux distributions has been that if you installed the vi-enhanced package you really get the vim text editor no matter which version you ask for. This changes in RHEL 7 and other distributions based on it. If you run vi you get plain old unimproved vi.

Get In The Habit of Running the vim Text Editor!

Get in the habit of always running vim!

That way you will either get the good one, or else you will see a “Command not found” error message informing you that the better one still needs to be installed!

Pro tip: If it’s missing, ask your packaging system what you need to add:

$ yum provides vim

Type to search

Do you mean "" ?

Sorry, no results were found for your query.

Please check your spelling and try your search again.