There are exactly 5,271 MRU (most recently used) vim plugins already in existence. And yet I felt compelled to write another one myself. Why? Three reasons.
Because I love building things. Especially things I don't know how to build. Because I also love learning things.
Because I have two big gripes with every MRU plugin I've ever tried.
a. They never expose their MRU list, meaning that you might actually have multiple plugins managing what amounts to the same list, which is not performant. For example, I used to use mru.vim for my MRU list. But I also used bufexplorer which manages it's own internal list in order to sort buffers in its interface. Wouldn't it be great if mru.vim just exposed its list and bufexplorer used that?
b. These plugins never seem to expose simple mappings for traversing the MRU tree backward and forward. They're almost always an interface for selecting from a list, e.g. in the
:browse oldfilesformat. Which is not what I want. I want to be able to bounce back and forth between a couple related buffers quickly without having to think about what the name or buffer number is (I'm assuming most people do
:b <name_or_number>to accomplish this most of the time).
Because there is exactly one word in the English language that has the letters "mru" in order. And that word is "rumrunner." When I learned that, I knew immediately that I could not fail to write an MRU plugin. Seriously, this was the main reason.
So I wrote vim-rumrunner, an MRU plugin that satisfies both of my gripes with existing MRU plugins and also features nifty pirate-themed ascii art.
___ | | | | _ \_ _ _ __ _ _ _ _ _ _ _ _ ___ _ _ )_) )_) )_) | / || | ' \| '_| || | ' \| ' \/ -_) '_| )___))___))___)\ |_|_\\_,_|_|_|_|_| \_,_|_||_|_||_\___|_| ) ___) ___) ___)\\ ) ___| ___| ___| ___\\\__ -----------------------------------------------\ /------- ^^ ^ ^^ ^^^^^ ^^ ^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^ ^ ^^^ ^ ^^ ^ ^^^^ ^^^^^ ^^^^^^
Rumrunner keeps track of your most recently used buffers and exposes that list for other plugins (or just ambitious vim scripters) to consume for whatever fancies they may find. I've even incorporated it into another vim plugin I wrote called vim-rebuff, which is my answer to some of the buffer manager short comings I've experienced. But more on that in another post.
Rumrunner also exposes the
]r normal mode key mappings (in keeping with the mappings from vim-unimpaired), "r" for either "recent" or "rumrunner" - take your pick. At any rate,
[r traverses the MRU list backward, and
Is that a question in the back? Yes, you with the hand up. "How can you go forward in an MRU list?" you ask? "Once you go backward once, isn't that now the most recently used and the one you just left the next most recently used? Won't you just bounce back and forth between those two for all eternity, nary to see the light of the terminal again?" Indeed, that is a problem, and probably why most MRU list plugins don't provide this functionality. But I shan't be defied by such nonsense as logic and reason. I added a (configurable) timeout (that requires vim 8) that defers modifying the MRU list so that you can go backward in the list and then come forward again through the same progression without changing the order of the buffers. Once you stop traversing the list, it updates the list to put the now current file at the head of the list (the most recently used). I just said "list" a lot. And you just reread to count.
This plugin is most useful when I'm working in a bunch of related files because usually changing something in one file reminds me that I need to also change something in another. And while there are other ways to find your way from shore to shore across the untamed depths of vim buffers, rumrunner is a captain who knows those waters. It's been the most expedient remediation when I know I was just in the buffer I'm looking for.
And you, oh reader, are you fettered by multiple MRU lists, unable to easily navigate the waters of buffers past? Do you love pirates? And ascii art? Of course you do! They're both so trendy! Then, dear reader, it's time for a better MRU plugin. It's time for rumrunner.