Vi the Unix text editor

Mohammad Khan
4 min readApr 18, 2018

--

What is Vi?

Vi is text editor for your terminal. Known as a “Screen editor”, “it takes up almost the entire screen, displaying part of the file on each screen line, except for the last line of the screen.[1]” Vi is lightweight, built into most *nix builds, and has a long history and large community base behind it.

A Vi joke in comics

Origins

Before the proliferation of graphical interfaces, Vi was the text editor of choice. (Emacs lovers may disagree). “The original code for vi was written by Bill Joy in 1976, as the visual mode for a line editor called ex[2]” If you start Vi on your machine today, you probably will be using Vim, Vi Improved, first released for the Amiga in 1991[3]. Usually preinstalled on your Mac, it is also available from github, with builds Amiga, Unix, Windows, Macintosh, and VMS. (sidenote, I thought VMS was dead, but it still has support!)

Getting started

Open your terminal and type vi

Type :version and you will see what version is installed. There is a gui version available, but apple does not ship bash with it

Type :help and we can get to the help file

Note the highlighted lines, if you are ever stuck :qa! will get you back to bash, albeit losing changes

Now in the help file you can go up and down as normal using the arrow keys. But suppose you wanted to page down? use fn key plus up or down.

If we go down the readme, we can see that there are two commands that can help use get started, :help quickref and :help tutor

Another way to access the vi tutor would be to exit to the bash prompt and type vimtutor

Lets open a file, but what file do we want to open? It is possible to traverse your directories! use :Ex and you can browse your files

Another cool trick is the ability open new tabs inside vim, :tabnew will start a new tab, which can be seen at the top. use :tabn to move to the next tab, :tabp for the previous

Sidenote, using hjkl to navigate vs the gamer wasd is a bit difficult to get used to. Look at your keyboard, see how it is layed out in one line rather then the natural pattern of wasd? I’m sure after several hours of usage, hjkl might be more comfortable)

Here is a pick of me getting stuck. How do I exit? Escape button and then a :qa! got me out, though another command may have sufficed

Verdict

Would I leave atom for the vim editor? Not at the moment. But for years I have heard accolades of Vim and am glad to have experienced it a little. When doing a quick little edit on a file, I may try to use vim more, rather than waiting for atom to load or using nano. With practice and vim plugins, it may grow on me!

--

--