0

Similarly to the question Cursor moves one position left after exiting insert mode? I would like to know the similar thing, but now for the append command. I want the cursor to stay when exiting both insert and append. The command

(setq evil-move-cursor-back nil)

lets the cursor stay for insert, but now the cursor moves for append. Is there a way to let it stay for both insert commands?

1 Answer 1

0

One would think that it should work no matter how you enter the insert state. I use Doom Emacs, and for me, sometimes it works sometimes it doesn't. So, how about just commenting out the last line in the function that moves one character back as you come out of the insert state?

(defun evil-move-cursor-back (&optional force)
  "Move point one character back within the current line.
Contingent on the variable `evil-move-cursor-back' or the FORCE
argument. Honors field boundaries, i.e., constrains the movement
to the current field as recognized by `line-beginning-position'."
  (when (or evil-move-cursor-back force)
    (unless (or (= (point) (line-beginning-position))
                (and (boundp 'visual-line-mode)
                     visual-line-mode
                     (= (point) (save-excursion
                                  (beginning-of-visual-line)
                                  (point))))))))
      ;; (backward-char))))

Not sure whether this would affect anything else.

Of course you can add conditions and set it only for certain modes instead of just commenting it out altogether.

This was bothering me in Python shell as the cursor on an empty line goes right to the prompt on exit from insert state even when the evil-move-cursor-back variable was set to nil.

(setq evil-move-cursor-back-nil-modes
      (list 'inferior-python-mode
            'inferior-ess-r-mode))

(defun evil-move-cursor-back (&optional force)
  "Move point one character back within the current line.
Contingent on the variable `evil-move-cursor-back' or the FORCE
argument. Honors field boundaries, i.e., constrains the movement
to the current field as recognized by `line-beginning-position'."
  (when (or evil-move-cursor-back force)
    (unless (or (= (point) (line-beginning-position))
                ;; OVERRIDE: Add conditon to check major mode.
                (member major-mode evil-move-cursor-back-nil-modes)
                (and (boundp 'visual-line-mode)
                     visual-line-mode
                     (= (point) (save-excursion
                                  (beginning-of-visual-line)
                                  (point)))))
      (backward-char))))
3
  • Thanks, but how can I use it? I tried to evaluate this function, but the behavior of the append is still unchanged and I shift one field further
    – Rareform
    Mar 6 at 11:01
  • Which one did you evaluate? Try the first one only, don't evaluate the second one. It works for me.
    – Arktik
    Mar 6 at 11:38
  • I tried the first one, no changes for me
    – Rareform
    Mar 7 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.