Vim

Vim is an old style text editor that is generally assumed to be useful only to computer programmers and counter intuitively that it is only useful for short amounts of text. Anyone who makes those two claims has never looked at the source code for a computer program more complex than a Hello World routine. Computer programs are long and complex texts and programming projects often involve changing a lot of items at once. Ease of changing text is of course very useful beyond the world of computer programming and when journalists were told to stop using Microsoft Word Vim became the new software of choice in the journalistic community. A single command can tell Vim to delete several characters at once or several lines at once. If you delete too much there is an undo command to restore your text. A single command also allows you to delete the rest of a paragraph or to delete to the end of the sentence. This is manna from heaven for journalists and for other non-programming writers. I wrote a 95,000 word book in Vim and so can attest from personal experience that Vim is definitely a good choice for writing and editing a large project and is not just suitable for the shorter writing forms of journalism.

Vim is hard to learn because it uses commands that are unusual in this age of Windows word processors using standardised commands such as Control+c for copy text and Control+v for paste text. Vim uses y for copy text and p for paste text. The reason that it can have commands without a modifier key (e.g., Shift or Control) is that Vim is a modal text editor. Most text editors and word processors have only one mode: edit text. Vim has a separate command mode which is entered by typing the Esc key. That separate mode means that unmodified letter keys can be used for commands, whereas non-modal text editors and word processors cannot do so as the letters are needed for inputting text. Non-modal editors also come up against the problem that they run out of key combinations to use, especially as many key combinations are reserved for operating system use. Vim's great rival Emacs overcame this problem by using double key combinations, e.g., Control+x followed by Control+w to save (or write) the file. In a sense Vim uses a double combination approach in that Esc is pressed to enter command mode then the command is entered. So in Vim when in editing (or insert) mode you delete a word by typing Esc followed by dw. That is not that different from typing Esc then d to delete a word in Emacs. The difference with a modal editor is that once command mode is entered (in Vim this is called normal mode) you can stay there so deleting a second word is not Esc then dw but simply dw. The command (normal) mode also means you can tell Vim to repeat the command multiple times. If you want to delete five words in command (normal) mode you enter the number of times first and then the command or 5dw. The command for deleting a whole line plus its carriage return is dd and to delete 11 lines the command is 11dd.

Those multiple delete lines are probably more useful to programmers and I have used them in the context of changing multiple web pages that have the same bits of text that I wanted to change. For example I had a lot of web pages that began the viewable text with the code h1 class="green" which translates as use Header Style One for the title and apply class green to it, which I have set up to mean aquamarine background and navy blue text. I changed the default for Header Style One to use aquamarine background and navy blue text so I wanted to remove the class="green" from multiple web pages. I began doing this by selecting text (called visual mode in Vim) and pressing delete. Eventually I discovered that I could enter command (normal) mode and type 14x as x is the command for delete one character and there are 14 characters in class="green" as I also wanted to delete the space before the phrase. Those multiple deletes would be less useful in a large writing project as find and replace is more useful.

Vim also allows you to move around the text with commands that are too numerous to list. Two very useful commands for writers is that k moves up a line and j down a line. They can be multiplied like the delete commands so that 8j takes you down 8 lines, which is actually 8 paragraphs. By default Vim keeps all the text in a single line until it meets a line break (usually a carriage return). Most writers will set up Vim to display the text like a standard editor and so it displays paragraphs within the viewable screen rather than making you scroll right to rest the rest of the paragraph. This has the complication that using the arrow keys to move up what looks like one line the text moves you up a paragraph to the equivalent character in that paragraph, e.g., pressing the up arrow while on the 24th character of a paragraph moves you to the 24th character of the previous paragraph. This means that multiplied movement commands can move you around your text quicker than you anticipated. So you wanted to move down 8 lines on your screen, but Vim actually moves you 8 paragraphs as it understands a paragraph as a single line of text. There is an exception to this rule that Vim ignores the way most writers have the display of paragraphs set up. H (i.e., Shift+h) moves you to top of the viewable screen, L to the bottom, and M to the middle of the screen. One advantage for large writing projects of Vim's line approach is that you can turn the display back to Vim's default and that allows you to view the beginning of many paragraphs at once in order to move quickly around your text. This is done by entering what Vim calls command mode. To get there from editing (insert) mode first press Esc to enter what I am calling command mode then to enter what Vim calls command mode type : which takes you to a command line at the bottom of the screen. To turn off line wrap you enter setwrap! on this command line or another way to think of it is that in command (normal) mode you enter :setwrap! to toggle between wrap being on and off.

One command that I love on Vim is changing case of one character by typing ~ in command (normal) mode. This can be multiplied so that you may change the case of a ten word with 10~ or as it is a complete word use gw which is multiplied for four words as g4w. There is a lot of complexity in the commands for Vim, but the power of its text manipulation is a real boon for writers editing their text and it is little wonder that journalists have embraced Vim in such a major way. Previously journalism was dominated by the use of Microsoft Word, but as a word processor it added a lot of extra information in the file and this caused problems for the post-production staff putting the words onto a website or into a desktop publishing (DTP) program. That illustrates the difference between a text editor and a word processor. The latter add a lot of information to the text and therefore must save the file in binary (machine readable) format, which means that it is difficult to read that file in a different progam. Even with the move to text based XML binary formats (e.g., docx rather than doc in Microsoft Word) there are still incompatibilities. A text editor on the other hand edits a plain text file and because it is just text you can edit is for a while in Vim then switch to Emacs or another text editor and when you return to Vim no incompatibilities have been introduced.

Vim is a wonderful tool for writers and will become more wonderful for you as you learn more of its commands. My writing method is to write a book in Vim and then format it for e-book or digital print editions in software designed for that purpose (e,g, Jutoh for e-books and InDesign for paperbacks). I write the book as one large file, which Vim is capable of loading almost instantaneously. Compare this to Microsoft Word, which struggles to handle very large documents, especially if you try to run a spellcheck on it. Vim is used by systems administrators to analyse the output of computer logs that run to millions of lines, so it would not fall over because you load in your 3,000 page fantasy novel.

Normally I go into the history of a bit of technology in these articles as well as my personal history with it. The personal history would not take long as unfortunately I was a very recent convert to Vim and text editors in general. The history of Vim is that it is short for Vi Improved. Vi was created about 1976 by Bill Joy (who later founded Sun Microsystems) and about the same time its great rival Emacs was created by Richard Stallman (who later co-founded the free software movement) and Guy Steele. Vim (or Vim or Vim) was created in 1991 by Bram Moolenaar originally so that he could use a vi clone on his Amiga computer. Vim is now available on a wide range of operating systems and has won over short form writers in the media world and should be considered by long form writers in the book authoring world.

Home Technology Privacy