How to switch between files in Vim?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to switch between files in Vim?

Gavin Sinclair
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?

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

  - I hit space and type "cont", which is enough to score a unique match

  - I hit ENTER and that file opens

Now that's not really achievable with the interface Vim has, but I'm wondering:

  - Does anybody know a plugin that provides this as best it can?

  - Does anybody have a different approach they use for selecting files?

A bit off topic, I know!

Cheers,
Gavin

_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to switch between files in Vim?

Doug Kearns
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
or
: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

:b
 
>   - 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>
<snip>

HTH,
Doug
_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to switch between files in Vim?

Gavin Sinclair
On 5/1/06, Doug Kearns <[hidden email]> wrote:

>
> :help buffer
>
> :b N
> or
> :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.

I've always thought of the :b command as rather primitive.  Thanks to
your suggestions on its usage (snipped) and the command-line mapping,
though, I'll give it another try.

In my project, I tend to have about 40 files open at once.

Thanks,
Gavin

_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to switch between files in Vim?

Sam Roberts-2
Another approach might be to use tags.

exhuberant ctags has a mode (--extra=+f) that will emit tags for
filenames, so you can to

  :ta fi<TAB>

to show completetions for filenames starting with "fi" and jump to it. I
use that mostly for jumping between files. There are tag command
variants to make new buffers, split windows and jump in the next window,
etc.

Cheers,
Sam

_______________________________________________
vim-ruby-devel mailing list
[hidden email]
http://rubyforge.org/mailman/listinfo/vim-ruby-devel