In Emacs with Evil mode, similar to Vim, a mark represents a position in the buffer that you can set and later return to, facilitating quick navigation between different locations within a file.
Set and restore a mark
You can set a mark by pressing the m
button followed by a letter. For example, pressing ma
sets a mark at the current cursor position and associates it with the letter a
. To restore a mark, press either the backtick (`
) or the single quote ('
) followed by the associated letter. For instance, pressing 'a
restores the cursor to the line of the mark, while pressing `a
moves the cursor to the exact line and column of the mark.
How to use a single quote instead of a backtick to restore both the line and column numbers of a mark
If you prefer using the single quote ('
) to restore both the line and column number of a mark, I’ve made a small change to accommodate this preference. The following Elisp code ensures that the single quote ('
) restores both the line and column, while the backtick (`
) restores only the line:
(define-key evil-motion-state-map "`" 'evil-goto-mark-line)
(define-key evil-motion-state-map "'" 'evil-goto-mark)
Code language: Lisp (lisp)