Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I often see people express a preference for vi or vim for text editing or even for programming.

I've tried it and I can't see how it could possibly be any faster or easier. If you use one of them, why?

share|improve this question
I just did some research and found out there is apparently a rivalry between vi and emacs users. Sorry if anyone was offended, I'm honestly curious and have never use emacs. –  T. Markle Jun 14 '11 at 4:01
@Martin, that is a tasteless comment. –  user1249 Jun 14 '11 at 4:41
well i found Pavel's more tasteless; and meaningless and bogus. –  Ritwik G Jun 14 '11 at 5:51
How do you generate a random character sequence? Put a beginner in front of Vim and tell them to exit it. –  Mongus Pong Jun 14 '11 at 9:22
@tdammers : A seasoned Unix user would already know Vi. –  Mongus Pong Jun 14 '11 at 12:47
show 4 more comments

marked as duplicate by gnat, Jalayn, MichaelT, World Engineer Apr 17 '13 at 14:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

10 Answers

up vote 15 down vote accepted

Essentially it comes down to the fact that you can do whatever you want without ever leaving the keyboard. There are lots of key bindings that let you do lots of things. There is a steep learning curve for those used to graphical (mouse) editors as it is a very different way of doing things. However, once you get familiar with it, you can move around and edit files quickly.

share|improve this answer
Maybe that's my issue, I dont' leave the keyboard in a typical text editor so I don't receive the same benefit as others. I'll accept this answer when the timeout's over. –  T. Markle Jun 14 '11 at 4:04
@T. Markle - Think that there are far more key bindings in vi/vim that in any "typical text editor" and you will start to understand that you can get very productive with vi/vim. Moreover, you can define srcipts for common repetitive tasks. –  mouviciel Jun 14 '11 at 5:08
A few basic examples: w and b move the cursor forward/backward across words. 0 and $ jump to the beginning or end of the line. yw "yanks" the word following the cursor (similar to copying); y2w yanks two words. fz jumps to the next occurrence of the letter 'z'. dfz deletes all letters on a line until it finds 'z'. gU$ capitalizes all letters between the cursor and the end of the line. –  Daniel Jun 14 '11 at 5:20
@T. Markle: You haven't scratched the surface yet. Vim does auto-completion, has integrated documentation both of itself and of the languages we write code with. I can instantly get documentation for the function under the cursor in almost any programming language. And the benefits don't only kick in for "lots of repetitive tasks", they are effective for even the most basic operations. There is a holy war between vim and emacs, but nobody really contests that these editors are far more powerful and capable than any of their graphic counterparts. –  Caleb Jun 14 '11 at 8:11
I'd add that there's more than not leaving the keyboard, but instead not leaving the Home Row keys. I think that for people who can touch type, that's something desirable. –  julio.g Apr 4 '13 at 18:50
show 6 more comments

Don’t forget scriptability. I’m not talking about plug-ins here (although these are great, and in fact far superior in scope and power to other editors). I’m talking about the fact that every keyboard command can be arbitrarily combined using movement commands.

For example, d deletes characters. dw deletes a word (in forward direction) and dd deletes the current line. d$ deletes from the current position until the end of the line. 20dd deletes the next 20 lines. df, deletes everything until the next comma. di( deletes the contents of the current parentheses.

Now use c instead of d and all these commands still work, but place you into insert mode afterwards.

This in itself is amazing, and cannot be approximated in any other editor (save Emacs, possibly). Now add macros recording to the mix. Press qa to record a macro into register a. Perform some action. Press q again to stop recording. Now press 20@a and play the macro twenty times.

Assume you’ve got a file with some text and you need to number the lines, so that each line starts with n.␣ where n is the ordinal number.

Easy. Simply type the following (starting at the start of the first line):

I 1 . q a y f v j P 0 Ctrl+A q 50 @ a


  • I goes into insert mode where we then type 1.␣.
  • qa starts recording a macro into register a.
  • yf copies everything up to the first space.
  • j goes into the next line and capital-P pastes the copied text.
  • 0 goes back to the beginning of the line.
  • Ctrl+A increments the number found under the cursor.
  • q stops recording, and
  • 50@a plays the recording 50 times, effectively resulting in 51 successively numbered lines.

Show me any other editor that can do that.

And I’ve not even mentioned search and replace.

share|improve this answer
I could show you emacs, I guess. The one thing I don't know if it exists is "increment number at point". –  Vatine Jun 14 '11 at 9:57
It's a lot quicker just to do :1,$!cat -n (or any other command to format the lines as you like), and that's been available in vi since long before vim existed. In bone-stock Emacs, you can do M-x shell-command-on-region cat -n or just M-| cat -n. I wrote a one-line variant called shell-command-in-region that does the edit in-place. –  Blrfl Jun 14 '11 at 10:04
@Vatine My answer is explicitly not directed against Emacs. I don’t know emacs well but I suspect that it’s at least as powerful as Vim. –  Konrad Rudolph Jun 14 '11 at 10:45
@Blrfl True, the ability to use shell commands makes vim even *more powerful. I wanted to stick to one point in my answer though to be honest I didn’t even know that cat could do this. –  Konrad Rudolph Jun 14 '11 at 10:48
Using shell commands fits the Unix philosophy of combining existing tools to make new ones. Your way has the advantage of working on platforms that don't implement the POSIX command set. (Speaking of which, pr -T -n' ' would have been a better choice, since I think cat -n is a GNU extension.) –  Blrfl Jun 14 '11 at 13:40
add comment

There is two good reasons to use vim:

  1. it is a clone of an editor which is always available on any Unix system.
  2. it is a very powerful editor

These two combined explains why the original vi is very popular on Unix systems in the first place. vim then fix a lot of the short comings of vi, making it even more attractive to these persons.

Personally, the reasons I use vim as a replacement for notepad on Windows systems, are:

  • Can integrate in right-click menu.
  • Easy navigation in large files. "G" goes to bottom. "1G" goes to line 1, i.e. the top.
  • Easy searching: "/searchstring" locates instance, RET locates next. "?" search backwards. Search strings are highlighted.
  • Handles large files easily.
  • Has unlimited undo when editing.
  • Syntax colouring. This is really nice when reading XML or program source.

I consider it to be a power tool, which takes learning to use well. If you do not want to do that, it is not the editor for you.

share|improve this answer
How can vi do syntax colouring? –  lamwaiman1988 Jun 14 '11 at 5:19
@gunbuster, I do not know how it is done technically. –  user1249 Jun 14 '11 at 5:25
@anderson i think he wants to know how he can make his vi to do syntax coloring. gunbuster, The answer is in downloading packages particular to your language. btw, vi comes with built in syntax coloring for c, c++ and others (it will get activated as soon as you provide a relevant extension to your file) –  Ritwik G Jun 14 '11 at 5:57
To be pedantic, vi cannot do syntax colouring - for that you need vim. –  nbt Jun 14 '11 at 6:57
@Ross, that is not "quit :)" but ":q" –  user1249 Jun 14 '11 at 8:06
show 3 more comments

Vi (or it's variants) is installed by default on most unix/linux systems, and its keybindings allow you to keep your fingers mostly on the homerow instead of fumbling with combinations of CTRL and ALT to do commands.

share|improve this answer
yes; we do not like pressing ctrl and alt and all those other stupid buttons –  Ritwik G Jun 14 '11 at 5:58
One of the things that's prevented me from using vi/vim more is that it is so tied to qwerty and I'm a dvorak user. –  dan_waterworth Jun 14 '11 at 6:05
@dan, that is just four keys which can move the cursor. Use arrow keys for that these days. –  user1249 Jun 14 '11 at 10:45
@Thorbjørn Ravn Andersen, hmm, maybe you're right. I'll try vim again one of these days and find out. –  dan_waterworth Jun 14 '11 at 12:56
@Scrooge: Yeah, that's for emacs users. –  David Thornley Jun 14 '11 at 14:44
add comment

One uses vim if his time is valuable. Generic reasons for using a terminal-based editor over an IDE can be found in Time to drop Emacs and vi?

share|improve this answer
add comment

In my opinion, the biggest advantage for programmers who use vim as editor, are all about faster text editing (text object concept, macro... etc) . We all type hundreds lines of code in front of the computer screen each day, and it takes time. Why would one not want a effective way to do this ? Not to mention there are tons of good plugins make vim even better.

7 Habits For Effective Text Editing 2.0 by Bram Moolenaar

Here is a good presentation about how to improve your text editing skill, by using VIM.

share|improve this answer
add comment

Make you efficient in text processing related work.Take some time to learn a advanced classical tool pays much more than the effort you had got involved in.

share|improve this answer
add comment

Another consideration, which no-one has so far mentioned, is the efficiency of vim when being used blind. By blind, I mean that you cannot see the results of what you are typing immediately, or within a reasonable time.

An example of this is when you are using a connection with a long lag time where it may take several seconds between typing a character and it being echoed back to your terminal. Even half a seconds lag can make interactive editing frustrating, much more can make it nigh on impossible.

A mode-less editor like emacs has the problem that much of the feedback is visual. With a mode based editor like vi you can queue up edits, meaning that you have to wait for the remote end to catch up less frequently.

I discovered this effect working on slow serial links many years ago, but it is still relevant today. Given the limitation of the speed of light on communication links, the round trip time of a signal up to a geostationary satellite and back is around 1/4 of a second.

share|improve this answer
I have to say that I can hardly bear working with Vim over a lagging SSH connection. So even though this might not actually be possible at all with a visual editor, it’s almost impossible with Vim, too. –  Konrad Rudolph Jun 14 '11 at 10:49
@Konrad - Like many things, it just takes practice. You just have to get out of an interactive mode of thinking. I guess that this is another thing vi helps with, since you already have to switch the way you use an editor to use vi at all. –  Mark Booth Jun 14 '11 at 12:40
add comment

Vi is a bloody good editor and by extension so is vim (although I actually prefer nvi of the two, it's closer in UI to the vi I learned some 20 years ago).

It's, however, not the editor I do most of my editing in, as I use the other one.

share|improve this answer
add comment

When I first started using Unix I tried both vi and emacs and I preferred the latter because it behaved in a way my brain expected it to. These days I use VS for Windows work and Eclipse for Linux work and emacs has been relegated to those times when I have no GUI.


Well, it all comes down to using the most productive tools for the job at hand. The jobs I've had recently had a much greater emphasis on testing than coding, and when there was a lot of new code to write, there was a lot of boilerplate code that could be automatically created using macros (yes, there's macros in VS). When I'm writing code, I rarely touch the mouse and with intellisense I get prompts as I type (it helps to be OK at touch typing). When I'm debugging or browsing I use the mouse so my fingers get a rest (don't want to get RSI now).

To answer the question then, people use vi because it maximises their ability to type and works in the way they think (i.e. the model for editing matches their internal model of how to edit).

Now, people who use an editor because "that's what all the cool people use" are probably being inefficient.

As for Konrad's procedure for creating a list of numbers, it's not something I need to do often, and when I do, I'd open a spreadsheet and get that to create the list then copy and paste. Neat, definitely. A reason to use vi, hmmm.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.