Thursday, January 3, 2008

My Emacs Encounter

An old vim user: This is the trap of the Catholics.
A somewhat-old vim user trying emacs: Now *sigh* I want to be a Protestant again.
Whenever I visit a website or read a book which says something about any editor, its mostly about emacs or vim and most of them talk about emacs only.

I have been reading a lot about emacs so I thought why don't give it a shot. I want to tell you that I have been using vim from quite long, almost two years now, since I started writing code. I wrote the first "hello world" of my life in vim, and it was really a very good experience.

So lets try emacs. I typed emacs on my terminal and what I got was a separate window of the powerful rhino with a very neat look and a lot of options to manipulate text on its Toolbar a lot like GVim. I played with it for a while and then tried to know more about it. I started its tutorial to know it's basics.

First thing its tutorial teaches you is the movement of the cursors on the screen. Its straight C-p, C-n, C-f, C-b are used to move the cursor to the previous line, next line, one character forward on the same line and one character backwards respectively. The same movement of the cursor in Vim is achieved using k, j, l, h. You can also use the arrow keys to move the cursor but it is recommended to use the other key combinations so that while editing you won't have to move your fingers away from the touch-typing position of the keyboard. These key combinations, both of Vim and emacs, let you move the cursor very fast throughout your text.

But truly, I don't like the C-p, C-n, C-f, C-b of emacs because you have to hold the C or the Ctrl key of the keyboard for all the time. My little finger started aching after a while. Moreover the characters p, n, f and b are scattered on the typing pad far-far away from each other. You can't really use these key combinations unless You really have long fingers (thank god my fingers are long enough). You actually have to wrestle with the keyboard while using these key combinations.

With a lot of pain in my fingers I was still going through *the mighty* emacs Tutorial. There a are several jobs in emacs which can be done in the Vim in fewer key strokes. Two to tell you are C-L (Ctrl-Shift-l) these are three keys to put the current line under the cursor in the middle of the window in Vim you have to use zz and to view the next and previous screen full of text in emacs you have C-v and M-v (M is your Meta or Alt or Esc key) the same thing in Vim is done using PageUp and PageDown keys.

I really don't want to talk about which editor is superior. You use what You have been using and what suits Your needs more. There is no point in learning to use a new editor when you already know a lot about the other one. Moreover there a lot of features in both Vim and emacs both which We won't use in our entire coding career.

4 comments:

Kazim Zaidi said...

If those are the key combinations, I'd find emacs cumbersome too.

+1.

When I was introduced to programmable editors, I was told about two. vi and emacs. People told me, vi is quick to learn and get accustomed to, but is less modular and programmable. emacs on the other hand, requires more courage to learn it, but is highly programmable.

As it turned out, I (and most of us) prefer ease over power. Many differ. But IMHO, these programmable editors have far more features than an average programmer ever uses in his life. That opinion also makes me choose vi.

No flamebaits intended.

tuxdna said...

Dimlomatic View:

Use right editor for the right job.

Fair View:

Here are a few features which you should like to consider before picking up an editor:

Version Control Integration ( CVS, SVN etc )

Code Browsing

Command Shell

Mail Client

Remote Editing

Your own macros for various purposes

Now keeping these features in mind, which I believe that any coder will frequently use, if you can manage to do all the things mentioned above outside editing session ( by closing/suspeding the editor ), then suggest Vi is better.

If you want to have all those ( and many more ) features just inside your editor, then Emacs is the best choice. *No other editor* in this world is so powerful. Moreover you will save a lot of your time! I do agree that you have to try hard to learn all those *weird* C-p, C-n keystrokes, but its worth once you have mastered those.

Most of the time I use Emacs and sometimes Vi.

Happy coding ;-)

Waseem Ahmad said...

That's a really long list of features that emacs has. I wish people are working on including these features in vim too.

emacs is indeed a very powerful editor, much more than vim, perhaps *the* most powerful editor in the world. But the main thing about the emacs i didn't like was the key combination it uses for the movement of the cursor. Really it's literally very painful to move the cursor in the emacs from one position to another in the file. Perhaps it wasn't designed taking ergonomics for the US keyboard in consideration by rms.
I saw the UNIX style keyboard in my college and tried to *virtually* practice some of it's key strokes mainly the cursor movement ones and really seem much easier to practice them. Perhaps rms have been using UNIX keyboard those days.
I think I will start using emacs when someone maps the h, j, k, l keys to emacs for cursor movement or when I won't have any other option except to use emacs.

tuxdna said...

The time when EMACS keybindings were designed, the US keyboards were not so popular ( perhaps ). you may look
here for details. So, I would suppose that it's not RMS's fault ( nor he intended to ).

Also that Emacs key-bindings were indeed designed keeping Ergonomics in mind.

If you would like to make it more convenient then try swapping CapsLock and Control key ( left ) here or here

You can also try VIPER mode in Emacs for Vi emulation :-)
I hope it will surely help.

--tuxdna