Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When navigating in Vim, I often find myself jumping to a file, jumping around that file, then onto another file and so on. Finally, I want to return to the original file. Using <CTRL-O> does the job, but requires many more presses than I'd like.

I'm aware that I could set a mark beforehand, but I'd like a solution that doesn't require any up-front thinking.

I'm looking for a way to navigate back through the jumplist, stopping exactly once per file.

share|improve this question

migrated from stackoverflow.com Mar 31 '13 at 1:26

This question came from our site for professional and enthusiast programmers.

    
I needed this, for when a window's contents were inadvertently changed, and I couldn't remember which buffer I had there previously, only that I wanted it to be there. –  Brady Trainor Jul 28 at 3:38

3 Answers 3

up vote 2 down vote accepted

My EnhancedJumps plugin has mapping variants of <C-o> / <C-i> to restrict jumps to the current or to different buffers.

<Leader><CTRL-O>, <Leader><CTRL-I> Go to [count] older / newer cursor position in another buffer. Jumps inside the current buffer are not considered. Useful for recalling previously visited buffers without going through all local positions. Regardless of the jump direction, the last jump position in a buffer is used when there are multiple subsequent jumps in a buffer.

share|improve this answer
    
Perfect, that's exactly what I'm looking for. Thanks. –  Paul Carey Mar 31 '13 at 14:46

I am not sure if I got you right. You want to jump between files/buffers, not the positions in jumplist. (which could be many positions in same file)

Then you could check buffer related commands. e.g.

:ls        "list all buffers, Number, name
:b[N]      "switch to buffer N
:b <tab>   "after tab, buffer name auto-completion 

and there are many plugins that help us to switch buffer easily.

share|improve this answer

The jumplist's purpose is not to help you jump from buffer to buffer: it records all the jump motions you do. Since typical vim usage includes lots of jumps within and across buffers, it would be a mistake to use it to navigate between buffers.

Unless you never use jump motions, that is. But that would be an even bigger mistake.

Vim has the buffer list which, as the name implies, is a list of all your buffers and comes with a bunch of navigation commands of its own. Unfortunately, this list is "static": you can navigate to the previous buffer in the list but not to the previously accessed buffer. Vim doesn't keep such a list.

I navigate buffers with names. But it could probably be doable to write a function that filers the jumplist and navigates to the first different buffer. I can't do that on this phone right now but I don't think it would be too hard.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.