Emacs equivalents of Vim's dd,o,O

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?

For o and O, here are a few functions I wrote many years ago:

(defun vi-open-line-above ()
  "Insert a newline above the current line and put point at beginning."
  (interactive)
  (unless (bolp)
    (beginning-of-line))
  (newline)
  (forward-line -1)
  (indent-according-to-mode))

(defun vi-open-line-below ()
  "Insert a newline below the current line and put point at beginning."
  (interactive)
  (unless (eolp)
    (end-of-line))
  (newline-and-indent))

(defun vi-open-line (&optional abovep)
  "Insert a newline below the current line and put point at beginning.
With a prefix argument, insert a newline above the current line."
  (interactive "P")
  (if abovep
      (vi-open-line-above)
    (vi-open-line-below)))

You can bind vi-open-line to, say, M-insert as follows:

(define-key global-map [(meta insert)] 'vi-open-line)

For dd, if you want the killed line to make it onto the kill ring, you can use this function that wraps kill-line:

(defun kill-current-line (&optional n)
  (interactive "p")
  (save-excursion
    (beginning-of-line)
    (let ((kill-whole-line t))
      (kill-line n))))

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 equivalent dd, o, and O commands.

Equivalence of Emacs and VIM commands, Here is presented the Emacs commands and their standard key bindings when there are some. But many (like myself) alter the default keybindings to type faster � Emacs has been around since 1976, and its name stands for Editor MACroS. The version of Emacs most people use today is called GNU Emacs, which was created by no other than GNU Project founder Richard Stallman. Just like Vim, Emacs runs on basically all operating systems you will ever come across.

C+e C+j

According to the emacs manual docs. That gets you a new line and indentation.

Emacs equivalents of Vim's dd,o,O, For o and O , here are a few functions I wrote many years ago: (defun vi-open- line-above () "Insert a newline above the current line and put� I know, this response is not straight to the point, however like a vim user, I found that Spacemacs is the most functional emacs starter pack to move from vim to emacs. You can configure it to be vim like, emacs like or hybrid.

For dd, use "kill-whole-line", which is bound to "C-S-backspace" by default in recent versions of Emacs.

I should add that I myself use whole-line-or-region.el more often, since C-w is easier to type than C-S-backspace.

Emacs equivalent to VIM ci"?, Off the top of my head, the closest command is M-z " which deletes everything from point to the next occurance of the " character. There is also C-M-k , aka "kill� The equivalent of Vi modelines in Emacs is file variables. As is often the case, the purpose of the feature is the same, but there are differences in the implementation details. The basic syntax of Emacs file variables is a block delimited by -*- characters which must be on the first line of the file.

You could create a macro and bind it to a key sequence. No need to learn any emacslisp yet.

Emacs equivalent of the following vim operation, Emacs has keyboard macros with counter support. The gist of the solution would be (assuming default key bindings):. F3 to start recording a� In vim, all instances of an apple tree can be replaced by an orange tree with :%s/an \zsapple\ze tree/orange/g. \zs and \ze mark the start and end of the passage to be operated on. Is there something equivalent in emacs? As far as I know, evil mode needs the much less elegant :%s/\(an \)\(apple\)\( tree\)/\1orange\3/g

Here's how I addressed the issue of Emacs's lack of a vi-like "O" command:

(defadvice open-line (around vi-style-open-line activate)
  "Make open-line behave more like vi."
  (beginning-of-line)
  ad-do-it
  (indent-according-to-mode))

With this in place, I've never really felt the need for a corresponding version of vi's "o" command. C-n C-o does the trick.

As for the "dd" command, that grated a little at first, but I eventually came around to Emacs's way of doing things. Anyway, when I want to delete several lines at once, which is often the case, I just do it using the region (C-a C-SPC, go to the other end of the text I want to delete, C-w). Or if I can eyeball the number of lines I want to delete, I'll do eg. M-9 C-k to delete nine lines at once.

Is there an Emacs equivalent for vim-bufferline?, I had already some lines of code when KaushalModi mentioned minibuffer-line . Maybe, you should use that mode. If you like you can steal some ideas from the� Vim commands are mostly structured as a movement command plus an editing command, which is very regular, whereas Emacs tends to combine both functions in a single command in a much more ad-hoc way.

[PDF] Advanced Emacs, Emacs equivalent of the .vimrc. ○ Single file holding configuration information written in Emacs Lisp. ○ .emacs.d directory often used to hold multiple files. Basically I want the emacs equivalent of vim's "global" command. keep-lines and flush-lines only take me 90% of the way there. Other variants of this problem I've run across in the last few days include (a) join matching lines with next line, and (b) delete last word of matching lines.

Emacs or Vim? Get the Best of Both with Evil, vimrc and map them to equivalent Emacs functions. This task was actually relatively painless, since most of the ported functionality already exists� I originally started with VI (real VI not VIM) and later started using Emacs. These days, I tend to use both, but emacs more because emacs has some features I need which are not in vim. The real challenge and what you should be aiming for is how to be as efficient, quick and accurate as possible with your editor of choice.

My pragmatic decision on GNU Emacs versus vim , I'm sure that there's an equivalent plugin setup for vim and an experienced vim person could get it up and running in no time flat, but I'm not that� Vim-mode is another implementation for Vi and Vim-like key bindings for Emacs. It is a complete new implementation from scratch with extensibility in mind. There are several other packages emulating Vim features, see CategoryEmulation for an overview.

Comments
  • I think best method for new line is this superuser.com/a/331661 (C-e C-j)
  • Wow great, thanks. Works like a charm :) Just the vi-open-line-above does not indent. Any ideas?
  • I added (indent-according-to-mode) in vi-open-line-above below (forward-line -1). This does the trick :)
  • Funny, I was in the middle of editing it again when you noted that you found the solution. As you can tell, this is old code that I don't use often. I wrote it when I first learning Emacs Lisp. This question gave me an excuse to freshen it.
  • if you are in the middle of a sentence or line, and c+j it will put the rest of the line on the new line. it's like hitting return in the middle of the line. we want to add a blank line below the current cursor position.
  • This sounds awkward to me. If I want to use vim, then I use vim not emacs.
  • Emacs' keybindings may(!) not be ergonomic, but for me at least, vi's modal **** grates on my brain.
  • @eteubert not awkward at all. just think of emacs as the 3rd (or 4th) mode. it actually feels natural once you've picked up emacs and everything resides within emacs.