29

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
    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))). – Joe Corneli Jun 15 '15 at 19:43
21

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.

  • Awesome. One thing that could improve this is an action to remove the mark from the mark ring... – Joe Corneli Jun 15 '15 at 19:45
12

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.

10

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
    I always find myself pausing to decide the best letter to assign my register to... – nispio Oct 29 '14 at 21:24
  • @nispio some time ago I've implemented extension git@github.com: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. – Andriy Tykhonov Jan 25 '15 at 5:33
9

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.

  • C-x C-xwith transient-mark-mode is excellent for selecting the last thing you either selected (useful with iedit mode) or yanked. – Rune Kaagaard Oct 12 '17 at 7:16
8

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.

5

(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, privacy policy and cookie policy

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