Somewhere Between Vim and Emacs There is a Great Text Editor

This post was written by Jake on April 13, 2008
Posted Under: Computer Science

Or: Yes, I’m The 300th Person To Write This Blog Post.

A year and a half ago, I abandoned Visual Studio to try to use the two most popular code editors: Vim and Emacs. Both of them have their advantages, but fall short of being the perfect editor.

Vim

The first coder’s text editor I used was Vim. It took quite a while to get past its infamous learning curve, but once I did, it was wonderful.

Advantages

  • Easy-to-Reach commands: The basic movement keys in Vim are right under your fingertips. Rather than wasting precious tenths of a second moving back and forth to the arrow keys, all you need to do is shift your right hand over. ‘h’ is left, ‘l’ is right, ‘j’ is down, and ‘k’ is up. This may seem weird at first, but after two weeks of using it, you’ll be disappointed whenever you’re typing in any other application.Not only that, but a lot of the extra movement keys are very close to the home row. ‘$’ and ‘0′, end and beginning of the line, respectively, are nearby. So is ‘^’, which gets you to the first whitespace character on the line. So is ‘G’, or the goto-line command. So is ‘w’, the “go to next word” command. No extra modifier keys needed.
  • Modal Editing: A lot of the power that Vim has comes from the fact that keys work differently based on what mode that you are in. If you are in Command Mode (the default mode in Vim), the ‘o’ key inserts a line below the current one and changes the mode to Editing Mode (which lets you enter text). If you are in Visual Mode (which is a selection mode), the ‘o’ key moves you to the other end of the selection.I’ve heard some people say that this is a strike against Vim, but I have never had any problem with this.
  • <action><location>: Once Vim beginners have learned all of the basic ways to move through a document (forward/previous character, forward/previous word, forward/previous line, searching, beginning/end line, etc), the next big epiphany is that you can combine these searches with commands. ‘dw’ deletes to the beginning of the next word. ‘d$’ deletes to the end of the line. ‘dn’ deletes to the next result in a search. The movements can be combined with commands to make complex text manipulation a piece of cake.Vim also comes with dozens of mnemonic commands, such as ‘daw’ (“delete a word”, deletes the word under the cursor, no matter where you started in the word).
  • Easy Repetition: Vim makes repetition very easy. All you need to do is type a number before you enter the command, and Vim will repeat it that many times. Want to delete the next 6 lines? Type ‘6dd’. Delete 6 words? ‘6daw’.
  • Quick Scripting: In Vim, this is one of the best timesavers available. If you have an action that you would like to do over and over again, you can store a key sequence in a buffer to recall later. For example, to start a macro, all you need to do is type ‘qa’, which will store a macro in the ‘a’ buffer. To finish, type ‘q’ again. To use the macro, type ‘@a’. To repeat it 100 times. type ‘100@a’. It’s that easy.
  • Fast Search: Searching in Vim is fantastically easy: all you need to do is type ‘/’, and then type your search regular expression. Search and replace is a lot more arcane: “:%s/<search regexp>/<replacement text>/gc” will do a search and replace globally and ask you for confirmation for each replacement. This is a common theme: there is less overhead to executing Vim commands. Sure, there are exceptions, but the stuff you use 80% of the time has been optimized for time.
  • Tabs, Buffers, Frames, Windows: All of the goodies you could ever ask for in this category. You have access to all of the standard ways to move data around. Miss buffers from Emacs? You get to use them in Vim. Miss tabs from Visual Studio? Type “:tabe” and use the tabs. Do you like having split screen code? You get that, too.
  • Customizable: Vim has its own scripting language that allows coders to build extensions. The site has a few thousand extensions that have been developed by the community, but I’ve always found it difficult to navigate.

Disadvantages

  • Chokes to death on multiple long lines: When I mean long, I’m not saying that Vim is a little slow on lines with 100 characters. If you had a file with multiple lines larger than the screen size (if you had a file of DNA sequences, for instance), you will probably not get the display behavior that you want with the default settings.
  • The Learning Curve: When you finally get up to speed using Vim, it is fantastic. However, it will take you a few weeks before you get used to all of the new commands, and even longer before you stop mixing up the movement keys and the home row. However, this is the kind of tool that is optimized for experts and not beginners.
  • Don’t Sneeze and Type: Have you ever started typing a sentence while in command mode and not in insert mode? Me too. I’ve watched half of my file disappear before my very eyes. Fortunately, the undo key (‘u’) is not very far away.

Emacs

Disclaimer: So that I don’t summon RMS from the depths of the Marianas Trench, mentally replace all instances of “Emacs” with “GNU Emacs”. It’s easier to type, and everyone knows what I meant, dammit.

Note: In key sequences, “C” means <Ctrl> and “M” means <Alt>. So C-M-Del means “<Ctrl><Alt><Del>”

Advantages

  • Easier to Learn: Emacs has a better learning curve than Vim, as the user is automatically able to start typing. It’s not until they try to save that they run into their first problem. However, the file menu helpfully gives the users the proper command.
  • Many Commands: Emacs has quite a bit of built in commands. To me, it seems like it has more than Vim, but that could just be a shortcoming of mine. It has a lot of helpful commands that Vim doesn’t have built in, such as transposition. This allows you to drag a word forward or backwards in a sentence or an argument list.
  • Everything but the Kitchen Sink: The main beauty of Emacs is that you shouldn’t need to leave your text editor in order to perform mundane tasks related to coding. Sure, Vim lets you compile and debug from the editor, but Emacs lets you check email, use calculators, play games. You can also perform any programming-related task you’d like. If you know a little eLisp (Emacs Lisp), you can even evaluate Lisp expressions inside of Emacs by default.
  • Better Auto-Indent: It seems like the coding modes in Emacs understand the document structure of programs a lot better, as they get tabbing right very frequently. Some of the modes are also intelligent when there is a tabbing ambiguity. For instance, in the Python writing mode, pressing the <Tab> key multiple times gives you all of the different possible legal tab positions.
  • Great Extension Community: Combining the magic of Lisp with the magic of Emacs, the community has been writing every imaginable extension you can think of since the mid ’80s.
  • Good Copy/Cut Behavior: By default, the copy/cut buffer in Emacs goes through “rings”, where you can repeatedly hit M-y in order to get previous items in the copy buffer. In Vim, you need to specify which buffer should be used as a copy, as it will continually overwrite the same one.
  • Good Buffer Support: Once you learn the different buffer commands, they turn out to be a very powerful way to switch documents. You can open new buffers as a scratch pad and turn to old ones in the blink of an eye.

Disadvantages

  • Ragtime Typing: Due to the use of modifier chords, you have to move your hands around quite a bit. The most commonly used key is the <Ctrl> key, so if your keyboard only has one, it is recommended that you swap your <Ctrl> and <Caps Lock> keys. For most of the simple movement, you need to use two keys to move instead of one: C-f to move forward, for instance.
  • Emacs Pinky: After a few weeks of use, I actually started getting the dreaded “Emacs Pinky”, a numb sensation in the pinky from constant use of the modifier keys. I took it easy for a few days and wore a wrist brace to find out when I’ve been abusing hand stretches, and the problem has since disappeared. However, the phenomena is very real, so be careful.

Somewhere There Is a Great Text Editor

Both of the text editors mentioned here have a lot of great features, but they also have a lot of drawbacks that are not mentioned here. Some certain commands have a lot more overhead then they should. Granted, you can just rebind keys to the command you want. However, this doesn’t always work when you are bouncing back-and-forth between a lot of different computers.

It would be great if Vim had the “kitchen sink” philosophy of Emacs built in, because then I’d never have to leave Vim and could forever revel in its modal glory. A lot of the buffer/window/tab commands in Vim feel like they have too much typing overhead. For example, typing “:tabn” over and over again to switch tabs gets old.

In turn, it would be great if Emacs had a lot less typing overhead for some of its commands. Viper (using VI bindings in Emacs) is a fair compromise, but it somehow feels cheap, and doesn’t really get away from the Ragtime Typing problem for anything but the most common movements.

In general, I’ve found that Emacs is a better writer than Vim, as it understands the structure of the document much better. However, I’ve found that Vim is a much better editor: I can perform a lot of the common editing commands a lot faster in Vim than in Emacs. It’s missing a few, like word dragging, but that is easily replaced by deleting the word and retyping it in the necessary location.

I think that a great text editor would have the following criteria:

  • Modal (helps cut down on keystrokes).
  • Low typing overhead for 99% of the most common editing tasks.
  • Easy on the C-M chord modifiers for the common tasks.
  • “The Kitchen Sink” philosophy. The programmer should never need to leave the editor to do common tasks like check email, the weather, their RSS reader, play basic games, etc.
  • Great understanding of the document structure, not just best-guessing the tabbing like Vim does.
  • Easy tabs/buffers/frames/windows.
  • Great integration with OS and local tools.

Anything else?

Popularity: 39% [?]

Reader Comments

“I can perform a lot of the common editing commands a lot faster in Vim than in Emacs. It’s missing a few, like word dragging, but that is easily replaced by deleting the word and retyping it in the necessary location.”

You can actually just ‘d’elete and ‘p’aste it where you want it, a raw delete in vim always cuts to the main register. You can also use a different register with “r (where r is the register, not a command).

Overall I agree with you to a degree, vim is optimized for opening and closing instances quickly, instead of having lots of tabs and windows (many panes in a single tab/instance). The repeated opening and closing paradigm is usually abandoned in a large scale project.

#1 
Written By Zubin on April 14th, 2008 @ 2:38 am

Regarding the long lines, I found this simple mapping helped tremendously in dealing with them (goes into your .vimrc):

noremap j gj
noremap k gk

This allows you to navigate /within/ long lines, just as if they were multiple lines, without breaking them up!

#2 
Written By Mikael Jansson on April 14th, 2008 @ 2:41 am

good observations.
I tried switching to emacs from vim and it wasn’t a good experience for me.

Vim was sufficient but the goodies/plugins that emacs offers seems to be irrestible.

#3 
Written By pavan on April 14th, 2008 @ 3:29 am

>A lot of the buffer/window/tab commands in Vim feel like they have too much typing overhead.
Why don’t you customize key mappings to execute that commands?

#4 
Written By kana on April 14th, 2008 @ 3:50 am

I see you tried out Viper. I don’t use it myself since I don’t know vi(m) very well. If there are any special drawbacks to it I am sure the Emacs (yes, it is OK to not write GNU Emacs, I have never seen RMS wanting that) developers might accept feature requests. I like the Vim philosophy but to me it seems it would be awkward when both modifying and entering text. Doesn’t that require you to do a lot of switching between command and editing mode?

I use Emacs not only as a editor but as a application development platform. When you know elisp it is very convenient to hack together small utilities and tools. I use it for playing music, I do IRC, I chat with a powerful Jabber client, I watch movies, I download radio shows, I upload and manage Flickr images, etc…

Good luck in the search of The editor! :)

#5 
Written By Mathias on April 14th, 2008 @ 7:05 am

I more or less agree with all the “criteria” you mentioned for the perfect editor. I normally use VIM, although I’m far from being an expert because the learning curve is quite steep.

I don’t agree too much with the “Kitchen Sink” philosophy: I’d like something fast to launch, which behaves like an editor and feels like an editor. Just that!

Basically I’d like a VIM with a friendlier commands, built-in chord modifiers (although remapping keys does the trick, most of the times), and easily scriptable *natively*.

#6 
Written By Fabio Cevasco on April 14th, 2008 @ 7:10 am

Fabio, have you tried emacs -Q? It’s quite fast on modern systems. Granted, not as fast as Vim. Also, Emacs users seldom close Emacs. We keep it running all day/week/month/year on and use emacsclient to make it open a new file (when you are in a shell, for example, from inside Emacs you use C-x C-f (or whatever easier binding you might have added) as usual, of course).

#7 
Written By Mathias on April 14th, 2008 @ 7:19 am

:tabn[ext]? Bleh! Use gt.

also, gT = :tabp

#8 
Written By Richard Howard on April 14th, 2008 @ 10:47 am

Regarding Vim’s understanding of tabbing for source code, enabling the FileType plugin is a godsend. It actually detects the type of the file being edited (either by file extension or #!/… header, etc), and it then performs smart indenting while editing based on language syntaxes (ie, auto-indenting after { } characters, or …: in Python, etc).

#9 
Written By John Reese on April 14th, 2008 @ 11:01 am

On most default installations of vim you should be able to use ctrl+pgdown/pgup to move back and forth between tabs. And if there’s really a tricky command you use very often you should probably try to look into remapping it to an easier keycombo.

And if I understood your “word dragging” correctly you should be able to perform the same by using dw to delete word and then just w to move forward one word and then P to paste in front of that word.

#10 
Written By Sam on April 14th, 2008 @ 3:40 pm

I wonder if Emacs with a footpedal for CTRL would be any good.

Or, VIM where you used a foot pedal to either toggle modes (normal/insert), or where it stays in insert but the pedal engages normal mode while pressed.

(I think this would be better as it would reduce ‘emacs-pinky’ syndrome and ‘running out of convenient, comfortable, memorable shortcuts’)

“”"Why don’t you customize key mappings to execute that commands?”"”

How can you know that you aren’t overriding some existing shortcuts? Which shortcuts are not used in any modes under any circumstances I might be in?

#11 
Written By s on April 14th, 2008 @ 4:35 pm

I use “gt” to get next tab.

#12 
Written By shannos on April 14th, 2008 @ 4:42 pm

Hmm, there’s an emacs mode that extends viper, supposedly to almost full vim emulation, I forget what it’s called…

#13 
Written By jeo on April 14th, 2008 @ 7:29 pm

“Modal” (by which you mean “alphabetic keys are sometimes commands”)!? Why would you want that?

Sure, I’m biased after over two decades of emacs, but look at the most popular development systems, Eclipse, VB/C++ system – NONE of them are modal – the c key is just a c key.

My email client is not modal; my browser is not modal; Google docs/MS word aren’t modal.

I type a lot, I’m used to just sitting down and typing. The fact that I can cause huge damage to my file this way in vi doing something that works on EVERY other editor I have in my life.

#14 
Written By Tom Ritchford on April 15th, 2008 @ 1:18 pm

@s: I’ve long thought that your feet could be put to good use while typing.

Why not have a foot mouse? With a pedal instead of a button? Then you could use the pedal for a Control key, as you describe.

It would be called a rat.

///ark

#15 
Written By Mark Wilden on April 15th, 2008 @ 3:04 pm

@Tom:

I agree that most ordinary applications should not be modal.

However, I use my text editor to code for 5 or 6 hours a day, so taking the time to learn a new methodology for editing makes sense if it is more efficient. Vim is an expert system, not a beginner’s text editor, so modality helps tremendously when you take the time to learn how it works in all modes.

Emacs, for example, uses C-v as a navigation, and C-y to paste from the clipboard. On a Windows machine, this goes against the grain of being able to do the same thing in every application, but it still helps make editing more efficient. This is perfectly fine, because Emacs is specialized for coding. This is a situation where YMMV. Taking the extra time to learn the different modes is, indeed, extra time. However, I’ve found that over the long haul, it works best for me.

#16 
Written By Jake on April 15th, 2008 @ 3:51 pm

I totally agree with this post, I recently (about 3-4 months ago) switched to using Emacs after being a Vim user for years. I love the Vim keybindings and editing, but Emacs is so much better as a whole IDE.

#17 
Written By Ycros on April 16th, 2008 @ 8:15 am

Hi,

I have been using Viper in XEmacs with the “expert” level set to 5. It has worked wonderfully, allowing me to use the best of both editors. I completely agree regarding the need to have “kitchen sink” capability and modal editing.

In Viper, I tend to use XEmacs keystrokes when I am in insert mode and use vi keystrokes for mostly everything else. The save and undo key combinations in XEmacs come in handy and I tend to use them a lot. Also, dabbrev-complete is unbelievably useful for any editing; I cannot live without this.

Why do you believe Viper is not the way to go?

#18 
Written By Naan Yaar on May 17th, 2008 @ 12:46 am

@Naan:

A Vim user who is looking to customize their environment would do well to consider Viper in X/Emacs and take advantage of the macros/modes that Emacs has to offer, but an Emacs user doesn’t necessarily pick up any big win by using Viper in Emacs. This comes down to something I said in the post: Vim is a better editor, but Emacs is a better writer.

With Emacs, all of the editing power is available as you are writing code for the first time (the time when you make the most mistakes). Emacs has a lower barrier to edit what you just wrote.

It does make sense for an Emacs user to turn on Viper mode after they have written something and have started maintaining it, as editing in Vim is certainly quicker than in Emacs (in my own experience with both editors). However, I suspect that many people either won’t make that distinction, or don’t want to learn two whole editing paradigms for one task.

If you have good results with Viper, then by all means, you should keep using Viper. Text editing is unique to everybody, so keep doing what works for you.

#19 
Written By Jake on May 17th, 2008 @ 11:23 am

joe: vimpulse

#20 
Written By webr on July 13th, 2008 @ 7:21 pm

I too have given VIM and Emacs some rigorous workouts. Two times as an experiment, I have switched from one editor to the other, mid-project.

They both have their strengths and weaknesses. I like Emacs better overall. I think it has better buffer management, better search, and better replace. It integrates with the shell, and it has a nice API.

My favorite feature of Emacs is this: Emacs keeps a stack memory of where you jump around your buffer. You can always get back to where you where by hitting C-u C-SPACE a few times (it’s easier than it looks). This is an extremely useful feature that no other editor has, as far as I know.

Both editors suck at keeping compatible with the key bindings of modern, windowed applications. Except, to a small extent OS X, which provides Emacs’ core key bindings for all its editing fields, and this extends to third-party applications as well.

#21 
Written By Moxley Stratton on July 13th, 2008 @ 11:14 pm

As a programmer, who has tried both Vim and Emacs, I find Emacs to be superior. With Vim I just had to keep hitting the Esc key to switch modes and that gave me what I can describe as the ‘Vim Pinky’ (maybe it is just the structure of my bones).
The commands in Emacs ae also quite intuitive and tend to become second nature in a short time. The buffer management and splitting etc. are quite unparalleled and leave a lot of ground for other editors to cover.
The only reason I needed to learn Vim was because of its ubiquitousness on Unix systems.

#22 
Written By Imad on August 30th, 2008 @ 2:43 pm

One of the reasons you should call Emacs “GNU Emacs” is to inform the people your talking to which version your actually using. Emacs can mean both GNU Emacs, and XEmacs.

#23 
Written By Zen Clark on August 31st, 2008 @ 11:48 am

2Moxley Stratton:
I didn’t know that Emacs has that vim ability to jump to where you where :)
CTRL-O and CTRL-I are uber vim commands!

#24 
Written By Maxim Kim on November 14th, 2008 @ 9:32 am

Add a Comment

required, use real name
required, will not be published
optional, your blog address

Previose Post: