2009.07.02 in uncategorized

Emacs and Vim

Last week I finally managed to switch to Emacs. I've meant to try this several times before, in particular when Richard Stallman, the original author of Emacs, stayed in my room for a night when he visited RPI. I had been using Vim since I switched to GNU/Linux. At that time, the Emacs keys made no sense. Also, in various Linux-related tutorials, Vim was usually mentioned first and there was no point in learning 2 editors.  I've found that moving around the text in Emacs is a bit easier, and the same as bash (and actually made me aware of more bash shortcuts). Since I had moved on from using qwerty over a year ago, I've been using the arrow keys instead of h, j, k, l. I never bothered to rebind the keys, which also would be annoying.  There are a number of things that annoy me about Emacs.

The syntax highlighting in Vim is nicer. First of all, the syntax highlighting of types in C in Emacs figures out what to highlight as a type based on context. Because of this, as you go along the colors change and it's kind of annoying. This also doesn't give you the alert that you would get in Vim when you make a typo and it doesn't change color, although the Vim way had the disadvantage of needing to specify the types in some syntax config file for more obscure types from a certain library, such as mpfr_rnd_t or something like that. Special escaped characters in strings, such as '\n' for newline or '\t' for tab, aren't highlighted in Emacs, but they are in Vim. The whole preprocessor directive is highlighted in Vim, but not in Emacs. Numeric constants aren't highlighted in Emacs. #if 0'd out sections are highlighted as comments, but not in Emacs. These things I could probably configure, although I'm rather lazy and probably won't look into it. My other issue with Emacs syntax highlighting is the theming. There seem to be no good themes in the only large collection I can find. The ones that could almost be the same as my old theme from Vim have odd things wrong with them, such as having strings or comments italicized and totally unreadable.

I've lost lots of time trying to get a usable config. I fought especially long trying to get indentation that makes sense. The default "GNU" indentation style is basically the worst thing ever, with braces halfway indented and such. Once I got an indentation style, Emacs forces you to that style. The tab key sent the current line to the "correct" indentation for that line. I wanted tab to just insert 4 spaces, and when I went to a new line to have it go to a suggested indentation level. This was frustrating primarily for 2 reasons. First, I like to indent my comments after lines of code, and try to line my comments up off to the side. I think it looks neater that way. Also, it would not allow you to indent preprocessor directives, which was annoying when dealing with OpenMP, where it makes sense to indent the #pragmas for parallelizing loops and such. I eventually gave up on getting tab to do what I want, and ended up just using M-i to tab in where I wanted to outside of the indentation guidelines, and rebinding enter to newline and indent.

I still can't do everything I used to be able to do in Vim. I haven't looked into a few things yet. But overall, I seem to do things more efficiently, and do things I never bothered learning in Vim. Emacs macros are also wonderful.

blog comments powered by Disqus