How to keep a history of Vim files

I am using Vim 7.3 with the MRU plugin .

With this plugin, when you enter :MRU you will see a new window with the most recently used files. This is cool, but I want something more specific than this:

Let's say that I work with only one window. First I open file A, then file B, then file C.

Now that I am in file C, I want to go back to file B and then go back to file A with a key press, just like the back button in the browser history. And I want to do the same thing to move forward, from file A back to file B and finally return to file C, as if I were playing with the browser history.

How can i do this?

+4
source share
3 answers

Files A, B, and C are called "buffers" in the Vim language. What you want is the ability to directly jump from buffer to buffer or the ability to select the buffer you want to jump to.

Jumping from one buffer to another is easy. This is done using the command :b or its cousins:

 :b filename<CR> " jump directly to the named buffer :b fil<tab> " select from <tab>-navigable menu if " more than one match, completes the " filename otherwise :b <tab> " select from <tab>-navigable menu :2b " go to buffer number 2 :bfirst<CR> (or :bf) " self-descriptive :blast<CR> (or :bl) " self-descriptive :bnext<CR> (or :bn) " self-descriptive :bprevious<CR> (or :bp) " self-descriptive 

Selecting a buffer from the list is also simple:: :ls<CR> displays a numbered list of buffers and waits for a command. At this point, enter :b <number><CR> or :<number>b<CR> to jump to the selected buffer. You can add the following conversion to your ~/.vimrc to speed up the whole process:

 nnoremap <leader>b :ls<CR>:b<space> 

You also have a fairly large number of plugins for switching buffers (the rest of the page is also filled with interesting information).

I use CtrlP , which is not specified when I can, and displayed above when I can not.

+3
source

Vim records a list of the last 100 jump moves you made both inside and between files. You can use Ctrl - O to go to previous locations and Ctrl - I to go forward again.

+6
source

I also highly recommend using the Tim Pope Unimpaired plugin , which allows you to do :bprev and :bnext with [b and ]b , as well as much more.

0
source

All Articles