2
votes

I am a vi/vim person at heart but I use LaTeX a lot and I really like AUCTeX Preview so I have been using emacs with viper until recently, but I am now trying evil instead. I am however certainly no emacs expert.

Visual line mode in emacs is terrific with AUCTeX Preview because when the Preview images are activated, the line lengths are all mucked up, but if each paragraph is really only one long line, in visual line mode it all looks great whether the Preview images are activated or not.

One thing that has always annoyed me is that viper commands like 'j' and 'dd' only work on "logical lines", not screen lines. In vim one would instead use 'gj' instead of 'j', and indeed this is how evil works. However there is no equivalent for 'dd'.

I came across the answer to a SO question addressing this for vim and it seems to do the trick :nnoremap dd g0dg$. Indeed typing the "right-hand side" in evil (even with a numerical prefix) works exactly as it should.

However I cannot easily see in the evil documentation how one might achieve this remapping. I have seen a detailed answer to a general SO question about evil but all its suggestions and examples show how to map a key sequence to a single already-defined evil function. I can't see any examples where an existing evil key sequence is remapped to another (possibly longer) existing evil key sequence.

I guess I could replace the "right-hand side" of the mapping with a sequence of existing evil functions, but I'm not sure how one might do that. Or I could just use a basic emacs key remapping but I fear that this will interfere with evil's different modes/states, or simply just won't work.

Does anyone have any ideas?

1

1 Answers

2
votes

Here's a basic function that does what I think you want (note that it doesn't do the other nice things like counts that Vim/Evil provide; use evil-define-command for that). You'll clobber some keybindings if you try to map it to gdd, so as a workaround, you could map it to gD (or whatever you like):

(defun evil-delete-visual-line ()
  (interactive)
  (let ((beg (progn (beginning-of-visual-line) (point)))
        (end (progn (end-of-visual-line) (point))))
    (evil-delete beg end)))

(define-key evil-normal-state-map "gD" 'evil-delete-visual-line)