Emacs: Jump to Previous Position
Mark and Jump to Previous Mark
Emacs records all mark positions in a buffer. You can jump to a previous position.
set-mark-command
【Ctrl+Space】-
Mark a position. (do it twice to remove the highlight.) This pushes current position into the mark ring.
universal-argument
set-mark-command
【Ctrl+u Ctrl+Space】-
Move cursor to previous marked position of current buffer.
Repeated call moves to previously marked positions in current buffer.
〔see Emacs: Universal Argument (prefix arg)〕
If set-mark-command-repeat-pop is true, you no need to press Ctrl+u each time.
(setq set-mark-command-repeat-pop t)
pop-global-mark
【Ctrl+x Ctrl+Space】-
Move cursor to previous marked position in another buffer.
Repeat call move cursor to positions in global-mark-ring.
exchange-point-and-mark
【Ctrl+x Ctrl+x】-
Exchange cursor position and the last mark.
💡 TIP: use this to move cursor to the other end of text selection.
Buffer Mark Ring and Global Mark Ring
Emacs store cursor positions and let you jump to it quickly.
There are 2 mark rings:
- mark-ring
-
Buffer Local Variable. A list of former marks of the current buffer, most recent first.
- global-mark-ring
-
A list of saved global marks, most recent first.
Max Count of Saved Positions
By default, each mark ring keep 16 positions. As new mark is set, oldest is removed.
- mark-ring-max
-
Max count of mark ring. Default is 16.
You can make it store less positions for better use of jump.
Put this in your Emacs Init File:
(setq mark-ring-max 6) (setq global-mark-ring-max 6)
- global-mark-ring-max
-
Max count of mark ring. Default is 16.