

GitHub - emacs-evil/evil-magit: Black magic or evil keys for magit
source link: https://github.com/emacs-evil/evil-magit
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.org
Black magic
This library configures Magit and Evil to play well with each other. For some background see Issue #1.
Note: I intend to track the latest commits to the master branch of the magit repo, meaning the keybindings here are potentially ahead of the last stable release of magit. Once the code in evil-magit stabilizes, I may switch to primarily tracking the stable release of magit and secondarily track the latest commits to master. Any help is welcomed.
Recent Changes (most recent first)
- [2018-03-13] Added basic evil support for
magit-list-repositories
. - [2016-07-27] Moved submodules popup to ’ and added the new subtree popup at “. This is not mnemonic in any way but easy to reach and keeps the two keys together.
- [2016-03-24] Moved
magit-diff-less-context
to = to fix conflict with moved revert. - [2016-03-21] Moved revert commands from
o
andO
to-
and_
. Rationale is that you are subtracting a commit. This makes room foro
andO
to be reset and the new reset popup command. Think of resetting to an “old” state.¯\_(ツ)_/¯
- Added
evil-magit-want-horizontal-movement
. Useh
andl
for movement like vim, movingh
toH
,l
toL
, andL
toC-l
. - Added
evil-magit-toggle-text-mode
onC-t
. This is a quick way to enter text mode in a magit buffer, which allows arbitrary movement, copying, etc. UseC-t
to return to the previous magit mode. - When
evil-magit-use-y-for-yank
is non nil,C-w
will prefix the evil window switching functions from magit buffers. evil-magit-use-y-for-yank
is now the default. It has worked well for me so far, and I’ve had good feedback, but please let me know if you see issues. You can use the original behavior with(setq evil-magit-use-y-for-yank nil)
. See the table below for a summary of differences.
Installation and Use
Everything is contained in evil-magit.el, so you may download and load that file
directly. The recommended method is to use MELPA via package.el (M-x
package-install RET evil-magit RET
).
Evil and Magit are both required. After requiring those packages, the following will setup the new key bindings for you.
;; optional: this is the evil state that evil-magit will use ;; (setq evil-magit-state 'normal) ;; optional: disable additional bindings for yanking text ;; (setq evil-magit-use-y-for-yank nil) (require 'evil-magit)
Note on evil usage
This package assumes that you either use the global variant of evil mode (e.g.,
through (evil-mode 1)
), or at least have evil-local-mode
(the local variant)
enabled in the magit buffers you want these bindings to take effect in. When
evil is disabled in a magit buffer, this package will not affect the default key
bindings (with one minor exception).
Note on evil-magit-use-y-for-yank
evil-magit-use-y-for-yank
enables evil’s visual state for linewise selection,
and as a consequnce y
will yank text from the buffer.
With this enabled which it is by default evil-magit uses v
and V
to select
by line. Selection in magit occurs linewise, so this choice is to avoid
confusion that might arise if someone thought they could stage part of a line
with v
for example.
Text mode
Text mode can be toggled with evil-magit-toggle-text-mode
(triggered with
C-t
or \
). This takes nearly any magit buffer out of the related magit mode
and puts it into text-mode
. This allows free movement in the buffer using the
standard evil movement and selection commands, making it easy to for example
copy arbitrary text in the buffer. It also effectively prevents magit keys from
shadowing evil ones, so f
runs evil-find-char
instead of
magit-fetch-popup
, allowing all vim related movement commands to be used in
magit buffers. You can think of this if you like as another state for evil-magit
to be in.
Several requests have been made to allow selecting and copying arbitrary text in the magit buffers, but there are many conflicts between evil bindings and magit bindings and there is no elegant solution to this problem in my opinion. Text mode is the best that I have come up with.
Key Bindings
The basic key binding scheme for evil-magit (EM) is described in the following tables. Blank columns indicate that the key is carried over from the left.
CategoryDefaultEM w/o yank optw/ yank opt (default)w/ horiz movecherry picka/A
branchb
bisectB
commitc
diffd/D
ediffe/E
fetchf
pullF
refreshg
gr/gR
(g
in popup)helph/?
H/?
ignorei/I
jumpj
g
deletek
x
untrackK
X
logl/L
L/C-l
mergem
remoteM
next sectionn
C-j
next section siblingM-n
gj
or ]
submoduleo
’subtreeO
”prev sectionp
C-k
prev section siblingM-p
gk
or [
pushP
P
or p
quitq
q
or ESC
rebaser
renameR
stages/S
tagt
notesT
unstageu/U
revertv/V
-/_
amw
patchW
resetx/X
o/O
show-refsy
yr
(y
in popup)cherryY
stashz/Z
git-cmd:
¦
run!
diff less/more context-/+
= / +copy section infoC-w
ys
copy buffer infoM-w
yb
New Commands
CommandEM w/o yank optEM w/ yank opt (default)w/ horiz moveevil-goto-lineG
evil-next-visual-linej
evil-previous-visual-linek
evil-backward-charunder M-x
h
evil-forward-charunder M-x
l
evil-search-nextn
evil-search-previousN
set-mark-commandv
or V
C-SPC
evil-visual-lineunder M-x
v
or V
evil-ex:
evil-search-forward/
evil-scroll-page-upC-b
evil-scroll-downC-d
evil-scroll-page-downC-f
evil-scroll-upC-u
(if C-u
scrolls)evil-emacs-stateC-z
evil-yank-lineunder M-x
yy
evil-window-mapunder M-x
C-w
evil-magit-toggle-text-modeC-t/\
Any other bindings are meant to be consistent with these.
Use evil-magit-revert
to revert changes made by evil-magit to the default
evil+magit behavior.
To add other common evil commands
Some may want ?
to search backward instead of launching the popup which is
also bound to h
. To get this behavior, add the following line after (require
'evil-magit)
in your configuration.
(evil-define-key evil-magit-state magit-mode-map "?" 'evil-search-backward)
Most (but not all) magit bindings are in magit-mode-map
, so other commands can
be bound in this way too.
Known Conflicts
These are the third-party packages that conflict with these bindings and will probably need to be disabled in magit buffers for evil-magit to work properly.
Disclaimer
Given the complexity of magit key bindings combined with the complexity of git itself, it is possible that there are some rough edges where the current binding is not the expected one in a buffer. It will be very helpful for you to report any such instances.
Recommend
-
164
magit/magit: It's Magit! A Git porcelain inside Emacs....
-
201
Evil is an extensible vi layer for Emacs. It emulates the main features of Vim, a...
-
114
Ghub — Client libraries for the APIs of various Git forges Ghub provides basic support for using the APIs of various Git forges from Emacs packages. Originally it only supported the Github REST API, but now it also supports the Githu...
-
135
Git Config Modes Emacs major modes for various Git configuration files. The list of contributors can be found here. The following libraries...
-
98
GitHub is where people build software. More than 28 million people use GitHub to discover, fork, and contribute to over 79 million projects.
-
77
I've been holding off on doing a Magit video for a while. Mostlybecause I wasn't using it exclusively and also because there arealready a number of good Magit videos and resources out there.What
-
45
Join GitHub today GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
-
12
evil-markdown-mode Supplemental evil-mode key-bindings to Emacs markdown-mode. This is inspired by https://github.com/Somelauw/evil-org-improved and
-
6
Jeremy Friesen Posted on Nov 6 ...
-
10
Talking never moves anything in Emacs, never did, never will. — 2021 Maintainer of GNU Emacs, who then proceeded to keep talking. Frequently Anticipated Questions This is the oft ideated, never su...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK