How do I set marks in Emacs à la Vim?

扶醉桌前 提交于 2019-12-02 20:25:13

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

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.

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.

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).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!