• Stars
    star
    849
  • Rank 53,688 (Top 2 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created over 11 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Minor mode for God-like command entering

God Mode β€” no more RSI

melpa-badge melpa-stable-badge gh-actions-badge

NOTE: Emacs 25.1 is required for this package to work well.

This is a global minor mode for entering Emacs commands without modifier keys. It's similar to Vim's separation of command mode and insert mode.

All existing key bindings will work in God mode. It's only there to reduce your usage of modifier keys.

Example

In the example below, you can see how much effort is reduced:

Before: C-p C-k C-n M-^ ) C-j C-y M-r C-x z z M-2 M-f C-x C-s
After:    p   k   n g ^ )   j   y g r     . .   2 g f   x   s

(Regarding ., see the useful key bindings section.)

You'll find this mode surprisingly natural, as you would already know how to use your existing Emacs commands. Whenever you feel like it, you can explicitly use modifier keys too.

See the key mapping section for a complete walk-through of key translations.

Setup

You can load and activate God mode as follows:

(require 'god-mode)
(god-mode)

This will activate God mode in all future buffers. However, activation of God mode itself is buffer-local.

God mode can be toggled through god-local-mode using the escape key (ESC) as follows:

(global-set-key (kbd "<escape>") #'god-local-mode)

If you want to toggle God mode on all active and future buffers, use god-mode-all as follows:

(global-set-key (kbd "<escape>") #'god-mode-all)

If God mode is activated through god-mode or god-mode-all, you might want to ensure that no buffers are skipped, as follows:

(setq god-exempt-major-modes nil)
(setq god-exempt-predicates nil)

This means that magit-mode or dired-mode, for example, will also enter God mode when you activate it in all buffers. This means you can always reliably use God mode commands in any buffer.

When God mode is enabled, entering function keys will be translated to use appropriate key modifiers. For example, entering <f5> is translated to C-<f5>. To disable this translation, you can set the god-mode-enable-function-key-translation variable to nil before loading God mode, as follows:

(setq god-mode-enable-function-key-translation nil)
(require 'god-mode)

Also, you can add this to your .xmodmap to rebind the caps lock key to the escape key:

remove Lock = Caps_Lock
keysym Caps_Lock = Escape

And run xmodmap .xmodmap for the changes to take effect immediately.

Or use dconf:

dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:escape']"

See this link for more details.

Key mapping

This package defines the following key mappings:

  • All commands are assumed to use the control modifier (C-) unless otherwise indicated. Here are some examples:

    • x → C-x
    • f → C-f
    • x s → C-x C-s
    • x SPC s → C-x s

    Note the use of the space key (SPC) to produce C-x s.

  • The literal key (SPC) is sticky. This means you don't have to enter SPC repeatedly for key bindings such as C-x r t. The literal key can be changed through god-literal-key. Here are some examples:

    • x SPC r t → C-x r t
    • x SPC r y → C-x r y
  • g is used to indicate the meta modifier (M-). This means that there is no way to enter C-g in God mode, and you must therefore type in C-g directly. This key can be changed through god-mode-alist. Here are some examples:

    • g x → M-x
    • g f → M-f
  • G is used to indicate both the control and meta modifiers (C-M-). This key can also be changed through god-mode-alist. Here are some examples:

    • G x → C-M-x
    • G f → C-M-f
  • Digit arguments can also be used:

    • 1 2 f → M-12 C-f
  • If you use some of the useful key bindings, z or . can repeat the previous command:

    • g f . . → M-f M-f M-f
  • Universal arguments can also be specified using u:

    • u c o → C-u C-c C-o

Lookup a key sequence

You can use god-mode-describe-key to check what command would be triggered by particular keys. This function works similarly to describe-key: it prompts for a key combination, translates it into a command, and display its information in the Help buffer.

By default, god-mode-describe-key is bound to C-h k in god-local-mode-map.

Note that god-mode-describe-key is only able to interpret key-bindings that are specific to god-mode. For other key-bindings, mouse-clicks, and menu items, it's better to use describe-key.

Visual indicators for God mode

God mode allows you to customize its minor mode lighter by customizing the god-mode-lighter-string variable and the god-mode-lighter face. For example, if you don't want any lighter, you can set the string to nil. On the other hand, if you want the lighter to stand out, you can change the face, e.g. by making it inherit from error. You can do this using M-x customize-face RET god-mode-lighter or as follows:

(custom-set-faces
 '(god-mode-lighter ((t (:inherit error)))))

Additionally, you can change the cursor style to visually indicate whether God mode is active as follows:

(defun my-god-mode-update-cursor-type ()
  (setq cursor-type (if (or god-local-mode buffer-read-only) 'box 'bar)))

(add-hook 'post-command-hook #'my-god-mode-update-cursor-type)

You can also change the foreground and background of the mode line to indicate whether God mode is active as follows:

(defun my-god-mode-update-mode-line ()
  (cond
   (god-local-mode
    (set-face-attribute 'mode-line nil
                        :foreground "#604000"
                        :background "#fff29a")
    (set-face-attribute 'mode-line-inactive nil
                        :foreground "#3f3000"
                        :background "#fff3da"))
   (t
    (set-face-attribute 'mode-line nil
			:foreground "#0a0a0a"
			:background "#d7d7d7")
    (set-face-attribute 'mode-line-inactive nil
			:foreground "#404148"
			:background "#efefef"))))

(add-hook 'post-command-hook #'my-god-mode-update-mode-line)

Note that using post-command-hook here should not be an issue for performance. If you are concerned about performance for any reason, you can use god-mode-enabled-hook and god-mode-disabled-hook. With Emacs 27.1+, you can also use window hooks.

overwrite-mode

You can pause or resume God mode depending on whether overwrite-mode is activated as follows:

(defun my-god-mode-toggle-on-overwrite ()
  "Toggle god-mode on overwrite-mode."
  (if (bound-and-true-p overwrite-mode)
      (god-local-mode-pause)
    (god-local-mode-resume)))

(add-hook 'overwrite-mode-hook #'my-god-mode-toggle-on-overwrite)

isearch integration

There is an optional feature for providing God mode behaviour in isearch. It allows you to hit ESC, for example, while in isearch to enable God mode. Here's a more complete example:

s h e y ESC s s s RET → C-s h e y C-s C-s C-s RET

You can load and activate this feature as follows:

(require 'god-mode-isearch)
(define-key isearch-mode-map (kbd "<escape>") #'god-mode-isearch-activate)
(define-key god-mode-isearch-map (kbd "<escape>") #'god-mode-isearch-disable)

You can also configure god-mode-isearch-map for additional keybindings.

Rebinding self-insert-command

You can rebind self-insert-command as you prefer. For example, here's a mapping that calls org-self-insert-command in org-mode:

(defun my-god-mode-self-insert ()
  (interactive)
  (if (and (bolp)
           (eq major-mode 'org-mode))
      (call-interactively 'org-self-insert-command)
    (call-interactively 'god-mode-self-insert)))

(define-key god-local-mode-map [remap self-insert-command] #'my-god-mode-self-insert)

Useful key bindings

The following key bindings are popular:

(define-key god-local-mode-map (kbd "z") #'repeat)
(define-key god-local-mode-map (kbd "i") #'god-local-mode)

Although I personally prefer:

(define-key god-local-mode-map (kbd ".") #'repeat)

These are also handy:

(global-set-key (kbd "C-x C-1") #'delete-other-windows)
(global-set-key (kbd "C-x C-2") #'split-window-below)
(global-set-key (kbd "C-x C-3") #'split-window-right)
(global-set-key (kbd "C-x C-0") #'delete-window)

(define-key god-local-mode-map (kbd "[") #'backward-paragraph)
(define-key god-local-mode-map (kbd "]") #'forward-paragraph)

So that you can run x 1, x 2, x 3, and x 0 in God mode.

Exempt major modes

NOTE: This is less necessary in recent versions of God mode, as it overrides all printable single byte keys and bindings in most major modes.

Sometimes, God mode is enabled in buffers where it makes no sense. In such cases, you can add the major mode to god-exempt-major-modes:

(add-to-list 'god-exempt-major-modes 'dired-mode)

Since dired-mode is already in the list, that's a no-op, but you get the idea. Consider opening an issue or pull request if you find a major mode that should be on the official list.

Another option to control the behavior of God mode in new buffers is to provide a function with no arguments that must return non-nil if God mode should be disabled in the current buffer. See the god-exempt-predicates variable and its default members god-exempt-mode-p, god-comint-mode-p, god-view-mode-p and god-special-mode-p for further details.

Usage with Evil

Evil is a popular Emacs package that provides modal editing in the style of Vi. While Evil doesn't always work well with God mode, there are a few simple customizations that enable them to be used together smoothly.

  • For running occasional and single commands in God mode, the built-in god-execute-with-current-bindings command works well with Evil without additional customization. This is quite similar to Evil's evil-execute-in-emacs-state command. All Evil bindings remain available when using god-execute-with-current-bindings. For example, executing god-execute-with-current-bindings and entering v will execute evil-visual-block, which is bound to C-v in Evil's Normal state.

  • For sustained usage of God mode, it's a bit trickier as keybindings in Evil states generally override God mode. For example, if God mode is activated in Normal state, entering v executes evil-visual-char, which is bound to v in Normal state, instead of executing evil-visual-block. A good option to use Evil's state-specific keybindings through God mode is to create an intercept keymap using evil-make-intercept-map and god-local-mode-map. For example, you can enable use of God mode in Normal state as follows:

    (with-eval-after-load 'god-mode
      (evil-make-intercept-map god-local-mode-map 'normal)
      (add-hook 'god-local-mode-hook #'evil-normalize-keymaps))
  • Another option to use God mode with Evil is to use the evil-god-state package, which provides a dedicated Evil state for using God mode. For running occasional, single commands through God mode, use the evil-execute-in-god-state command. This works similar to god-execute-with-current-bindings. For sustained use of God mode, use the evil-god-state command. evil-god-state is also useful for accessing default Emacs keybindings through God mode. However, a disadvantage of evil-god-state is that Evil's state-specific keybindings will not be available in God mode.

More Repositories

1

git-gutter

Emacs port of GitGutter which is Sublime Text Plugin
Emacs Lisp
830
star
2

helm-swoop

Efficiently hopping squeezed lines powered by Emacs helm interface
Emacs Lisp
688
star
3

org-page

[INACTIVE] A static site generator based on Emacs and org mode.
Emacs Lisp
673
star
4

popwin

Popup Window Manager for Emacs
Emacs Lisp
496
star
5

helm-ag

The silver searcher with helm interface
Emacs Lisp
492
star
6

quickrun

Run command quickly. This packages is inspired quickrun.vim
Emacs Lisp
474
star
7

anzu

Emacs Port of anzu.vim
Emacs Lisp
414
star
8

emamux

tmux manipulation from Emacs
Emacs Lisp
265
star
9

ov

Overlay library for Emacs Lisp.
Emacs Lisp
211
star
10

helm-gtags

GNU GLOBAL helm interface
Emacs Lisp
204
star
11

direx

Directory Explorer for GNU Emacs
Emacs Lisp
204
star
12

terraform-mode

Major mode of Terraform configuration file
Emacs Lisp
194
star
13

git-gutter-fringe

Fringe version of git-gutter.el
Emacs Lisp
160
star
14

req-package

dependency management system on top of use-package
Emacs Lisp
153
star
15

git-messenger

Emacs Port of git-messenger.vim
Emacs Lisp
146
star
16

go-eldoc

eldoc for go language
Emacs Lisp
128
star
17

libegit2

Emacs bindings for libgit2
C
115
star
18

key-chord

Map pairs of simultaneously pressed keys to commands
Emacs Lisp
108
star
19

yascroll

Yet Another Scroll Bar Mode
Emacs Lisp
104
star
20

zoom-window

Zoom and Unzoom window
Emacs Lisp
102
star
21

company-jedi

Company backend for Python jedi
Emacs Lisp
100
star
22

swoop

Peculiar buffer navigation for Emacs
Emacs Lisp
90
star
23

org-redmine

Redmine tools using Emacs OrgMode
Emacs Lisp
83
star
24

dired-k

Highlighting dired buffer like k
Emacs Lisp
82
star
25

magit-gerrit

Magit plugin for Gerrit Code Review
Emacs Lisp
61
star
26

go-add-tags

Add field tags for struct fields
Emacs Lisp
59
star
27

pkg-info

Provide information about Emacs packages
Emacs Lisp
57
star
28

helm-css-scss

This emacs program makes your CSS/SCSS/LESS coding faster and easier than ever.
Emacs Lisp
54
star
29

smeargle

Highlighting Regions by Last Updated Time
Emacs Lisp
49
star
30

evil-anzu

anzu for Evil
Emacs Lisp
49
star
31

mongo

MongoDB driver for Emacs Lisp
Emacs Lisp
47
star
32

manage-minor-mode

Manage your minor-mode on the dedicated interface buffer. Emacs.
Emacs Lisp
47
star
33

gh-md

Render markdown using the github api
Emacs Lisp
46
star
34

farmhouse-themes

Hand-picked light and dark color theme for Emacs 24+
Emacs Lisp
43
star
35

go-direx

Tree style source code viewer for Go language
Emacs Lisp
40
star
36

undohist

Persistent Undo History for GNU Emacs
Emacs Lisp
40
star
37

helm-themes

Emacs theme selection with helm interface
Emacs Lisp
38
star
38

fontawesome

fontawesome utility
Emacs Lisp
33
star
39

go-impl

impl for Emacs
Emacs Lisp
32
star
40

ansible-doc

Ansible documentation for GNU Emacs
Emacs Lisp
32
star
41

sr-speedbar

Same frame speedbar
Emacs Lisp
31
star
42

fancy-battery

Display battery in Emacs Mode line
Emacs Lisp
31
star
43

cpp-auto-include

Insert and delete C++ header files automatically.
Emacs Lisp
31
star
44

helm-open-github

Utilities for opening github page
Emacs Lisp
29
star
45

ac-etags

etags/ctags completion source for auto-complete
Emacs Lisp
28
star
46

transpose-frame

Transpose windows arrangement in a frame
Emacs Lisp
26
star
47

osx-trash

Make Emacs' delete-by-moving-to-trash do what you expect it to do on OS X.
Emacs Lisp
26
star
48

ac-emoji

auto-complete source of Emoji
Emacs Lisp
25
star
49

ac-ispell

ispell/aspell completion source for auto-complete
Emacs Lisp
25
star
50

applescript-mode

Emacs mode for editing AppleScript
Emacs Lisp
24
star
51

codic

Codic for Emacs
Emacs Lisp
23
star
52

magit-svn

Git-Svn extension for Magit
Emacs Lisp
22
star
53

helm-pydoc

pydoc with helm interface
Emacs Lisp
20
star
54

evil-textobj-line

Evil Line text object
Emacs Lisp
18
star
55

ac-alchemist

auto-complete source of alchemist
Emacs Lisp
18
star
56

sourcemap

Sourmap parser in Emacs Lisp
Emacs Lisp
18
star
57

dart-mode

An Emacs mode for the Dart language
Dart
16
star
58

helm-ack

App::ack with helm interface
Emacs Lisp
13
star
59

helm-perldoc

perlpod with helm interface
Emacs Lisp
12
star
60

reverse-theme

Emacs color theme of reverse(like 'emacs --reverse-video')
Emacs Lisp
12
star
61

helm-github-issues

github issues with helm interface
Emacs Lisp
12
star
62

ac-capf

auto-complete source of completion-at-point
Emacs Lisp
12
star
63

sound-wav

Play wav file
Emacs Lisp
12
star
64

ac-racer

auto-complete source of racer
Emacs Lisp
10
star
65

qt-pro-mode

GNU Emacs major-mode for Qt build-system files
Emacs Lisp
9
star
66

popup-complete

Completion with popup-el
Emacs Lisp
9
star
67

splitjoin

Emacs port of splitjoin.vim
Emacs Lisp
8
star
68

miniedit

Enhanced editing for minibuffer fields
Emacs Lisp
8
star
69

helm-ispell

ispell completion with helm interface
Emacs Lisp
8
star
70

thingopt

Additional features of thingatpt.el
Emacs Lisp
8
star
71

helm-package

Listing ELPA packages with helm interface
Emacs Lisp
7
star
72

magit-p4

Magit plugin integrating git-p4 add-on.
Emacs Lisp
6
star
73

docean

Interact with DigitalOcean from Emacs
Emacs Lisp
6
star
74

pyimpsort

Sort python imports
Python
5
star
75

emamux-ruby-test

Ruby test with emamux
Emacs Lisp
5
star
76

octicons

Emacs octicons utility
Emacs Lisp
5
star
77

oberon

Major mode for editing Oberon/Oberon-2 program texts
Emacs Lisp
5
star
78

dedicated

A very simple minor mode for dedicated buffers
Emacs Lisp
4
star
79

haxe-mode

Major mode for editing Haxe files.
Emacs Lisp
4
star
80

helm-robe

Helm completing function for robe
Emacs Lisp
4
star
81

ert-expectations

The simplest unit test framework in the world
Emacs Lisp
4
star
82

keydef

A simpler way to define keys, with kbd syntax
Emacs Lisp
3
star
83

help-find-org-mode

Advise help functions to find org babel source blocks instead of tangled source
Emacs Lisp
3
star
84

test-more

Emacs Test framework like Perl's Test::More
Emacs Lisp
3
star
85

tree-mode

A mode to manage tree widgets
Emacs Lisp
3
star
86

showtip

Show tip at cursor
Emacs Lisp
3
star
87

import-popwin

Pop up buffer near by import statements with popwin
Emacs Lisp
3
star
88

literate-coffee-mode

Major mode for Literate CoffeeScript
Emacs Lisp
3
star
89

perl-utils

Emacs Perl utilities
Emacs Lisp
2
star
90

ltsv

LTSV for Emacs
Emacs Lisp
2
star
91

later-do

Execute lisp code ... later
Emacs Lisp
2
star
92

findr

Breadth-first file-finding facility for (X)Emacs
Emacs Lisp
2
star
93

org-json

Conversion between org and json
Emacs Lisp
2
star
94

dirtree

Directory tree views
Emacs Lisp
2
star
95

pylint

Minor mode for running `pylint'
Emacs Lisp
2
star
96

jedi-eldoc

Eldoc with emacs-jedi
Emacs Lisp
2
star
97

w32-browser

Run Windows application associated with a file
Emacs Lisp
2
star
98

setnu

Emacs Lisp
1
star
99

oddmuse

Edit pages on an Oddmuse wiki
Emacs Lisp
1
star
100

.github

Talk and learn about the Emacsorphanage
Makefile
1
star