---
created_at: '2015-04-12T09:47:13.000Z'
title: Why, oh why, do those nutheads use vi? (2007)
url: http://www.viemu.com/a-why-vi-vim.html
author: chdir
points: 86
story_text: 
comment_text: 
num_comments: 126
story_id: 
story_title: 
story_url: 
parent_id: 
created_at_i: 1428832033
_tags:
- story
- author_chdir
- story_9362786
objectID: '9362786'

---
[Source](http://www.viemu.com/a-why-vi-vim.html "Permalink to Why, oh WHY, do those #?@! nutheads use vi?")

# Why, oh WHY, do those #?@! nutheads use vi?

![][1]

[Home][2] | [Support][3] | [Customer area][4] | [Store][5] | [Forums][6] | [Blog][7]

# Why, oh WHY, do those #?@! nutheads use vi?

![][8] The _VI Gang Sign_

_by Jon Beltran de Heredia, May 16th, 2007_

Yes, even if you can't believe it, there are a lot fans of the 30-years-old **vi** editor (or its more recent, just-15-years-old, best clone & great improvement, **vim**).

No, they are not dinosaurs who don't want to catch up with the times - the community of vi users just keeps growing: myself, I only got started 2 years ago (after over 10 years of being a professional programmer). Friends of mine are converting today. Heck, most vi users were not even born when vi was written!

Yes, there are definite reasons why the vi/vim editing model is just superior to any other out there. And you don't need to be a Unix whiz to use it, either: [vim][9] is available for free for almost any platform out there, and there are plug-ins to get the functionality inside all major IDEs. Let's try to break a few misconceptions, and see some real examples of why it's the killerest:

### Misconception #1: modal editing

The first time you stumble into vi or vim, you are shocked and disgusted that you have to use 'i' to start typing text. Can't remember which of hjkl moves in which direction. And you need to press 'a' if you want to insert after the last character of the line. Since you're already probably used to other editors, and if the arrow keys work in insert mode (they do if the system is configured properly, which is over 90% of the cases), you will stay in insert mode and not go back to normal mode except if absolutely necessary. You'll probably spend 20 minutes with it, and never go back. And also complaining: ["How on earth am I going to remember whether I'm in insert or normal mode?"][10]

Turns out, this is just a _completely wrong_ way to use vi or vim. Using vi/vim properly, you don't use it modally. You are _always_ in normal mode, and only enter insert mode for _short bursts_ of typing text, after which you press <Esc> to go to normal mode. Thus, the remembering-the-mode problem just doesn't exist: you don't answer the phone in insert mode to get back to vi and not remember where you were. If you are typing text and the phone rings, you exit insert mode and then answer the phone. Or you press <Esc> when you come back. But you never think about insert mode as a mode where you _stay_.

Let me explain the philosophy behind this.

Commands in vi/vim are meant to be combined - 'd' means delete, 'e' means 'move to end of word', then 'de' is a complete command that deletes to the end of the current word (something like Ctrl-Shift-Right, Left, Del in most regular editors).

One good benefit of this is that the '.' command repeats the last _complete_, _combined_ editing command (not movement commands). After doing 'dw', '.' will act as a command to delete to the beginning of the next word. You can move around at will with all the powerful navigation commands, and press '.' at will to delete to the next word quickly. This turns out to be incredibly powerful.

And now we come to insert commands. These commands enter insert mode and let you type text until you press <Esc>. Ok, in the case of these commands, the full command includes all the text you typed between 'i' (or whatever command you used to enter insert mode, as there are several) and <Esc>.

What this means is that if you type 'iHello<Esc>', which enters the text 'Hello' at the cursor's position, what now '.' does is "Type 'Hello' at the cursor's position". All of it. And you can understand that is pretty powerful. But it's better than this. 'A' goes to the end of the current line and enters insert mode there. So, after completing the insert by pressing <Esc>, you can press '.' anywhere to go to the end of the line and do the same thing.

One other even more powerful example: let's take the 'ce' command, which is composed of 'c' and 'e'. The 'c'hange command deletes the range specified by the next motion command, and also enters insert mode. It's the same as 'd', but with the distinction that it enters insert mode, instead of staying in normal mode. The boon is that the text you type in the next (short) input session is also part of the command. So if you do 'ceHello<Esc>>', what you do is replace from the cursor to the end of the word by 'Hello', and the '.' command afterwards will work exactly like that: replace up to the end of the word with 'Hello'.

Motions (cursor-moving commands) can also get more complex, and there are all sorts of insert-mode-entering commands ('o' to create a new line below, 'O' to enter one above, 'S' to delete to the end of line, etc... all of them entering insert mode afterwards) so you can imagine what type of powerful editing mini-ops you can build and repeat with simple '.'s!

### Example #1: the wonderful dot command

Let's see a concrete example. Say you have declared three new functions in your header file, and you need to implement them in the module. You copy the following text and paste it into your implementation file:

![][11] _All code starts like this, doesn't it?_

Now you have to remove their semicolons, and adding an empty body would be a good idea. With the cursor as above, you can use 'A' to go straight into insert mode at the end of the line:

![][12] _After 'A' - see the insert mode cursor (vertical line) at the end_

Now you delete the semicolon with <backspace>:

![][13] _Deleting is simple_

And type <return> { <return> } <return> to insert the body:

![][14] _Inserting too, as in any other editor_

And finally, type <Esc> to return to normal mode:

![][15] _And now, quickly!, we return to normal mode_

And now you have to repeat this with the other two. How do you do it? Easy: first, press 'j' to move the cursor down. And then, press '.' to repeat the last full editing command (the 'A' command with the backspace and the inserted text). If you do 'j.j.', that is, twice, you get the following:

![][16] _Just j.j. to do this!_

The vi command architecture was key here, together with the fact that <backspace> is as part of the editing sequence as regular typing, and the editing operations being pretty repetitive. But think about it, how much of your daily editing is repetitive? Yeah, I thought so.

### Misconception #2: it's not all about regular expressions

Vi/vim is pretty powerful handling regular expressions. All half-serious editors have regular expression support for searching, replacing, etc, but only vi (that I know) can use them in highly complex ways, such as doing a certain regex search and replace in the second occurrence of 'begin' after lines that contain 'proc', or whatever you think up.

So this is not to demean the power of regexes, or the vi/vim regex-using power. But the main power of vi, and the power that you can't live without after you've got used to it, is the power of the basic editing model:

* One- or two-key motions to move directly anywhere on the line, or on the screen
* Operators such as 'd' or 'c' that can be combined with any motion to directly modify some text and maybe enter insert mode, and being able to repeat it all as many times as you wish with '.'
* Anything can be done without moving your hands away from home row! No more suffering when editing on a laptop with a braindead keyboard layout (most of them)

### Example #2: smart ranges

Let's see the following typical example. It's just a function call embedded in a somewhat complex expression:

![][17] _Complex expression and function call_

As you see, we have the cursor positioned at the start of the call. Now imagine that we want to extract this and assign it to a local variable. The first part is selecting the relevant call, then copying and deleting it to move above, typing the var name, and moving above to type the declaration. In regular editing models, you will play hunt-and-peck with Ctrl-Right and left/right until you get it exactly right. Not with vi or vim. The '%' motion moves from a parenthesis (or similar grouping character) to its matching one - but if you're not positioned at one of these special characters, it will scan character by character to the right, until the first one is found, and then moving to the character matching that one. So, in the above situation, it will move to the right closing parenthesis!

Knowing about the 'c' command, which deletes the extents of the next motion (also copying it to the clipboard) and enters insert mode, we can type just 'c%' ("change match") from the above case and we get the following:

![][18] _After just 'c%' ("change match")_

The relevant call has gone to the clipboard, and we're also ready to type the name of the variable. Not bad for just two keystrokes! After typing the variable name and pressing <Esc> to go back to normal mode, it will look like this:

![][19] _Typing and <Esc>_

Now in normal mode, you can type 'O' to open a new line above the current one and enter insert mode, and start typing the declaration:

![][20] _Just pressed 'O' and typed the start of the declaration_

And now, when we have to insert the previous expression, since we have it in the clipboard, we can use Ctrl-R, " to paste it in insert mode (admittedly a bit unintuitive to remember, but it's the key to simple multiple-clipboard support). This will bring in the function call we deleted at the previous point. So Ctrl-R, ", we type a semicolon, and <Esc> to get back to insert mode gest us here:

![][21] _Finished!_

### Misconception #3: you gotta be nuts and/or a genius to use it

Well, I hope that with the above explanations and examples, you have already seen some of the power that vi/vim provides. Learning it is tough (see below), but if you're going to be editing code 8 hours or more a day for years, it's the second best investment after learning touch typing (which you already know, right? If not, don't bother with vi, learn that first). A learning curve of weeks make sense for such a lifetime investment. And, at least, you won't have a [dumb assistant][22] to annoy you to death.

The point is, with vi, your keyboard becomes a huge specialized text-editing gamepad with almost a hundred buttons. Each of them has at least two functions, shifted and unshifted, so you have almost two hundred functions at a single keypress (not counting Shift). Commands are incredibly powerful for text editing, and you can even combine them to obtain the best results. While typing some text, it is a regular keyboard, but when you're back to normal mode you have the best-designed text-editing machine there is, and it shows.

### Example #3: manipulating delimited blocks

One other simple example. This one only works with vim (uses one of vim's specific motions). Say you are inside an angle-bracketed section, as is so common in these days of XML:

![][23] _Life at an XML tag..._

How do you select the text inside for copying/deleting/modifying it? In regular editors, once again, you have to move your hands off their current, comfortable position, and go for the arrow keys or, even worse, the mouse. Any of those is probably a pain, especially when working on a laptop. How do you do it in vim? You just use one of the text-object motions, which all start with 'i' or 'a' (they can only be used after an operator like 'd' or 'c'). 'i>' refers to "the current 'i'nner angle bracket block", so you can do 'di>' ("delete inner angle-block") to just delete all the contents from the above situation:

![][24] _After typing di> ("delete inner angle-block")_

You can use '(' or ')' for the current parenthesized block (or even 'b' from 'b'lock), '[' or ']', '{' or '}', 'w' for punctuation-delimited-word, or 'W' for the current space-delimited word, prepending 'i' to any of them for the 'inside' contents, or 'a' to include the delimiting characters too.

### Misconception #4: hjkl to move around?

Many people find it weird to use hjkl instead of arrow keys for moving around. The actual reason for this implementation seems to be that terminals of the time didn't reliably have arrow keys, and that [this terminal][25] in particular had [hjkl keys doubling as cursor keys][26]. But the side effect is that you don't need to move your hands off the home row to move around, which is great.

But in any case, although you will use hjkl to move around at first, once you master vi/vim you probably won't use 'h' and 'l' ('left' and 'right') at all, and you will use 'j' and 'k' sparingly. Why is that? Because there are other, more powerful motions, that will often get you where you want to go much faster. When moving inside a line, I find that there is always a motion to take me straight to where I want to go, so I use those motions: 'f' followed by any other character to find its next occurrence, '%' to use matching parens to go where you want to go, etc... When navigating the file, you have motions to go to the top/middle/bottom of the screen directly, '/' which is effortless to type to search for a string, ']]' and the likes to navigate by functions, etc.

### Example #4: nice commands

Some commands are just so useful that you would miss them if you knew them. 'H', 'M' and 'L' take the cursor directly to the 'H'ighest, 'M'iddle, or 'L'ower line on the screen. 'zt', 'zz' and 'zb' keep the cursor at the current position, but scroll the view so that it falls at the 't'op, 'z' center, or 'b'ottom of the screen. '*' searches forward for the next occurrence of the word under the cursor ('#' does the same backwards, at symmetrical positions so its easier to remember). And there are dozens more...

### Misconception #5: since you are thinking 90% of the time, and editing 10%, the productivity gain might be there, but it's useless anyway

Well, those are exaggerated figures, but this fact is often mentioned against any editing gains being important to development productivity. I'll wager that this is wrong.

First thing, in the chances where I really have to think a problem, and there is no need to look at code, I pick my bike and go for a one hour ride. Or a two hour ride. At least if the weather is good. It's much nicer than staying in front of the computer.

Also, when I have to analyze some hard problem and design a solution, I often bring out a notebook (a real notebook, made of paper with cardboard covers and bound with a spiral), and a pen, and try to clarify my thoughts there.

You can bet that, with a few exceptions, productive work can't be done away from the computer. This is because, most of the time, you have to look at the code to think and design. And this involves navigating the code with an editor. And also, very often, you *are* indeed typing or editing continuously. You maybe just think for 1 minute, but then you spend one other full minute editing the changes you just thought about. And when you are editing, you want to have the best damn tool for the job.

Comfortable editing helps you stay in "the zone", the state of concentration that gets you the maximum productivity. As you master a powerful tool such as an editor, it just disappears from your conscious, and you are free to concentrate in the problem, and your editing happens unconsciously. Regular editing makes you hunt-and-peck, use Ctrl-Right, Ctrl-Right, Ctrl-Right, Ctrl-Right, Ctrl-Right to get to where you want to go, it makes you move your hand to your mouse, open a menu, select an option, enter stuff into a dialog and click 'Ok' to accept it. In vi/vim most stuff is a surprisingly small number of keystrokes away, in a direct fashion.

Other vi users have also shared this with me, so I know I'm not alone in the feeling: once you start to master vi, there are times in which, after finishing a 30-second-long full-steam editing session, you kind of 'wake-up' to a faint memory of the sound of a continuous stream of keystrokes. It feels like you have been hearing them in the back of your head while you were dicing and slicing lines of text, blocks, motions and modifications. And this during this period of editing, you are feeling a tremendous sensation of power.

### Example #5: indenting a block

Vi and vim know your code has some structure. Many of the commands reflect this. Say 'aB', as described in example #3 above: it selects the current '{' and '}' delimited block, including the braces themselves ('a}' does the same). And let's take it and combine with the '>' operator, a useful operator that indents the region indicated by the next motion. Picture the following code:

![][27] _Improperly indented_

How often do you encounter such a case? Yes, you can paste with auto-reindent (just ']p' in vim), but often you forget to, or you reach this case not because of pasting the block, but because you added or removed stuff above. You just have to indent it a bit, and you'll be done. In other editors, you move around, you select, you type TAB or the shortcut to auto-indent. Not so with vim, just three keystrokes: '>aB' ("indent a Block") and you get this:

![][28] _We didn't even have to move the cursor!_

How cool is that? You didn't move or select, you just told it directly what you wanted to do, and it did it. I believe it's this type of "straight" editing that gives you the feeling of power and helps you enter and stay in ["the zone"][29].

### Misconception #6: it's just sticking to a disappearing past

[ ![vi-vim emulation for visual studio in action][30] ][2]

Vi has been around for 30 years, and it's still there. Vim, a full-vi-clone which introduces even more improvements than vi has features, has been alive and kicking for 15 years, available for free on almost every single platform on earth. People who love vi have found a way to use it everywhere: there is [a plug-in to get vi emulation in Eclipse][31], [a plug-in to get vi emulation in many Mac OS X apps][32], [a plug-in to add vi emulation to IntelliJ IDEA][33], even Emacs has not one, [but][34] [several][35] built-in vi emulators (when I end up tinkering lisp code in emacs, I start by trying to use emacs keybindings, and always end up typing "M-x viper-mode"), I develop and sell [ViEmu][2], a family of plug-ins to get vi/vim emulation in Visual Studio, SQL Server, Word and Outlook, [Paul Graham][36] still uses it for his lisp and arc hacking, [Tim O'Reilly][37] is a confessed vi-er, [SlickEdit][38] and [Crisp][39] have vi emulation...

Of course, the vi/vim community is not a majority: most computer users are not even touch-typists, and vi adds yet another steep learning curve. Those who have seen the light, though, won't go back to other, poorer, editing systems - so vi/vim editing is guaranteed to survive for many years to come. Actually, using vi(m) keybindings is probably the closest you can get to ensure you have it available in any environment you are or will be in the future, from old Unix systems to the latest popular IDE.

### Example #6: visual nature

And as a final example, even if it seems vi is just about cryptic and unreadable commands, we are going to see some of the more visual aspects (actually, they are vim features, rather than vi original ones). One of them: with 'hlsearch' enabled (off by default in vim, but easily enabled with ":set hlsearch"), when you search for a string, all its matches are highlighted on the screen. Say you have the following html code:

![][40] _Some html source_

If you press '*', the word under the cursor ('div') is searched for. It results in this:

![][41] _Powerful asterisk!_

As you see, the cursor has moved, and the different occurrences are conveniently highlighted.

Let's see some more. We've seen operators like 'd' and 'c' act upon the region given by the next command. Well, if we want visual feedback, we can use visual mode: press 'v', move around while you see the region from the initial point highlighted, and then press the operator directly to see its effect. Search commands work here as well. If you use 'V' instead of 'v', highlighting will be done by lines. Let's press 'V' and then 'k' (up) after the above:

![][42] _After Vk ("visual-lines, up")_

As you see, the two lines are highlighted as selected. Say we want to select until the closing div tag (the search highlight shows it). Type 'N' (previous match), and we get the following:

![][43] _After 'N' ("previous-match")_

And now we can do whatever we want, say, the 'gU' operator to make everything upper-case (and return to normal mode):

![][44] _Lovely upper case_

And now, let's just go for a correct common 'conception' about vi/vim:

### Correct-conception #1: steep learning curve

There is one thing which is a commonly held piece of knowledge, and which is true as well. It is shown [on this page][45] to the best effect. It's the fact that learning vi/vim is an activity that will take a long time (weeks to months), and that the first experience is not pleasant. I take it this is the main reason why vi/vim editing isn't, and will never be, a popular thing. You need to invest quite some effort to learn, memorize, and internalize the 30 or so commands that start making you more productive than with other editors. Since they're all arbitrary one-key commands (although all of them have some easy mnemonic to aid in remembering them, and even some form of coherence), this is not an easy task. It's easy to throw in the towel and go back to familiar jedit or pico, ultraedit or textmate, or even emacs. But once the effort to learn it has been made, I know of no one who goes back. And I know dozens of people that have told me that they've been using 'vi' for over 10 years, and that they're accustomed to and expecting even the smallest details.

### Closing words

Do whatever you want. Don't learn it if you feel it's too much effort just for nothing. Learn emacs instead. Or stay in your IDE using a lousy editor. Whatever. But in any case, don't ever claim again that those 'vi guys are nutheads' - I hope that I have succeeded in showing you why they (_we_) stick to it, and you should at least be able to understand its power, even if you prefer to stay away from it.

If you want to research vi/vim editing some more, here are some useful references:

* [Learn why I got started][46]
* [Use my graphical cheat sheet and tutorial to learn vi/vim editing][47]
* [The awesome "vi lovers" home page][48]
* [Learn Jonathan McPherson's hints for effective editing with vim][49]

And of course:

* [Go to vim's homepage for anything you want][9]

_(Special thanks to Ivan Vecerina, [Andrey Butov][50], [Jose Gonzalvo][51], [Mark Petrik Sosa][52], [Aitor Garay][53] and [Woody Thrower][54] for commenting on early drafts of this article)_

_(All captures taken from Visual Studio with [ViEmu][2], my (commercial) vi emulator, and with [codekana][55], my upcoming product, providing the enhanced syntax highlighting)_

  

You can [**comment the article at my blog**][56]

  

## Highlights

ViEmu: vi/vim emulation for Visual Studio, Word, Outlook and SQL Server:

![ViEmu][57]

See where ViEmu customers are around the world:

![Map of ViEmu customers around the world][58]

Hear what others are saying about ViEmu:

![ViEmu testimonials][59]

Learn vi/vim easily with this cheat-sheet and tutorial:

![Vi/vim Cheat Sheet and Tutorial][60]

Read why vi/vim editing is _the killerest_:

![Why vi/vim editing?][61]

Visit the Symnum web site and customer area for everything about upgrades, licensing, and sales (see [here][62] for all details on the new license key system):

![Symnum Web Site and Customer Area][63]

![][64]

[**[Go to main vi-vim tips index]**][65]

© 2005-2017 [Symnum Systems][66] (formerly NGEDIT Software) 

[1]: http://www.viemu.com/MainGradient.gif
[2]: http://www.viemu.com
[3]: http://www.viemu.com/support.html
[4]: http://www.symnum.com/customer-area
[5]: http://www.viemu.com/store.html
[6]: http://www.viemu.com/forum
[7]: http://www.viemu.com/blog
[8]: http://www.viemu.com/why-vi-img/vi-gang-sign.gif
[9]: http://www.vim.org
[10]: http://www.dina.kvl.dk/~abraham/religion/vi-tutorial.html
[11]: http://www.viemu.com/why-vi-img/why-vi-1-1.gif
[12]: http://www.viemu.com/why-vi-img/why-vi-1-2.gif
[13]: http://www.viemu.com/why-vi-img/why-vi-1-3.gif
[14]: http://www.viemu.com/why-vi-img/why-vi-1-4.gif
[15]: http://www.viemu.com/why-vi-img/why-vi-1-5.gif
[16]: http://www.viemu.com/why-vi-img/why-vi-1-6.gif
[17]: http://www.viemu.com/why-vi-img/why-vi-2-1.gif
[18]: http://www.viemu.com/why-vi-img/why-vi-2-2.gif
[19]: http://www.viemu.com/why-vi-img/why-vi-2-3.gif
[20]: http://www.viemu.com/why-vi-img/why-vi-2-4.gif
[21]: http://www.viemu.com/why-vi-img/why-vi-2-5.gif
[22]: http://blogs.sun.com/marigan/entry/how_the_vi_editor_would
[23]: http://www.viemu.com/why-vi-img/why-vi-3-1.gif
[24]: http://www.viemu.com/why-vi-img/why-vi-3-2.gif
[25]: http://www.tentacle.franken.de/adm3a/
[26]: http://www.tentacle.franken.de/adm3a/adm3a-hjkl.jpg
[27]: http://www.viemu.com/why-vi-img/why-vi-5-1.gif
[28]: http://www.viemu.com/why-vi-img/why-vi-5-2.gif
[29]: http://www.joelonsoftware.com/articles/fog0000000339.html
[30]: http://www.ngedit.com/ad-viemu-1.gif
[31]: http://www.satokar.com/viplugin/
[32]: http://www.corsofamily.net/jcorso/vi/
[33]: http://ideavim.sourceforge.net/
[34]: http://www.informatik.uni-hamburg.de/RZ/software/emacs/viper/viper_toc.html
[35]: http://www.informatik.uni-hamburg.de/RZ/software/emacs/vip/vip_toc.html
[36]: http://www.paulgraham.com
[37]: http://www.oreilly.com/pub/a/oreilly/ask_tim/1999/unix_editor.html
[38]: http://www.slickedit.com
[39]: http://www.crisp.com
[40]: http://www.viemu.com/why-vi-img/why-vi-6-1.gif
[41]: http://www.viemu.com/why-vi-img/why-vi-6-2.gif
[42]: http://www.viemu.com/why-vi-img/why-vi-6-3.gif
[43]: http://www.viemu.com/why-vi-img/why-vi-6-4.gif
[44]: http://www.viemu.com/why-vi-img/why-vi-6-5.gif
[45]: http://www.bemroses.net/images/curves.jpg
[46]: http://blog.ngedit.com/2005/06/03/the-vi-input-model/
[47]: http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
[48]: http://thomer.com/vi/vi.html
[49]: http://jmcpherson.org/editing.html
[50]: http://www.antair.com
[51]: http://www.dbdesc.com
[52]: http://www.hcpv2.com/watership/
[53]: http://aitor.name
[54]: http://www.woodpress.org
[55]: http://www.codekana.com
[56]: http://blog.ngedit.com/2007/05/17/why-oh-why-do-those-nutheads-use-vi/
[57]: http://www.viemu.com/LogoShadow.gif
[58]: http://www.viemu.com/img/minimap-persp.gif
[59]: http://www.viemu.com/img/mini-collage.gif
[60]: http://www.viemu.com/img/cheatsheet-rot.gif
[61]: http://www.viemu.com/img/mini-why-vi.gif
[62]: http://www.viemu.com/new-licensing-system.html
[63]: http://www.viemu.com/img/mini-symnum.gif
[64]: http://www.viemu.com/img/highlights-bottom.gif
[65]: http://www.viemu.com/vi_vim_tips.html
[66]: http://www.symnum.com

