A taste of the f
operator of vim in Emacs.
- Bind
find-char
to some key, sayM-j
. - Hit
M-j
and the character that you want to move to. - Press “ ’ ” to move forward,
;
to move back. - Press any other key to finish
Extra:
- You can combine numerical arguments with
find-char
, e.g.,C-3 find-char
,C-- C-4 find-char
. - Press the character you are searching for to move forward, Press the reversed case of it to move backward. E.g,
M-j f
,f
forward,F
backwardM-j F
,F
forward,f
backward.
- Case-sensitivity is controlled by
case-fold-search
.
Note: find-char doesn’t search the whole buffer since it’s just for short distance jumping.
key | Command |
C-d | Quick delete region (like df ) |
C-w | Quick copy region |
C-v | Toggle highlight of region |
The mark is set to where you began jumping, you can do whatever you want with that.
Variable | Description |
find-char-search-range | find-char doesn’t search the whole buffer, but only a portion around point |
find-char-stop-at | where does find-char stop, can be 'beginning or 'end |
case-fold-search | controls case-sensitivity when searching |
You can customize find-char-transient-map
, the map that activates during jumping. Default value is:
(defvar find-char-transient-map (let ((map (make-sparse-keymap)))
(define-key map (kbd "'") #'find-char-forward)
(define-key map (kbd ";") #'find-char-backward)
(define-key map (kbd "C-'") #'find-char-forward)
(define-key map (kbd "C-;") #'find-char-backward)
(define-key map (kbd "C-d") #'find-char-quick-delete)
(define-key map (kbd "C-v") #'find-char-toggle-region-highlight)
(define-key map (kbd "C-w") #'find-char-copy-region)
map)
"Transient map for find-char.")
Plus the dynamically binded search char and reverse case of search char mentioned in “usage” section above.
Comparison with jump-char
I’ve been using jump-char for quite a while and it is great. Here is the differences between jump-char and find-char:
- jump-char uses isearch, which brings advantages and disadvantages. It is more like searching than a jumping. E.g., there is no trivial way to jump with region activated AFAIK .
- jump-char integrates ace-jump while find-char doesn’t.