28

I'd like to be able to set multiple marks in Emacs like Vim does. In Vim you might press m b and that would set a mark at that line in the file. Later pressing ' b will move your cursor back to that line. You can make multiple marks with m{a-zA-Z}. Is there a way to have multiple marks like this in Emacs?

user4035
  • 22,508
  • 11
  • 59
  • 94
MDCore
  • 17,583
  • 8
  • 43
  • 48

5 Answers5

35

From Emacs documentation :

C-x r SPC r

  • Record the position of point and the current buffer in register r (point-to-register).

C-x r j r

  • Jump to the position and buffer saved in register r (jump-to-register).

But if you want your positions to persist automatically from one Emacs session to the next, you should use Bookmarks :

C-x r m RET

  • Set the bookmark for the visited file, at point.

C-x r m bookmark RET

  • Set the bookmark named bookmark at point (bookmark-set).

C-x r b bookmark RET

  • Jump to the bookmark named bookmark (bookmark-jump).

C-x r l

  • List all bookmarks (list-bookmarks).

M-x bookmark-save

  • Save all the current bookmark values in the default bookmark file.
Jérôme Radix
  • 10,285
  • 4
  • 34
  • 40
17

You can use what Emacs calls registers. The documentation explains them better than I can.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
6

Try the mark ring for quick marks:

C-space
Make a mark at current position; also, add position to mark ring.

C-xC-x
Jump back to previous mark.

C-UC-space
Cycle through marks in the mark ring.

I used Vim for a decade before switching to Emacs a few years ago, and while the registers and bookmarks looked good at first, the mark ring is what I actually end up using 90% of the time. Usually I just use the C-space, C-x C-x, but cycling works, too.

Btw, realize that doing large non-arrow key movements like M-v will often add a mark to the mark ring. Just practice these key combos and you'll likely find them sufficient for most tasks.

Radix already did a good job explaining the registers and bookmarks, and those are useful for locations in files that will be referred to often or need annotation.

labyrinth
  • 13,397
  • 7
  • 35
  • 44
  • 1
    To avoid transient mark being activated when jumping (C-x C-x), use prefix argument (C-u C-x C-x). – arvidj Oct 28 '15 at 13:05
5

Vanilla Emacs makes you specify a name for each bookmark. What you want, it sounds like, is a quick way to create bookmarks without naming them -- just hit a key. You want autonamed bookmarks, available with Bookmark+. You can even have them be automatically highlighted, if you like (the fringe or the line).

Drew
  • 29,895
  • 7
  • 74
  • 104
0

Have a look at this: http://www.cs.utah.edu/dept/old/texinfo/emacs18/emacs_13.html