I frequently have several buffers open in my Vim session. This means that my jumplist stores locations from several buffers. However, frequently when I use Ctrl-o to jump to a previous location, I do not want to leave the buffer and want to jump to previous locations "local" to the current buffer. How do I do this?
Example: If my jumplist looks like to following:
4 10 1 ~/aaa.m
3 20 1 ~/aaa.m
2 12 2 ~/xxx.m
1 15 1 ~/aaa.m
I want to jump to line 15 of file aaa.m the first time I press Ctrl-o. Importantly, the next time I press Ctrl-o, I do not want to jump to file xxx.m. Rather, I want to jump to line 20 of file aaa.m; that is, my previous location within the "current" buffer. The default behaviour of Vim is to take me to to line 12 of file xxx.m. Any ideas on how I can achieve this?
Maybe the EnhancedJumps plugin will help.
With this plugin installed, the jump to another buffer is only done if the same jump command is repeated once more immediately afterwards.
Try the following jump-list traversing function. It steps successively from one jump-list location to another (using Ctrl+O or Ctrl+I depending on what values its
back
andforw
arguments have) and stops if the current location is in the same buffer as that buffer it has started from. If it is not possible to find a jump-list location relating to the buffer, the function returns to the position that jump-list has before start.To use this function as a Ctrl+O/Ctrl+I-replacement locked to the current buffer, create mappings as it shown below.