Visual move line down
Hi there, 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 So far, this is what I have (ignoring the reindent portion for now): (evil-define-operator my-move-line-down (beg end type) "Move selected lines down" (evil-move beg end (+ 0 (line-number-at-pos end))) (call-interactively evil-visual-restore) ) (define-key evil-visual-state-map (kbd "J") 'my-move-line-down) It has a few problems: evil-visual-restore doesn’t work like it does in vim, in particular, it is restoring to include the original first line of the selection as well as the text that has moved. In other words, if I select 2 lines, then hit J, 3 will be selected afterwards, the selection expands down instead of moving down. I can’t figure out how to get the count such that 3J would move down 3 lines. I’d like to replace the 0 with the count. I’m not sure if I’m supposed to use evil-move in this way, it seems to work, but I don’t know if it is abusing a command. Originally I tried to do this by programmatically executing an ex command but apparently that is a no-no. Thanks! Aaron
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, Frank
Aaron Jensen <aaronjensen <at> gmail.com> writes:
evil-visual-restore doesn’t work like it does in vim, in particular, it is restoring to include the original first line of the selection as well as the text that has moved. In other words, if I select 2 lines, then hit J, 3 will be selected afterwards, the selection expands down instead of moving down.
Frank Fischer added https://bitbucket.org/lyro/evil/commits/a1ce5b51471d which makes the selection restore properly if I use `:move` as a command, but when I use it programmatically as in the original function it still expands the selection instead. One more issue I noticed: The operator as defined does not create a new undo step (or whatever it is called) and instead appends to the last thing I actually did. Is there something I need to do for that?
On 06.03.2016 19:41, Aaron Jensen wrote:
One more issue I noticed:
The operator as defined does not create a new undo step (or whatever it is called) and instead appends to the last thing I actually did. Is there something I need to do for that?
Please provide a reproducible example starting with `make emacs` in Evil's source directory. Frank
_______________________________________________ implementations-list mailing list [email protected] https://lists.ourproject.org/cgi-bin/mailman/listinfo/implementations-list
participants (2)
-
Aaron Jensen -
Frank Fischer