As readers of this blog may remember, back in 2011, I decided to move to a command-line based editor. For roughly two weeks in December, 2011, I exclusively used Vim, and for the same amount of time in January, 2012, I used exclusively Emacs. I had used a little of each editor in the past, but this was my first time using them to do true editing work. My experiences are chronicled in my blog posts (parts 1, 2, 3, and 7 months later follow up).
To summarize, I decided to use Emacs, as I found it to be much more intuitive, and much more user-friendly. Today, January 1, marks the one-year point of my using Emacs as my sole text editor, with some exceptions (notably, I’m currently writing this blog post in the browser). So I’d like to make some observations:
M-x customize), but on the other hand, Vim’s scripting language is much easier to hack on than Emacs lisp (I still can’t code in Lisp to save my life; it’s a very challenging programming language).
But my point here is that neither has really great defaults. For example, in Emacs,
M-space is bound to
just-one-space, which is great for programming. What it does is remove all spaces around the cursor, except for one. But to be really useful, it also should include newlines. It doesn’t do this by default. Rather, you have to call it with a negative argument. So to be really useful, you have to add
(defun just-one-space-with-newline () "Call just-one-space with a negative argument" (interactive) (just-one-space -1)) (global-set-key (kbd "M-SPC") 'just-one-space-with-newline)
M-w(Emacs version of copy). And if a feature involves several keystrokes to access, forget about it (for example, rectangular selection, or any features of special modes). If I use a new mode, e.g., for some file type that I rarely edit (like HTML), I might as well not have any of the features, other than the syntax highlighting, because I either don’t know what they are, or even if I know that they should exist (like automatic tag completion for html), I have no idea how to access them.
There’s really something to be said about GUI editors, which give these things to users in a way that they don’t have to memorize anything. Perhaps I should try to use the menu more. Or maybe authors of addons should aim to make features require as little cognitive user interaction as possible (such as the excellent
auto-complete-mode I mentioned in part 3).
I mention this because it is one of the things I complained about with Vim, that the keybindings were too hard to memorize. Of course, the difference with Vim is that one has to memorize keybindings to do even the most basic of editing tasks, whereas with Emacs one can always fall back to more natural things like
Shift-Arrow Key to select text or
Delete to delete the character under the cursor (and yes, I know you can rebind this stuff in Vim; I refer you to the previous bullet point).
emacsclientany more. Ever since I got my new retina MacBook Pro, I don’t need it any more, because with the solid state drive starting Emacs from scratch is instantaneous. I’m glad to get rid of it, because it had some seriously annoying glitches.
alias e=emacsto your Bash config file (
.bashrc). It makes life much easier. “emacs” is not an easy word to type, at least on QWERTY keyboards.
C-u 4 C-x TAB, actually
C-c u 4 C-x TAB, since I did the sensible thing and rebound
C-uto clear to the previous newline, and bound
C-c u) come to mind).
I feel as if I were to watch someone who has used Emacs for a long time that I would learn a lot of tricks.
imenu. If you know of anything, please let me know. One thing I really liked about Vim was the tag list extension, which did this perfectly (thanks to commenter Scott for pointing it out to me). I’ve been told that Cedet has something like this, but every time I try to install it, I run into some issues that just seem like way too much work (I don’t remember what they are, it won’t compile or something, or maybe it just wants to do just way too much and I can’t figure out how to disable everything except for the parts I want).
check-syntax: $(CC) -o nul $(FLAGS) -S $(CHK_SOURCES)
(and if you don’t use a Makefile, start using one now). This is assuming you have
FLAGS defined at the top (generally to something like
-Wall, respectively). Also, add the following to your
;; ===== Turn on flymake-mode ==== (add-hook 'c-mode-common-hook 'turn-on-flymake) (defun turn-on-flymake () "Force flymake-mode on. For use in hooks." (interactive) (flymake-mode 1)) (add-hook 'c-mode-common-hook 'flymake-keyboard-shortcuts) (defun flymake-keyboard-shortcuts () "Add keyboard shortcuts for flymake goto next/prev error." (interactive) (local-set-key "\M-n" 'flymake-goto-next-error) (local-set-key "\M-p" 'flymake-goto-prev-error))
The last part adds the useful keyboard shortcuts
M-p to move between errors. Now, errors in your C code will show up automatically as you type. If you use the command line version of emacs like I do, and not the GUI version, you’ll also need to install the flymake-cursor module, which makes the errors show up in the mode line, since otherwise it tries to use mouse popups. You can change the colors using
M-x customize-face (search for “flymake”).
Actually, what I really would like is not syntax checking (I rarely make syntax mistakes in LaTeX any more), but rather something that automatically builds the PDF constantly as I type. That way, I can just look over at the PDF as I am writing (I use an external monitor for this. I highly recommend it if you use LaTeX, especially one of those monitors that swivels to portrait mode).
C-e, etc.), but that only works in Cocoa apps, and it doesn’t include any meta key shortcuts. This lets you use additional shortcuts literally everywhere (don’t worry, it automatically doesn’t use them in the Terminal), including an emulator for
Command-s). It doesn’t work on context sensitive shortcuts, unfortunately, unless the operating system already supports it with another keyboard shortcut (e.g., it can map
Option-right arrow). For example, it can’t enable moving between paragraphs with
C-S-}. If anyone knows how to do that, let me know.
(add-hook 'latex-mode-hook 'auto-complete-mode) (add-hook 'LaTeX-mode-hook 'auto-complete-mode) (add-hook 'prog-mode-hook 'auto-complete-mode) ;; etc.
Vim is great for text editing, but not so hot for text writing (unless you always write text perfectly, so that you never need to leave insert mode until you are done typing). Just the simple act of deleting a mistyped word (yes, word, that happens a lot when you are decently fast touch typist) takes several keystrokes, when it should in my opinion only take one (two if you count the meta-key).
Needless to say, I find Emacs to be great for both text editing and text writing.