I am currently playing around with emacs and happy with most of the concepts. But I really adored the convenience of the three vim commands: dd,o,O
Hopefully you can tell me how to mirror them in emacs 🙂
dd – deletes whole line, including newline, no matter where the cursor is.
I found something similar to do the trick:
C-a C-k C-k
While C-a
moves the cursor to the beginning of the line, the first C-k
kills the text, the second one kills the newline. The only problem is that this is not working on empty lines where I only need to type C-k
which is quite inconvenient as I have to use different commands for the same task: killing a line.
o / O – creates a new empty line below / above cursor and moves cursor to the new line, indented correctly
Well, C-a C-o
is nearly like O
, just the idention is missing. C-e C-o
creates an empty line below the current but does not move the cursor.
Are there any better solutions to my problems or do I have to learn Lisp and define new commands to fulfill my needs?
Best Answer
For
o
andO
, here are a few functions I wrote many years ago:You can bind
vi-open-line
to, say, M-insert as follows:For
dd
, if you want the killed line to make it onto the kill ring, you can use this function that wrapskill-line
:For completeness, it accepts a prefix argument and applies it to
kill-line
, so that it can kill much more than the "current" line.You might also look at the source for
viper-mode
to see how it implements the equivalentdd
,o
, andO
commands.