43

I have used the mark to select regions of a buffer. For example, I know the sequence C-<space> C-s foo can be used to select all text between the current point and the point after a search for foo.

I recently discovered the existence of the mark ring, so I can C-<space> C-<space> to leave a mark, move the point in the buffer, and then C-u C-<space> to jump back.

Are there any suggestions, guides, or tips to effectively navigating using the mark ring?

2
  • 2
    Thanks for asking the question. One thought that occurs to me is to make a faster binding for "adding a mark", e.g. (global-set-key (kbd "s-m") '(lambda () (interactive) (push-mark))). Commented Jun 15, 2015 at 19:43
  • C-Space C-Space does not work in SpaceEmas on My MacBook?, I try it, it does nothing
    – 1234
    Commented Dec 18, 2019 at 19:34

6 Answers 6

28

Helm has an interface for browsing both local and global mark-rings: helm-all-mark-rings.

See the mini-guide for a brief description and a screenshot.

And if you prefer Ivy/Swiper/Counsel, see counsel-mark-ring.

2
  • 1
    Awesome. One thing that could improve this is an action to remove the mark from the mark ring... Commented Jun 15, 2015 at 19:45
  • During using counsel-mark-ring can the jumped lines could be highlighted?
    – alper
    Commented Aug 4, 2021 at 23:06
16

When you set set-mark-command-repeat-pop to t via

(setq set-mark-command-repeat-pop t)

you can keep pressing C-SPC after the first invocation of C-u C-SPC to jump to previous locations stored in the mark ring.

1
  • How can we reverse the jump process?
    – alper
    Commented Aug 4, 2021 at 23:00
14

I find it easier to use registers to mark locations: C-x r <space> and then a letter to mark, C-x r j and a letter to jump back. I can maintain a number of marks, very useful when alternating between multiple buffers

2
  • 3
    I always find myself pausing to decide the best letter to assign my register to...
    – nispio
    Commented Oct 29, 2014 at 21:24
  • 2
    @nispio some time ago I've implemented extension [email protected]:atykhonov/iregister.el.git One of the idea was: allow to skip decision which register to use. May be the extension will not be useful for you but you can borrow the idea in which your custom script could just use any free register and then it will allow to browse the used registers and restore. Commented Jan 25, 2015 at 5:33
11

C-x C-x for exchange-mark-and-point has similar use to C-u C-space. It lets you bounce between a point and the last mark. It's a little weird for bouncing with transient-mark-mode as it activates the mark and selects the region.

1
  • C-x C-xwith transient-mark-mode is excellent for selecting the last thing you either selected (useful with iedit mode) or yanked. Commented Oct 12, 2017 at 7:16
11

Apart from the other tips you have got here I thought I should mention that C-s sets the mark for you, so there is no need to do it explicitly. Also, many commands that "move a potentially long way" (beginning-of-buffer and end-of-buffer for example) also sets the mark where you started. Together with the other ways to work with the mark (pop, exchange point and mark, etc) it is a quite powerful way to work with a buffer, once you understand how it works. Also note that if you yank text into a buffer, point and mark surrounds the yanked text.

6

(Your question is pretty open-ended, so it might get closed as being primarily opinion-based.)

What I use: Icicles multi-command icicle-goto-marker (bound to C-- C-SPC) to trip around the marks in any buffer (mark-ring), and icicle-goto-global-marker (C-- C-x C-SPC) to trip among the global marks (global-mark-ring).

The lines of text where the markers are located are used as completion candidates. You can type some text (e.g., substring, regexp) to narrow the candidates to the lines that match. You can cycle among the matching lines, visiting any that you like. If you also use library crosshairs.el then position of a marker you visit is highlighted temporarily with crosshairs, so you can quickly see where it is.

Here is part of the doc string for icicle-goto-marker:

Go to a marker in this buffer, choosing it by the line that includes it.
If `crosshairs.el' is loaded, then the target position is highlighted.

By default, candidates are sorted in marker order, that is, with
respect to their buffer positions.  Use `C-M-,' or `C-,' to change the
sort order.

During completion you can use these keys:

`C-RET'   - Goto marker named by current completion candidate
`C-down'  - Goto marker named by next completion candidate
`C-up'    - Goto marker named by previous completion candidate
`C-next'  - Goto marker named by next apropos-completion candidate
`C-prior' - Goto marker named by previous apropos-completion candidate
`C-end'   - Goto marker named by next prefix-completion candidate
`C-home'  - Goto marker named by previous prefix-completion candidate
`<S-delete>' - Delete marker named by current completion candidate

Use `mouse-2', `RET', or `S-RET' to choose a candidate as the final
destination, or `C-g' to quit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.