sponsor Vim development Vim logo Vim Book Ad

FSwitch : Allows switching between companion source files (like a.vim)

 script karma  Rating 120/47, Downloaded by 5055  Comments, bugs, improvements  Vim wiki

created by
Derek Wyatt
script type
This script is designed to switch between companion files much like vimscript #31 (a.vim).

Out of the box it will support C and C++ for most usages, unless you've got an interesting setup I haven't guessed.

You can:

  - switch the file and keep it in the current window with :FSHere

  - switch the file and put it in the window to the left with :FSLeft
  - switch the file, split the window to the left and put it there with :FSSwitchLeft

  - the same can be done with Right, Above and Below.

The switch function should be easy enough to call in different ways that give you more exotic behaviour.

Using the location directive, you can be quite specific about how the companion file is resolved and, more importantly how it's created when it doesn't exist.  This latter bit was apparently a sore point with a.vim and I hope that it's acceptable in FSwitch.

You can state locations as being the result of

- a regular expression substitution
- a globbed match
- a relative path (either unconditionally or only if the current buffer's path matches a required pattern)
- an absolute path (either unconditionally or only if the current buffer's path matches a required pattern)

Using an autocmd to set the buffer-local variables allows you great flexibility in specializing the behaviour of FSwitch.

There are also a couple of public functions you can use to retrieve the companion file for use in your own functions as well.

This script is now maintained at https://github.com/derekwyatt/vim-fswitch
install details
I've put this in a format that's easiest to use with pathogen (vimscript #2332).  Just unzip it in the right spot (say, ~/.vim/bundle) or unzip it and copy the 'plugin' and 'doc' directories into the right spot in the runtime path (say, ~/.vim).

You can also use package managers that work with GitHub by using the repo https://github.com/derekwyatt/vim-fswitch

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
fswitch-0.9.3.zip 0.9.3 2010-10-12 7.0 Derek Wyatt Small fix to check for Vim version (Timon Kelter)
FSwitch-0.9.2.vba 0.9.2 2009-10-10 7.0 Derek Wyatt Fix to the split commands (Thanks to Michael Henry)
FSwitch-0.9.1.vba 0.9.1 2009-03-25 7.0 Derek Wyatt See :h fswitch-changes

Added :ifrel and :ifabs location directives
Exposed two public functions for retrieving the companion file in a script
Changed defaults for c/c++ code to use :ifrel instead of :rel
FSwitch-0.9.0.vba 0.9.0 2009-03-24 7.2 Derek Wyatt Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.