7

I am wondering about a improvement for vim that I can jump back for where I was the last time I stopped to move around for like 3 seconds. Then I can scroll around and have a kick shortcut to jump back where I was with the same old CTRL+o.

Vim put a lot of movements in the :jumps list and I wondering that half of that is useless in any moment for me, so how could I do that ?

In any another words I'm trying to make the jumplist more sensible.

ps: Netbeans and VS has a similar behavior.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MaikoID
  • 4,359
  • 4
  • 25
  • 27

3 Answers3

11

To have the current position automatically added to the jump list, you can utilize the CursorHold event:

:autocmd CursorHold * normal! m'

Navigation is with the default <C-o> / <C-i>.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
8

It's common to use the m and ' commands to jump around. For instance, you can type mx, go off and do some things, and then do 'x to jump back to where you were when you did mx. This works for every letter of the alphabet (i.e. ma, mb,... mz). Uppercase marks (mA, mB,...) will also remember the filename so you can jump between files. There are a number of other special marks you can set for various purposes.

The "previous context mark" is called '. It is set automatically when you jump around, and can also be manually set with m'. Jump to it with ''. The m' command also manually adds a jump to the jumplist. '' is roughly equivalent to Ctrl+O, but doesn't take a count.

If you replace the apostrophes in these commands with backticks, Vim will jump to the specific column rather than just the line. In practice, apostrophe is easier to type and often close enough.

Kevin
  • 28,963
  • 9
  • 62
  • 81
  • I know about marks but its just not enough when you are analyzing logs, you have scroll too much. The standard jumps are not useful for this scenario too because I need more than one automatic stored jump. – MaikoID Nov 28 '14 at 19:08
  • @MaikoID: Why not set alphabetic marks manually when you need them? – Kevin Nov 28 '14 at 19:38
  • 1
    Because I need to set them before I starting scrolling, and I simple can't remember to do that. I use marks to remember important things I think is wrong to use it to help scrolling but is my opinion. – MaikoID Nov 28 '14 at 19:48
  • You've got 26 of 'em (52 counting file marks). You can and should use them for whatever you want. – Kevin Nov 28 '14 at 20:18
2

You can set a mark in the ' register. The keystrokes would be m'

I found this in vim's documentation :help jumplist.

You can explicitly add a jump by setting the ' mark with "m'".

raman
  • 643
  • 7
  • 16