4

At first I am going try to explain you "order of opening". For example, if I'll open files in this order:

1_file.c
2_file.c
3_file.c
4_file.c

:ls command will give me:

:ls
  1      "1_file.c"                     line 1
  2      "2_file.c"                     line 1
  3 #    "3_file.c"                     line 1
  4 %a   "4_file.c"                     line 1

After if I'll jump into buffers :b3, :b2, :b4, then if I'll invoke :bp command then I would go in the buffer 3 or if i'll invoke (from buffer 4) :bn I would go in the buffer 1. So I'll jump between buffers in order of opening.

But I want to simple method to jump between files in "order of accessing", for example from previous example if I'll jump into buffers :b3, :b2, :b4. I want to jump back like: buffer 2, buffer 3, and after jump forward like buffer 2, buffer 4. I hope you guys understand what I mean. Is there native command in vim to achieve this?

I was searching on the Internet about this facility, but no luck. There are commands for jumping in history with CtrlO and CtrlI but it cause jumping inside of same file too.

2

My EnhancedJumps plugin provides (among other variants) <Leader><C-O> and <Leader><C-I> commands that work like built-in <C-O> / <C-I>, but skip over jumps inside the same buffer.

I personally use the old MruMenu plugin for buffer recall. It uses the menu (in GVIM), is file-based instead of showing the current buffers, and limits to N entries, though.

  • I was hacking a little with your plugin, it does pretty great stuff. Thank you! But actually I wanted more :bp, :bn-like behaviour, I mean cycling jumping between current buffers. So I don't want jump onto already deleted buffers and want to jump on the first one if it was last buffer in the list of accessed buffers. – Alexander Myshov May 4 '15 at 14:21
  • Well, you could modify my plugin / take some parts to build your own. Actually, I use a slightly different approach to the problem; see my edit. – Ingo Karkat May 4 '15 at 14:44
1

I just found a plugin on reddit which does exactly what you want: bufsurf. From the readme:

... This plugin supplies the user with the commands :BufSurfForward and :BufSurfBack to navigate buffers forwards and backwards according to the navigation history. ...

  • Thanks! It's actually what I wanted. By the way I already found this facility in github.com/jeetsukumaran/vim-buffergator plugin, but for me it's just overkill to use this plugin only for 2 commands, maybe if I need more comprehensive tool for bufer managment, but not now. – Alexander Myshov May 15 '15 at 16:45
  • I've returned back to the buffergator, because bufsurf jumps to closed buffers. – Alexander Myshov May 26 '15 at 11:13
0

The Unite plugin's buffer source remembers the order of accessing. I just opened the files in the order you wrote, and the buffer-chooser window looks like this:

unite buffer and list of buffers

You can open the Unite with :Unite buffer -direction=botright, press <Down><CR> to go to the next buffer and <Up><CR> for the previous.

To make life simpler, here's the mappings to go to the older/newer buffer:

map  <C-Y>  :Unite buffer -direction=botright<CR><Up><CR>
map  <C-E>  :Unite buffer -direction=botright<CR><Down><CR>

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.