There’s no denying that vi has a great set of keybindings. For pure editing rather than writing I’ll often use Evil mode – an extensible vi layer for Emacs (See below for installation). Vi key combinations are often easier on the fingers: hitting dd to kill a line is easier than C-S-Backspace any day. I also find navigating with hjkl preferable to C-p, C-f and so on.
That got me thinking. What is it about the vi commands that make them so good for editing? What’s more, as I edit in a different way using vi, can any of those methods make my Emacs use more efficient?
I took a break a moment ago to reflect on what I’d just written and came to the conclusion that I really am as boring as my wife keeps telling me. But what the heck. I find it fun, and the fact that you’re still reading shows that you think this is interesting too.
So here goes.
One vi feature I use a lot is f . to find the end of a sentence. Now I know that you can jump to the end of sentence using M-e, but this only works if there are two spaces after the full stop, and fewer and texts follow this convention nowadays.
You can replicate this in Emacs using C-s . The thing is, I never thought of doing that until I stopped to think about my vi habits. That led me to using M-z . to delete to the end of the sentence (this is similar to df . in vi).
I’ve written elsewhere about using C-s more often. The fastest way I know to jump to a word I can see on the page is to C-s (word).
Bearing that in mind, there’s a nice trick in vi where you c/pattern to clear up to a pattern. So if I wanted to clear all the words from here to this 34 I’d hit c/34
Thinking about that has led me to doing the following in Emacs
C-Space C-s 34 Enter C-w
In other words
C-Space to set the mark; C-s 34 to jump to 34 and then C-w to clear. More keystrokes, true, but you’re not constantly shifting between modes.
There are advantages to modes, of course. I love the fact that “ jumps back to the last edit in vi. You can partially replicate this in Emacs using C-Space C-Space to push a point to the mark ring, and then you can jump back using C-u C-Space. It’s not the same, but it will do.
(setq set-mark-command-repeat-pop 't)
in your .emacs file allows you to just keep hitting C-Space after that initial C-u C-Space. The mark ring is set to 16 by default. With this setting you can go round and round your last 16 marks as many times as you care to hit C-Space
(require 'evil) (evil-mode 1) (define-key evil-normal-state-map (kbd "<remap> <evil-next-line>") 'evil-next-visual-line) (define-key evil-normal-state-map (kbd "<remap> <evil-previous-line>") 'evil-previous-visual-line) (setq-default evil-cross-lines t)
Thanks for set-mark-command-repeat-pop tip!
There’s a setting to be “modern day” compliant:
Of course! Thanks for the tip, Bounga!