A modal editing minor-mode designed with Emacs in mind.
Comma-mode is minor mode for Emacs that defines a single key map to
facilitate fast modal editing. Most of the modal commands our derived
from key bindings that come with a standard Emacs installation. For
example, C-f is bound to f in the comma-mode key map to move
forward a character. This allows to use the same mnemonics that one
has learned from vanilla Emacs to navigate a buffer but without always
having to hold down the control key.
Place comma-mode.el in the lisp folder in your .emacs.d
directory. Then add the following somewhere in your init.el file:
(require 'comma-mode)
By default comma-mode does its best to not interfere with your emacs setup as you need to manually activate it. The first thing that you will want to do is assign a key to activate comma-mode while in a Emacs buffer. For example, I use the following:
(global-set-key (kbd "C-,") 'comma-mode)
This sets the control plus the comma key to the global key map to
activate comma-mode (hence the name). Of course, when you visit a
buffer comma-mode will not automatically activate. This is to
facilitate learning comma-mode incrementally but soon you may want to
have comma-mode activate automatically when you visit certain buffers.
For example, I have the following in my init.el file for when I
visit a buffer that is a text, programming language, or org file:
(dolist (hook '(emacs-lisp-mode-hook
org-mode-hook
prog-mode-hook
text-mode-hook))
(add-hook hook 'comma-mode))
Comma-mode being a minor mode also allows adding custom command to various keystrokes. This will be discussed at the end of the manual.
The rest of this document will serve as a manual for comma-mode and is written in a manner to allow the reader to follow along with Emacs. If you haven't already, install comma-mode with the instructions above and open any text file, such as this README, in Emacs or open up the scratch buffer.
Enter comma-mode with C-, if you matched the setup instructions above.
You can also activate comma-mode with the command M-x comma-mode but
that's pretty cumbersome so you will most likely will want a key binding.
To exit comma-mode, you can either use:
- Hit
C-,again. The same key to enter is the same for exiting. iwill exit and place the point in front of the current character.Iis likeibut places the point after the current charcter.C-gorESC, ESC, ESCas with vanilla emacs to quit something.
Simple navigating around a buffer matches Emacs Control + Key movements:
fmove forward one characterbmove backward one characternmove one line downpmove one line up
lmove right one wordhmove left one wordjmove down one paragraphkmove up one paragraphamove to the beginning of the current lineemove to the end of the current line
Comma-mode was designed with programming in mind so many motions are made to quickly navigate files of programming language text.
M-lmove right one sub-wordM-hmove left one sub-wordLmove right one expressionHmove left one expressionvjump inside into next expression (useful for lisp)Vjump outside of current expressionKjump to the beginning of a function (beginning-of-defun)Jjump to the end of a function (end-of-defun)
More interesting is that comma-mode allows you to jump directly to the
any of the following !@#$%^&*()-=_+[]{}\;:'"<>,./? glyphs by
pressing that key. In other words, pressing [ will jump to the next
[ in the buffer. Alternatively, you can hold the Meta key while hitting
any of those keys to go backwards to the most recent glyph of that key.
Quick jumps to any glyph can be done forwards and backwards. This
mimics C-s and C-r in Emacs but is for a single character as
opposed to searching for an entire word.
s+ any key: jump forward to the next occurrence of that glyphr+ any key: jump backward to the previous occurrence of that glyph
Finally, we can combine any of the previous jump motions, s or r
commands and the jump direct to punctuation commands, with the more
motion command:
mrepeat the last jump motion in that directionMrepeat the last jump motion in the reverse direction
Note that you can repeatedly press m to continually repeat that last
jump motion. Furthermore, you can press M to immediately reverse
that jump motion to the previous occurrence. This is useful if you
overshoot your target location from repeated presses of m.
Remember, that this command repeats the previous direction so if you
were to search backward for the letter e with the jump motion of r e
then repeatingly pressing m will continue to search backwards for
the previous e while pressing M will reverse and search
forward for the next occurrence of letter e.
Similiar to VIM's % command, comma-mode uses Y, as in Yo-Yo, to
jump between matching pairs of brackets [], curley brackes {},
carets <>, and parentheses ().
Comma-mode provides keys for other commonly used Emacs commands:
yyankwkill-regionddelete-charM-jjoin-line~swap case of the character at the pointoinsert newline below the pointOinsert newline above the pointzrepeat the last command as inC-x zXexecute-extended-commandSPCset-mark-commanduuniversal-argument -- Note that repeatingudoesn't work like repeatingC-u. Also, you can followuwith any numbers as the argument, such asC-u 13.
Using SPC as the set-mark-command deserves special mention since it be
combined with other motions to execute specific actions. For example, you
can enter the keystrokes SPC . f BSPC with comma-mode active to delete a
sentence. In other words, what we have done is:
- called set-mark-command with
SPC - jump forward to the next period with
. - move foward one character past the period with
f - deleted the current region with
BSPC
As for another example, suppose we are working on a function in some
programming language and we want to move the whole function to a
different part of the file (or another file altogether). We can
achieve this with the keystroke sequence K SPC J w. That is
jump to the beginning of the function, set the mark, jump to then
end of the function, and kill the current region. Now we can where
we want to place the function and paste it with y.
This is the closest thing to VIM's text objects that comma-mode has to offer. While technically one more keystroke and has to be done from the beginning of a particular position, I find this method more natural as it encompasses motions that I'm constantly using to navigate and edit text without having to think of the mnemonic to perform a given action.
Comma-mode does not offer a leader key as in VIM. Instead it uses key
combinations with x and c prefix followed by another key to
execute various commands. Here are some commonly used commands that
ship with comma-mode:
x ssave-bufferx fido-find-filex uupcase-regionx :eval-expressionx 4 oido-display-bufferx 4 fido-find-file-other-windowc ggrepc ccomment-regionc uuncomment-region
Note that x commands are derived from the default Emacs control
chord counterparts. There are several others and you can view the
full list at the bottom of comma-mode.el. You can easily define you
own key combinations by placing them in your init.el file. For
example, you would add the following after (require 'comma-mode) in
your init.el file to have the key sequence c s execute the
magit-status command (assuming you have magit installed):
(define-key comma-mode-map (kbd "c s") 'magit-status)
This concludes the manual for comma-mode. I hope it brings you as much joy as it has for me!




