1

Let's say I'm on line Y, char X, and then do an i-search or do a goto line. Then I move around there a bit, but then I want to return to Y, X. How do I do this? Is there an automatic mechanism that remembers my position when doing common "jumps" to other places in the code?

I know Emacs has a function that changes point and mark, but C-Space causes highlighting as it's used for copy/paste so seems to be the wrong thing to use. Also, then I have to manually do something before I jump. I'm hoping for a way to magically return. This would be extremely useful.

1

There is no vim-like convenience jumps forth and back (C-o and C-i if I recall it correctly) built-in. Evil has it though.

As for built in mechanism, try C-u C-Space (pop-mark?) or C-x C-Space (pop-global-mark)

For example, if you in the middle of the buffer, move your cursor to the buffer end with M->. You can return to the place before jump with C-u C-Space.

| improve this answer | |
  • pop-mark is exactly what I'm looking for! But exactly how does pop-global-mark work? A forward circuit of buffers where you have pressed C-Space? I tried doing C-Space on line 20 in my .emacs, but when pop-global-mark returned to .emacs it was on line 1. Generally, how/when do you use this function? – forthrin Apr 2 '18 at 8:34
  • You have to remember that with pop-global-mark you will return to the saved mark. If for ex, you were on .emacs line 1 then searched for use-package -- you'll save the mark on line 1. And if you will pop-global-mark from another buffer you'll jump to exactly line 1 of your .emacs – Maxim Kim Apr 2 '18 at 11:03
1

In addition to vanilla C-u C-SPC and C-x C-SPC (pop-global-mark), if you use Icicles then you can use those keys instead to more easily navigate among local and global marks, respectively.

C-SPC does this (by default) in icicle-mode:

icicle-goto-marker-or-set-mark-command is an interactive compiled Lisp function in icicles-cmd2.el.

It is bound to C-@, C-SPC.

(icicle-goto-marker-or-set-mark-command ARG)

Set mark or goto a marker.

With no prefix arg or a prefix arg > 0, this is set-mark-command. (This includes the cases of C-u and C-u C-u.)

With a prefix arg = 0, this is icicle-goto-any-marker.

With a prefix arg < 0, this is icicle-goto-marker.


icicle-goto-marker is an interactive compiled Lisp function in icicles-cmd2.el.

It is bound to menu-bar search goto icicles icicle-goto-marker.

(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

When candidate action and cycling are combined (e.g. C-next), option icicle-act-before-cycle-flag determines which occurs first.

With prefix C-M- instead of C-, the same keys (C-M-mouse-2, <C-M-f1>, C-M-down, and so on) provide help about candidates.

Use mouse-2, RET, or S-RET to choose a candidate as the final destination, or C-g to quit. This is an Icicles command - see command icicle-mode.


C-x C-SPC does this (by default) in icicle-mode:

C-x C-SPC runs the command icicle-goto-global-marker-or-pop-global-mark (found in icicle-mode-map), which is an interactive compiled Lisp function in icicles-cmd2.el.

It is bound to C-x C-@, C-x C-SPC.

(icicle-goto-global-marker-or-pop-global-mark ARG)

With prefix arg < 0, icicle-goto-global-marker; else pop-global-mark.


icicle-goto-global-marker is an interactive compiled Lisp function in icicles-cmd2.el.

It is bound to menu-bar search goto icicles icicle-goto-global-marker.

(icicle-goto-global-marker)

Like icicle-goto-marker, but visits global, not local, markers.

If user option icicle-show-multi-completion-flag is non-nil, then each completion candidate is has two parts, the first of which is the name of the marker’s buffer, and the second of which is the text from the marker’s line.

By default, candidates are sorted in buffer order and then marker order, that is, buffer positions. Use C-M-, or C-, to change the sort order. Remember too that you can use C-A to toggle case-sensitivity (e.g., for buffer names).


icicle-goto-any-marker is an interactive compiled Lisp function in icicles-cmd2.el.

It is bound to menu-bar search goto icicles icicle-goto-any-marker.

(icicle-goto-any-marker)

Like icicle-goto-marker, but lets you visit markers in all buffers. If user option icicle-show-multi-completion-flag is non-nil, then each completion candidate is has two parts, the first of which is the name of the marker’s buffer, and the second of which is the text from the marker’s line.

By default, candidates are sorted in buffer order and then marker order, that is, buffer positions. Use C-M-, or C-, to change the sort order. Remember too that you can use C-A to toggle case-sensitivity (e.g., for buffer names).

| improve this answer | |

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.