ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software

Why "traditional" text editors like Emacs and Vim are still best

Updated on February 4, 2011

What's the big deal?

For programmers especially, text editors can be a surprisingly personal topic. When what you do for a living (or hobby) is write things so that your computer can understand them, it's important that you can do so efficiently and in a way that feels natural. You could write everything in Notepad if you wanted to: after all, it lets you insert and delete text wherever you want, and the end result will be the same no matter what editor you used to produce the program. And some poor souls do exactly this! But using an editor that understands the language you're working with can be a tremendous boon. It can give you hints about the structure of the program with syntax-aware coloring; automatically write tedious code for you; notify you about constructs that are illegal or dangerous. The list of things your editor can do for you is enormous, and choosing an editor with capabilities that match your personal style will matter more than you think.

Tried and true

There is a tendency, when dealing with computers especially, to look for the "latest and greatest" and assume it will be the best. And this is not far off: I'm sure some hardware fanatics out there will tell me I'm wrong, but usually the hardware in computers gets more powerful with time, and newer software will have been designed with newer hardware in mind, allowing them to leverage that new technology to look better, move more smoothly, handle more things at once, and so on.

But a lot of products don't need terribly powerful hardware to run: you could play Sudoku on a computer from thirty years ago and it would run just fine. Similarly for text editors, the computer is way faster than you are - it's spending almost all of its time waiting for you to type, patiently making the cursor blink for you.

So being new is no particular advantage for text editors; in fact, the best thing a text editor can have going for it is...age! Programs like emacs and vim have had decades to work out all the kinks and add all the subtle usability features you could really want, making editing easier without you having to think about it. Eclipse, a newer product, is fantastic for editing Java, but I regularly have to restart it because it crashes somewhere, or consumes so much memory it can no longer respond quickly to my input.

So what are the options?

The two heavyweights in the arena of Editors For Programmers are Emacs and Vim. My experience is primarily with Emacs, so my examples will be for Emacs, but I don't want to start any religious wars: I'm sure Vim does all of these lovely things (almost!) as well as Emacs. And note that both of these programs have kept up to date, with active volunteer maintenance teams, like any well-loved open-source project. In particular, they both have windowing modes that make use of the mouse in the same way you're used to with newer text editors, so you can take your time getting the hang of using them, falling back to basic point-and-click as an escape hatch if you get frustrated with the "traditional" way to do something.

Less of a mouse allergy than a keyboard fetish

By far the biggest hurdle to get over, when trying to learn any new interface, is learning the tools it provides you with, and where to find them when you want them. This is amplified when transitioning to a classic editor like Emacs, because it was designed before the mouse was even invented. Thus, many of the actions you're used to performing with the mouse are instead hooked up to some particular key sequence. You may need some convincing, but this is a fantastic feature. Every time your fingers leave the home row to reach for the mouse, or even the arrow keys or the home/end/pagedown area, you have to interrupt the flow of typing, move the cursor to where you want, and then get back to the home-row position that you're most productive typing from. Emacs and Vim both let you move around with the arrow keys or the mouse, but they provide alternatives that use the letter keys. For example, you can scroll up a line in Emacs with C-p (that's Emacs shorthand for control-p), and Vim has a distinct "edit mode" where all of the letter keys perform editing-related tasks instead of inserting new text: in this mode, the K key scrolls up a line.

A stylish vim cheat sheet for commonly-used commands.
A stylish vim cheat sheet for commonly-used commands.

The keyboard isn't on the screen

If a program uses mostly the mouse for its user interface, then it has a difficult tradeoff to make: every button it adds takes up another chunk of the screen that you'd rather have to yourself. Using expanding/folding menus solves this problem, but having to navigate through three levels of menu makes a feature very difficult to use.

At a rough estimate, there are three modifier keys on every keyboard (Ctl/Cmd, Alt/Meta, Shift), and 30 primary keys like letters. If you permit up to two modifiers at a time, that's over two hundred commands available with a single key combination. Add to this the notion of a "prefix key" like "C-x followed by C-c", and there are over forty thousand commands that you can access in less than a second. That's more commands than you could possibly remember, and none of them are taking up any space on the screen, just in the help files. The limiting factor in terms of power is now you, not the computer: it's gotten out of your way and made it possible for you to do whatever you want to.

And of course both of the major editors let you customize any of the keys you don't like, moving commands you use often to more-convenient keys, move uncommon commands to different keys, and even invent your own new sequences to bind to commands you write yourself.


I get it, the keyboard is awesome, what else?

I've gone on too long about how exciting the keyboard is: by now I'm either boring you or preaching to the choir. So let's talk about language integration. Vim and Emacs both have a concept of "modes", for activating specialized functionality based on the type of file you're editing. They come with modes for most common programming languages, as well as things like viewing diff files. For example, in C mode you can hit M-. (that's alt-period) when the cursor is on a function or variable, and Emacs will jump to the definition of that variable, whatever file you're in. It even keeps your place for you with a stack of automatic "bookmarks": once you're done exploring something, you can go back to where you were with C-u <SPACE>.

Emacs can automatically complete function names for you, make sure opening and closing braces match up, indent your code according to customizable rules, work with "chunks" of code like "everything from this { to its matching }" instead of just characters or lines of text...the list goes on.

And the cut&paste abilities are fantastic. Plus, they're given the fantastically more exciting names of kill and yank respectively (they've been around since before the cut/paste idiom caught on). You would think that without a mouse this would be inconvenient, but in fact it's even better. For one thing, you get an enormous number of separate areas for holding text. Emacs builds a list of things you've killed (cut) recently, and you can yank (paste) any of them back into the document, or search through the kill buffer to find the thing you're looking for. Vim has a similar functionality, which (I think) assigns a buffer to each letter, so that you can "kill this text to area G", for example. And because the number keys are used to repeat commands, you can quickly give instructions like "kill the next five words" or "yank exactly 100 copies of that buffer onto the screen" without having to do the counting yourself.

Integrated debugging

It's incredibly useful to have a debugger that cooperates with your editor. Above, you see me using the Geben debugger plugin for Emacs to walk through a PHP program as it runs, and seeing the values of relevant variables. As you can see, I'm doing this in terminal mode: The screen is a little cramped since my terminal isn't very large, but it's perfectly usable and I could make the terminal larger if it were a problem.

Work remotely

Did you catch the implication of that? It means that no matter where I am, if I have access to a computer, I can ssh (or use PuTTy on Windows) to my usual machine, and have an IDE with a debugger instantly available to me, just as if I were in the office. This makes it very convenient to do remote work if something comes up, or you have this great idea while you're at home or whatever. That is much harder to do with a windowed editor like Eclipse, which relies on an actual window to display information, and prefers that you use a mouse to give it instructions.

Not just a text editor

Gedit is a fine text editor, and it's handy when you're borrowing someone else's computer or just want to change a line of text in some file and forget about it. But it's like a futon: you can sleep on it, and sometimes it's the best choice, but in the long run you'll be a lot happier with a king-sized bed. Emacs and Vim are more than just text editors: they are program editors. They understand what you want to do, and try to help out. And because they are massively extensible, even by end users, you can do anything you want without having to leave Emacs for some less-friendly program. Emacs has an email client, an IRC client, a web browser, and more; and if you want, you can run a console in an Emacs window too. I rarely use these things because I like to have my mouse handy when I'm browsing the Web, but it's pretty amazing to have the option. And everything is customizable. I happen to like the way the Home key behaves in Eclipse, and when I switched to Emacs I was sad to discover that C-a (the equivalent key) isn't as "smart" as I was used to. So I opened up Emacs, wrote a quick function for moving the cursor the way I was used to, and bound it to C-a. Now it does just what I want, every time.

My smart-line-beginning function

(defun smart-line-beginning ()
  "Move point to the beginning of text 
on the current line; if that is already
the current position of point, then move
it to the beginning of the line."
  (let ((pt (point)))
	(when (eq pt (point))

(global-set-key "\C-a" 'smart-line-beginning)

Awesome! Where do I sign up?

Emacs and Vim originated on the Unix platform, and that's still the best place to use them, but they are both well-loved enough that they've been ported to every popular operating system, and are quite usable on all of them. And because they're open source, they're also free. Here's a quick summary of how to get an editor on any of the Big Three:

  • Windows: Vim and Emacs
  • Macintosh OS X: Vim, and Carbon Emacs or Aquamacs
  • Linux: vim and emacs packages are available for all the popular package managers. On Ubuntu, you can find yours in System/Administration/Synaptic.

You'll also want a guide to help you learn how to use your new toy. Each comes with an interactive tutorial and context-sensitive help. You can enter the Emacs tutorial at any time with C-h t (remember: "help, tutorial"), and get information about the other help features with C-h C-h ("help with help"). Vim allows you to write :help before any command to get help with that command, and comes with a secondary program called vimtutor for introducing you to Vim.

Additionally, you can find excellent newcomer-oriented guides on the Web: the Emacs Newbie page, especially its Guided Tour section, and A Byte of Vim are two stellar examples.


It will be a tough couple of weeks while you adapt to your new environment. Try to figure out how to do things in your editor, but don't be afraid to fall back on something more familiar if you've spent a minute or two on something and are feeling frustrated. It took me two tries to get into Emacs, and about two weeks of regular, sometimes painful use before I was as comfortable as I used to be with more modern editors. But there is unlimited room for improvement: I learn new tricks all the time, and sometimes they are jaw-droppingly useful. Now after just six months of Emacs usage, I have drunk the kool-aid, and I'm more productive than I was after spending ten years working with point-and-click editors.


    0 of 8192 characters used
    Post Comment

    • btcminer profile image

      btcminer 5 years ago

      Vi or Vim is really also nice, but that is only once you get used to it, could be like a dvorak keyboard is nice once you get to rewire your brain to that.

      I tried the dvorak for a couple of hours, the problem is that I really need to rewire the brain but I absolutely liked the feel of dvorak (really nice I always moves my hands way to much when editing with the qwerty keyboard, dvorak I can keep my hands much more still.).

    • profile image

      ericsomething 5 years ago

      amalloy, this is good stuff. makes me want to familiarize myself a bit more with emacs. I'm a Vim user, and I especially like being able to go right into an editing session from Midnight Commander.

      Kind of surprised no one really got started with a vim/emacs shooting war in your comments (yet). I recently got into a debate with a guy about it on Google+, turned out he was one of the big guys with the Free Software Foundation. Maybe I'll learn to pick my fights better.

    • btcminer profile image

      btcminer 5 years ago

      Really nice hub I love emacs I used Vim but it wasn't so great so I went to emacs, and that is a lot nicer.

      I like the cheatsheet you got very nice I always forget some of the movement commands.


    • profile image

      archbishop of cantebury 6 years ago

      stealing your C-a function. i never really noticed how annoying it is to kill the indentation along with the text

    • ezhang profile image

      Edward Zhang 7 years ago from Bay Area, CA

      I'm also wondering about the "staff" icon on our pictures. I could have sworn they used to be there.... (but then again, I can't be entirely sure)

    • Ari Lamstein profile image

      Ari Lamstein 7 years ago from San Francisco, CA

      @amalloy: can you recommend any good books for learning emacs or vi? If so, please link to them in an Amazon capsule. Thanks.

    • Ari Lamstein profile image

      Ari Lamstein 7 years ago from San Francisco, CA

      Whatever. I guess this means that I suck at comments (as well as twitter)?

      You can always delete comments, you know...

    • amalloy profile image

      amalloy 7 years ago from Los Angeles

      Ari, you're posting comments on my hub about features that will totally be your job to implement. Just go implement them, and then show off how awesome they are to everyone! :)

      (Mostly posted so that ezhang will get notified about Ari's comment, to be honest)

    • Ari Lamstein profile image

      Ari Lamstein 7 years ago from San Francisco, CA

      You know what, I bet that ezhang will never see my previous comment because our notification system will only email him the next time that the Hub author posts a comment.

      I can see why people want a "follow" button on comment threads.

      Also, it would really help if there were some kind of threading for comments, so that my previous comment could visually be seen as being related to ezhang's previous comment.

      Also, is it a bug or a feature that the "staff" icon doesn't appear on our pictures when we post comments?

    • Ari Lamstein profile image

      Ari Lamstein 7 years ago from San Francisco, CA

      @ezhang: would you really want to switch from gedit to one of these guys?

    • amalloy profile image

      amalloy 7 years ago from Los Angeles

      Thanks for the suggestion, ezhang: I've added a section or two on that.

    • Ari Lamstein profile image

      Ari Lamstein 7 years ago from San Francisco, CA

      Thank you for the thorough answer, Alan. However, I have to say that I would still take gedit over emacs or vi any day of the week! POW!

    • ezhang profile image

      Edward Zhang 7 years ago from Bay Area, CA

      Thanks for sharing!

      How would you recommend one to START learning to use one of these editors? Any advice about switching over from the common text editor (gedit, textedit) to using these powerful beasts?