How to switch between files in Vim?

Doug Kearns dougkearns at
Sun Apr 30 10:37:32 EDT 2006

On Sun, Apr 30, 2006 at 07:27:16PM +1000, Gavin Sinclair wrote:
> Hi folks,
> Just wondering...
> If you have a lot of files open in Vim, how do you switch to the one
> you want in the easiest fashion?

:help buffer

:b N
:b filename

I find that if there's a manageable amount, say less than 10, you can
generally remember the buffer number. If there's more than that then I
use the second method.
> In my Rails project, there are lots of files (models, views,
> controllers, helpers, javascript, etc.) and I need to flick around
> between them.  I use and highly recommend the Project plugin, but
> ideally I could just type in a few characters from the filename and go
> there.
> The perfect interface would be something like this.  Say I want to
> switch to "user_controller.rb".
>   - CTRL-G (for Goto file) pops up a small window where I can type
>     letters and it can display some matching filenames

>   - I type "user" and it narrows it down to about 6 files

:b user<C-d>

A mapping is useful here. Something like:
:cmap <Tab> <C-l><C-d>
>   - I hit space and type "cont", which is enough to score a unique match

:b user_cont<Tab>
>   - I hit ENTER and that file opens

:b user_controller.rb<Enter>


More information about the vim-ruby-devel mailing list