tags:

views:

173

answers:

2

Is there a good project / session manager for vim? A session (or project) is a named lists of files, e.g. "bitonic_sort" could identify files "~/A/bitonic_sort.sk", "~/B/bitonic_sort.smt2", etc.

(rationale) I have a project where I need to edit files from many different locations, and it is too cumbersome to open them manually each time I resume work. (so, it looks like things like nerdtree brought up at this sister question, http://stackoverflow.com/questions/21725/favorite-gvim-plugins-scripts, won't work). I also need separate sessions (i.e. lists of files) for different projects, not just a recent document list.

After all documents have been loaded as buffers, any enhancements to switching between them is a plus (e.g. start typing a name, and matching documents are displayed). Thanks in advance.

+3  A: 

I'm not sure exactly what you're asking for... but if you want to turn on tab-completion when opening files in vim, add this to your ~/.vimrc:

" Auto-complete file names after <TAB> like bash does.
set wildmode=longest,list
set wildignore=.svn,CVS,*.swp

Also, take a look at screen. From the man page:

When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would. Then, at any time, you can create new (full-screen) windows with other programs in them (including more shells), kill existing windows, view a list of windows, turn output logging on and off, copy-and-paste text between windows, view the scrollback history, switch between windows in whatever manner you wish, etc. All windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the user's terminal. When a program terminates, screen (per default) kills the window that contained it. If this window was in the foreground, the display switches to the previous window; if none are left, screen exits.

It's pretty much like having several xterms open, except unlike graphical xterms you can access your screen session if you access your machine remotely (e.g. by sshing to it). You could leave up several different instances of vim in separate screens with all the files you want open, and just never exit them.

The very basic setup I use is one vim window, one compile window, and one testing/debugging window.


And since we're talking about vim, check out this post: Post your Vim config. Lots of cool tweaks and spiffy stuff in there.

John Kugelman
I want a "project" / "session" concept (named list of files, e.g. "bitonic sort project"), possibly with alternate document lists / switchers. Please clarify the question if something's unclear. Screen is a good idea, I'll have to learn that sometime :)
gatoatigrado
Oh, duh, like IDEs have. I don't know how to do that.
John Kugelman
+3  A: 

Vim has built-in session manager. To save your current session use:

:mks session1.vim

This basically create a Vim script named session1.vim, which will restore your opened file if you source it or start Vim like this:

vim -S session1.vim

To overwrite your saved sessions, use :mks! your_saved_session.vim. Combine with a custom key map and this will be the solution. For more about Vim session read :help :mks. Vim also has views manager which is quite similar. Read more from: :help :mkview

For switching between buffers, you can use FuzzyFinder; but I prefer this key map:

nmap <C-tab> :bn<CR>
imap <C-tab> <ESC>:bn<CR>i

Add it to .vimrc and I can use Ctrl + Tab to switch between buffers just like Firefox tabs. Hope this help.

tungd
Great, thanks! I do work with a _lot_ of files, and FuzzyFinder seems awesome! One minor thing -- vim's filename completion is useful, but I'd like it to just save the active session on exit... do you happen to know how to do this?
gatoatigrado
Yeah, that's a great idea. After Googling a bit I find this Vim script [vim-session](http://github.com/xolox/vim-session). It comes with some extra features that I don't need, so I borrowed some code and come up with this: `au VimLeavePre * if v:this_session != '' | exec "mks! " . v:this_session | endif` .Add this to your .vimrc and your current session will be saved automatically when exit.
tungd
Wow, you are awesome, thanks so much!!!
gatoatigrado