| Tuesday May 31st 2016

vi Survival Guide

If you are trying to work at a command line in pretty much any Operating System, no matter if it is a GNU/Linux brand such as Ubuntu or Fedora Core, another UNIX-like system like Mac OS X or FreeBSD or even Microsoft Windows, you will most definitely need a text editor sooner or later. exit vi commandsIf you are using a UNIX-like system, like GNU/Linux variants, there are many text editors that may or may not be installed. Luckily there is one de-facto standard: vi is included in almost every GNU/Linux or UNIX distribution. “vi” is a truncation of the word “visual” and has, contrary to popular belief, nothing to do with the Roman number 6. Many people are not too fond of vi, but are, alas, often forced into using it when it is the only known option. You may prefer easier editors like gEdit (Gnome), kate (KDE), emacs or ne (command line), but these may not be present when working at the command line.
Therefore, it is best to know at least the basics of vi and to understand it a little better; the basics of survival in vi, which you will learn in this guide. Unlike what you may have heard about the invention of the language C, the vi editor was not the idea of some kind of sick joke. It was for real and it served a real purpose. I am writing this in vi.

vi is very old, 1976 to be exact – that is only 6 years after 1970-01-01, which is the second no. 0, the big bang, the birth of Jesus Christ of UNIX system clocks. In the age of information and the internet, 30 years is practically a century. Remembering the age can help you to accept it if you do not particularly like it. Still, however, many people like the fact that they can memorize the keystrokes and be at home with it for quick tasks, and they like its tiny footprint of disk space and RAM. They like it both as the old reliable standard on most distributions of GNU/Linux and as a simple but powerful editing tool.

The vi editor has an interesting history. It was created in a Berkeley University dorm room, Evans Hall, in 1976 by Bill Joy and some of his friends, although he was the one who fleshed most of it out, using the Pascal language. He designed it for a version of Unix he was working on at Berkeley University called BSD Unix, which stands for Berkeley Software Distribution Unix and forms the base of some modern Unices such as the popular FreeBSD.

Bill Joy eventually moved on to Sun Microsystems as one of its original founding members and has since moved on to other projects. Before Bill wrote vi, the students at the university were using an editor called ed. The ed tool, still as widespread as vi, unfortunately, is much harder to use. The students discovered that they could use terminal escape codes so that the terminal moved the cursor to the bottom, and they dubbed this “open mode” where short commands could be typed. There were later derivatives of the ed tool called em and en, and students were experimenting with reprogramming each and borrowing each other’s features. Eventually the most popular became Bill’s project, vi. When the VAX came about, the terminal escape codes standardized as VT100 (Vax Terminal 100) and this carried over into the BSD Unix and is still there today, implemented, for example, in the Linux console and xterm. These codes were utilized in moving the cursor around in the editor, scrolling sections, blocking off certain sections so that they do not scroll, and other cursor movement features. Anyway, what is most important to note about vi’s history is that there was very limited memory and disk space, so commands seemed to be more efficient if they were short keystrokes, rather than typing words. Also, menus and even a mouse weren’t invented yet at XEROX PARC center, so short keystroke commands seemed to fit the ticket.

Dan Bricklin’s Visicalc program would later hinge off of that aspect and use keystrokes the brought up menus, and that approach led to the success of Lotus 1-2-3. So short keystrokes it became, and each of us who use Linux should get to know how to survive in using these keystrokes. Like many things in Unix and Linux, when enough people know about a command and
depend on it, it becomes one of the defacto items that just has to be rolled in with it, like it or leave it, or enough people will complain.

vi survival guide

Related Posts: On this day...

Leave a Reply

You must be logged in to post a comment.