Visual move line down

Frank Fischer frank-fischer at
Sun Mar 6 19:10:40 CET 2016

On 06.03.2016 17:07, Aaron Jensen wrote:
> I’m trying to reimplement this handy vim snippet:
> vnoremap J :m '>+1<CR>gv=gv
> vnoremap K :m '<-2<CR>gv=gv
> What it does is it moves visually selected lines down with J and up with
> K, reindenting them as it goes and maintaining the same visual selection
> so it is easily repeatable w/ J/K

I do not know if it does what you want, but with the latest change (it's
probably not yet in melpa), the following, which is quite similar to
your vim code, should work.

  (define-key evil-visual-state-map "J" ":m '>+1^Mgv=gv")
  (define-key evil-visual-state-map "K" ":m '<-2^Mgv=gv")

Note that ^M is a literal RET character. It can be entered in Evil by
C-v C-m. Alternatively you can use

  (define-key evil-visual-state-map "J"
    (concat ":m '>+1" (kbd "RET") "gv=gv"))
  (define-key evil-visual-state-map "K"
    (concat ":m '<-2" (kbd "RET") "gv=gv"))

Best regards,

More information about the implementations-list mailing list