summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Nguyen <james@jojojames.com>2026-04-25 12:50:24 -0400
committerJames Nguyen <james@jojojames.com>2026-04-25 12:50:24 -0400
commitdbedcf2f52b2050ec09d6217928b82be021ad89d (patch)
tree6b990065f718ca046dd73e6a1e7c652763794239
parent1b851ae7c02ed783e27c6db6c5c7797633cf29a8 (diff)
Bind ret & shift-ret for the two related RET commands:
magit-diff-visit-worktree-file and magit-diff-visit-file This allows us to get the old behavior of RET before the switch to defaulting to visiting the diff but still allow consisten behavior. Set this: +(defcustom evil-collection-magit-visit-worktree-file-on-return t to nil to match RET in magit without evil. This would be the original (but updated) behavior. Another way to configure the behavior (and more context): From: `magit-diff-visit-file' In the past \\`<return>' (this command) used to go to the file in the worktree, if point is on an added or context line of a diff showing staged changes. Set `magit-diff-visit-prefer-worktree' to t to restore that behavior, but note that doing so makes the behavior inconsistent and you would give up on the ability to visit the index blob. If you already use \\[magit-diff-visit-worktree-file] to jump to the live \ file from committed changes, it might be better to retrain muscle memory to do the same from staged changes.
-rw-r--r--modes/magit/evil-collection-magit.el32
1 files changed, 28 insertions, 4 deletions
diff --git a/modes/magit/evil-collection-magit.el b/modes/magit/evil-collection-magit.el
index 732ba47..1cdef63 100644
--- a/modes/magit/evil-collection-magit.el
+++ b/modes/magit/evil-collection-magit.el
@@ -558,6 +558,16 @@ denotes the original magit key for this command.")
(eq (magit-diff-type) 'untracked))
(magit-stage-untracked t)))
+(defcustom evil-collection-magit-visit-worktree-file-on-return t
+ "When non-nil (default), RET visits the file in the worktree
+\(`magit-diff-visit-worktree-file') and S-<return> visits the file
+in the current diff context (`magit-diff-visit-file').
+
+When nil, the bindings are swapped: RET uses `magit-diff-visit-file'
+and S-<return> uses `magit-diff-visit-worktree-file'."
+ :group 'magit
+ :type 'boolean)
+
(defvar evil-collection-magit-original-section-bindings
`((,(copy-keymap magit-file-section-map) "\C-j" magit-diff-visit-worktree-file)
(,(copy-keymap magit-hunk-section-map) "\C-j" magit-diff-visit-worktree-file))
@@ -565,17 +575,31 @@ denotes the original magit key for this command.")
evil-collection-magit affects.")
(defun evil-collection-magit-adjust-section-bindings ()
- "Revert changed bindings in section maps generated by evil-collection-magit"
+ "Adjust bindings in section maps for evil-collection-magit."
(define-key magit-file-section-map "I"
'evil-collection-magit-stage-untracked-file-with-intent)
(define-key magit-file-section-map "\C-j" nil) ; breaking change
- (define-key magit-hunk-section-map "\C-j" nil)) ; breaking change
+ (define-key magit-hunk-section-map "\C-j" nil) ; breaking change
+ (let ((return-cmd (if evil-collection-magit-visit-worktree-file-on-return
+ 'magit-diff-visit-worktree-file
+ 'magit-diff-visit-file))
+ (s-return-cmd (if evil-collection-magit-visit-worktree-file-on-return
+ 'magit-diff-visit-file
+ 'magit-diff-visit-worktree-file)))
+ (define-key magit-file-section-map (kbd "RET") return-cmd)
+ (define-key magit-hunk-section-map (kbd "RET") return-cmd)
+ (define-key magit-file-section-map (kbd "S-<return>") s-return-cmd)
+ (define-key magit-hunk-section-map (kbd "S-<return>") s-return-cmd)))
(defun evil-collection-magit-revert-section-bindings ()
- "Revert changed bindings in section maps generated by evil-collection-magit"
+ "Revert changed bindings in section maps generated by evil-collection-magit."
(define-key magit-file-section-map "I" nil)
(define-key magit-file-section-map "\C-j" 'magit-diff-visit-file-worktree)
- (define-key magit-hunk-section-map "\C-j" 'magit-diff-visit-file-worktree))
+ (define-key magit-hunk-section-map "\C-j" 'magit-diff-visit-file-worktree)
+ (define-key magit-file-section-map (kbd "RET") 'magit-diff-visit-file)
+ (define-key magit-hunk-section-map (kbd "RET") 'magit-diff-visit-file)
+ (define-key magit-file-section-map (kbd "S-<return>") nil)
+ (define-key magit-hunk-section-map (kbd "S-<return>") nil))
;; Popups