How do I set marks in Emacs à la Vim?
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?
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.
You can use what Emacs calls registers
. The documentation explains them better than I can.
Try the mark ring for quick marks:
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.
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).
Have a look at this: http://www.cs.utah.edu/dept/old/texinfo/emacs18/emacs_13.html
精彩评论