Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM - How can I put my current position in jumplist?

Tags:

vim

shortcut

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.

like image 658
MaikoID Avatar asked Nov 28 '14 17:11

MaikoID


2 Answers

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

like image 178
Ingo Karkat Avatar answered Oct 11 '22 12:10

Ingo Karkat


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.

like image 44
Kevin Avatar answered Oct 11 '22 13:10

Kevin