From b3f5950598280eeeb9eecc03fcc28fd7d2af0db2 Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Thu, 30 Mar 2023 03:02:49 +0200 Subject: [PATCH] vterm: bypass line wraps in the prompt line When the command in the prompt line is so long that it wraps to multiple lines, movements such as `h`, `l`, `^`, and `$` IMHO behave unexpectedly. In normal terminal emulators outside of Emacs, a long prompt line contains only soft-wraps, i.e. being at the last character before a wrap and pressing `` moves the cursor to the first character of the next line. This is also how vterm behaves without Evil. I am changing `h` and `l` to behave the same way. While doing so, I am doing the same for `^` and `$`. --- modes/vterm/evil-collection-vterm.el | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/modes/vterm/evil-collection-vterm.el b/modes/vterm/evil-collection-vterm.el index a77ee211..648cae40 100644 --- a/modes/vterm/evil-collection-vterm.el +++ b/modes/vterm/evil-collection-vterm.el @@ -223,6 +223,22 @@ But don't allow the cursor to move bellow the last prompt line." (when (> (count-words (point) (point-max)) 0) (evil-next-line count))) +(evil-define-motion evil-collection-vterm-forward-char + (count &optional crosslines noerror) + "Move cursor to the right by COUNT characters, bypassing line wraps." + :type exclusive + (if (get-text-property (1+ (point)) 'vterm-line-wrap) + (forward-char 2) + (evil-forward-char count crosslines noerror))) + +(evil-define-motion evil-collection-vterm-backward-char + (count &optional crosslines noerror) + "Move cursor to the left by COUNT characters, bypassing line wraps." + :type exclusive + (if (and (not (bobp)) (get-text-property (1- (point)) 'vterm-line-wrap)) + (forward-char -1) + (evil-backward-char count crosslines noerror))) + ;;;###autoload (defun evil-collection-vterm-setup () "Set up `evil' bindings for `vterm'." @@ -265,12 +281,10 @@ But don't allow the cursor to move bellow the last prompt line." "P" 'vterm-yank "a" 'evil-collection-vterm-append "A" 'evil-collection-vterm-append-line - "d" 'evil-collection-vterm-delete "D" 'evil-collection-vterm-delete-line "x" 'evil-collection-vterm-delete-char "X" 'evil-collection-vterm-delete-backward-char (kbd "RET") 'vterm-send-return - "^" 'evil-collection-vterm-first-non-blank "i" 'evil-collection-vterm-insert "I" 'evil-collection-vterm-insert-line "u" 'vterm-undo @@ -282,8 +296,15 @@ But don't allow the cursor to move bellow the last prompt line." "G" 'vterm-reset-cursor-point) (evil-collection-define-key 'visual 'vterm-mode-map + "x" 'evil-collection-vterm-delete-backward-char) + + (evil-collection-define-key '(normal visual) 'vterm-mode-map "d" 'evil-collection-vterm-delete - "x" 'evil-collection-vterm-delete-backward-char)) + "l" 'evil-collection-vterm-forward-char + "h" 'evil-collection-vterm-backward-char + "$" 'vterm-end-of-line + "^" 'evil-collection-vterm-first-non-blank)) + (provide 'evil-collection-vterm) ;;; evil-collection-vterm.el ends here