| I use several things to work better with multiple files, in a tree: 1. Vim sessions: saving named sessions and restoring. (With some custom commands, see below.) 2. A plugin called BufExplorer (slightly hacked, see below). 3. My own implementation of "autochdir" (current working directory follows file). My own implementation of "autochdir" consists of: A variable $top bound on startup which keeps track of the original directory where Vim is executed. This is assumed to be the root of the project. The absolute path to the root is available in $top, which can be interpolated almost anywhere. :let $top=getcwd()
The following three commands implement the behavior similar to Vim's built in autochdir:When we load a buffer, change to its directory via "lcd" (local cd): :au BufWinEnter * exec "lcd " . expand('%:h')
If the file name is blank, go to the top directory: :au BufWinEnter * if expand("%") == "" | exec "lcd $top" | endif
If the file is under .git/, likewise go to the top. E.g., when we are editing ./git/COMMIT_EDITMSG, we don't want to be under .git. :au BufWinEnter *.git/* exec "lcd $top"
For helping with sessions::S colon command for creating a session. Argument is a name, interpreted relative to $top (defined above). For example :S foo saves a session called $top/foo. :command -nargs=1 S exec "mksession! " . expand('$top/') . expand('<args>')
+ command for saving the session at any time. Overrides the + which goes to the next line (never used by me). You just hit + in command mode to save the session. :nmap + :wa<Bar>exe "mksession! " . v:this_session<CR>
A saved session is restarted with "vim -S <sessionfile>".My small for BufExplorer is this. The default command for launching BufExplorers menu is the Vim leader character (\) followed by "be". I found this to be obtuse so I changed it to be \ followed by \. Thus two backslashes brings up the BufExplorer screen: :nnoremap <script> <silent> <unique> <Leader>\ :BufExplorer<CR>
BufExplorer is a window in which you have an interactive view over the buffers. They can be shown in various orders like most recently used first. You can move around in them, hit Enter to activate the one under the cursor, d to delete, search through them, and so on. There are other buffer managers for Vim. |