-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
move-text-down does not maintain proper selection when using visual line mode #5365
Comments
Reported in evil as well: https://bitbucket.org/lyro/evil/issues/630 |
FYI, closed as invalid on evil. We may need our own version of |
Could not this be reported upstream on |
I've been searching for a replacement for this too for a couple of days and I haven't found any that works well with evil, which is rather anoying since this is a one liner for each direction in vim: vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv |
@jcalve I've got it close, but it doesn't quite work, see http://emacs.stackexchange.com/questions/20782/programmatically-execute-evil-ex-move-command |
@jcalve w/ the latest, soon to be on MELPA evil, this works: (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")) |
@aaronjensen that's great, mr. Fischer delivering the goods, I think that closes this issue |
I'm going to close this out, but I wonder if it'd make sense to update spacemacs/layers/+vim/unimpaired/keybindings.el Lines 9 to 10 in 074f425
gv afterwards?
|
I re-open to fix the key bindings in related evil states. |
@syl20bnr are you just thinking of just making the visual bindings as I have J/K up there? If so, can pull request, if not, just let me know what you're thinking |
Is it possible to use Ctrl+j ? In vim J even in visual mode is concatenation of lines. |
^on latest master (just updated packages) System Info
(auto-completion emacs-lisp sql elixir
(ruby :variables ruby-version-manager 'rvm ruby-enable-enh-ruby-mode t)
ruby-on-rails dash markdown org vinegar) |
@aaronjensen I don't personally use spacemacs, but I found this conversation interesting. This is more of a thought aloud, and I don't know if this will actually be useful to anyone, but perhaps this could be more generalized into moving both lines and regions based on context? Kind of like this (excuse my probably messy emacs-lisp): (defun move-line-or-region (arg)
(interactive "P")
(if (or (not arg) (>= arg 0))
(let ((reg-or-lin (if (region-active-p) "'>" "."))
(reactivate-region (if (region-active-p) "gv=gv" ""))
(num (if arg arg 1)))
(execute-kbd-macro
(concat ":m" reg-or-lin "+" (number-to-string num) (kbd "RET") reactivate-region)))
(backward-move-line-or-region (- arg))))
(defun backward-move-line-or-region (arg)
(interactive "P")
(if (or (not arg) (>= arg 0))
(let ((reg-or-lin (if (region-active-p) "'<" "."))
(reactivate-region (if (region-active-p) "gv=gv" ""))
(num (if arg (+ arg 1) 2)))
(execute-kbd-macro
(concat ":m" reg-or-lin "-" (number-to-string num) (kbd "RET") reactivate-region)))
(move-line-or-region (- arg))))
These functions probably shouldn't depend on each other, but it's just an idea. |
I have been using the code provided by @aaronjensen for quite some time and it was working really well. But recently it stopped working with the error as I then found this project https://github.com/rejeep/drag-stuff.el and with below code everything works fine
|
Nice, I'll give this a shot, thanks for the tag :) It must be emacs 27, i'm still on 26 and it's fine. I noticed this package doesn't indent when you move, but as such it's much faster. I'm probably good w/ that, but maybe I'll update it to indent afterwards some time. |
The When it's enabled in the user-config: (setq vim-style-visual-line-move-text t) Then One issue is that the selection changes after moving a char or block selection. To be consistent, moving selected lines should probably also work with spacemacs/layers/+spacemacs/spacemacs-editing/packages.el Lines 202 to 213 in bd77a5d
and with spacemacs/layers/+spacemacs/spacemacs-evil/local/evil-unimpaired/evil-unimpaired.el Lines 90 to 91 in bd77a5d
And the selection should probably not change. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid! |
To echo @duianto last comment, |
I don't know if something's changed, or if I made a typo in my previous comment ☝️. Because I said that enabling the variable: But when I try it now, by adding it to the Then the keys still call the default evil normal actions:
It works from user-initIt does work after setting the variable in the Windows 1903#### System Info :computer: - OS: windows-nt - Emacs: 26.3 - Spacemacs: 0.300.0 - Spacemacs branch: develop (rev. c3f13d039) - Graphic display: t - Distribution: spacemacs - Editing style: vim - Completion: helm - Layers: ```elisp (autohotkey auto-completion command-log emacs-lisp git helm html imenu-list (java :variables java-backend 'meghanda) javascript latex lsp (markdown :variables markdown-live-preview-engine 'vmd markdown-command "vmd") multiple-cursors (org :variables org-agenda-files '("~/org/notes.org")) pdf python (shell :variables shell-default-shell 'shell shell-default-height 30 shell-default-position 'bottom) spell-checking (syntax-checking :variables syntax-checking-enable-by-default nil) treemacs version-control) ``` - System configuration features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS THREADS LCMS2 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid! |
The following PRs changes have been applied to the The text can now be dragged up and down with the commands: Or the key bindings:
The lines can be dragged and the drag stuff transient state can be opened at the same time with:
Or the drag stuff transient state can be opened without moving any text, with:
There are also commands for dragging words or selected characters left and right: Dragging left and right are included in the drag stuff transient state:
There's a bug when dragging a word left and right, if the cursor is on the first letter of a word. It's been reported upstream: |
Description
If you select multiple lines with visual line mode
V
and thenM-x move-text-down
the resulting selection is incorrect. You should be able to repeatM-x move-text-down
and continue to move the same text without having to reselect. Compare to hybrid/holy mode when you useC-SPC C-n C-n
to select multiple lines.Note, move-text-down and move-text-up are bound to
] e
and[ e
respectively by https://github.com/syl20bnr/spacemacs/blob/074f425dc5d233f24195ecc3021eb96ac9d55d4d/layers/%2Bvim/unimpaired/keybindings.elAlso,
SPC x J
is bound as part of core and it is broken as well in visual line mode.Reproduction guide
Start Emacs in evil mode
SPC b s
Enter text:
Go to line 3 and
V j j
M-x move-text-down
(can also useSPC x J
)M-x move-text-down
Observed behaviour:
Text is moved correctly, but line 5 is selected after first
move-text-down
. After second, line 5 moves down a line. Resulting in 1, 2, 3, 5, 4, 6.Expected behaviour:
After first
move-text-down
lines 2 and 3 should remain selected. The second should move them down again, making the line order 1, 2, 5, 6, 3, 4. This is how it works if you were to use hybrid/holy mode and select withC-SPC C-n C-n
instead.System Info
The text was updated successfully, but these errors were encountered: