One thing nice about Vim is manipulating whole lines at a time.
dd deletes a line (including trailing newline), regardless of where the cursor is on the line. Then,
p puts that line (with its newline) as a new line after the current line, and
P puts it above the current line, again regardless of where your cursor is at the moment. (It also jumps the cursor to the beginning of the text you just inserted, which is nice.)
C-S-Backspace) which is like Vim's
dd. But I didn't find an equivalent of
P. So here's my version:
(defun yank-with-newline () "Yank, appending a newline if the yanked text doesn't end with one." (yank) (when (not (string-match "\n$" (current-kill 0))) (newline-and-indent))) (defun yank-as-line-above () "Yank text as a new line above the current line. Also moves point to the beginning of the text you just yanked." (interactive) (let ((lnum (line-number-at-pos (point)))) (beginning-of-line) (yank-with-newline) (goto-line lnum))) (defun yank-as-line-below () "Yank text as a new line below the current line. Also moves point to the beginning of the text you just yanked." (interactive) (let* ((lnum (line-number-at-pos (point))) (lnum (if (eobp) lnum (1+ lnum)))) (if (and (eobp) (not (bolp))) (newline-and-indent) (forward-line 1)) (yank-with-newline) (goto-line lnum))) (global-set-key "\M-P" 'yank-as-line-above) (global-set-key "\M-p" 'yank-as-line-below)
Just one more step along the path to Vimmify my Emacs setup. Emacs has some weird edge cases because you can move the cursor one "line" past the last real line in the file. But I think I worked out something comfortable for myself.
PS: I've written about this before, but if you use
C-S-Backspace a lot in Emacs on Linux, I highly recommend putting this into your X11 config:
Option "DontZap" "True"
It's really easy to mix up
C-M-Backspace (the latter of which kills your X server). It's not fun to mix those up. Not fun at all.
PPS: This thread on Stack Overflow has some Emacs equivalents of Vim's
O which are pretty nice too.