Most programming languages are line-oriented and Vim’s visual-line mode
suits this very well. In Vim I can press V
and then j
three times
and I will have selected three whole lines for acting upon. In Emacs I
have to first move to the beginning of the line with C-a
, then start
selecting with C-SPC
, then go down three lines by pressing C-n
three
times, and finally press C-e C-f
to move to a position such that three
complete lines are selected. This is uncomfortable.
Lots of Emacs users use kill-whole-line
to kill a line without it
mattering whether your cursor is at the beginning or in the middle of
that line. I don’t find this comfortable, I think because I don’t want
to choose whether I’m doing a line-wise or character-wise selection
until after I’ve starting highlighting my selection. I want to expand my
selection to take up the beginning and ends of the lines. This feels
like an operation similar to what expand-region.el
does. The following
piece of advice makes one’s er/expand-region
keybinding expand one’s
character-wise selection into something of a line-wise selection,
provided you haven’t use expand-region
to make the current selection.
So it takes you from this:
?expandregionlines1.png
to this:
?expandregionlines2.png
(require 'expand-region)
(defadvice er/expand-region (around fill-out-region activate)
(if (or (not (region-active-p))
(eq last-command 'er/expand-region))
ad-do-it
(if (< (point) (mark))
(let ((beg (point)))
(goto-char (mark))
(end-of-line)
(forward-char 1)
(push-mark)
(goto-char beg)
(beginning-of-line))
(let ((end (point)))
(goto-char (mark))
(beginning-of-line)
(push-mark)
(goto-char end)
(end-of-line)
(forward-char 1)))))