Open a related file based on the path.
Switch branches/tags
Nothing to show
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
plugin Add optional argument to :RelatedFile to open in other modes Apr 14, 2013 Add optional argument to :RelatedFile to open in other modes Apr 14, 2013


A vim plugin for opening a related file based on the file path.


I prefer to use Vundle but it's just as easy using other methods.


Install Vundle, following the instructions.

Add the Bundle to your vimrc:

Bundle 'donaldducky/related.vim'

Then run the BundleInstall from the command line:

vim +BundleInstall +qall


If you use pathogen.vim, you can just clone the repo, manually.

git clone ~/.vim/bundle/related.vim


There are two commands currently exposed:

  1. :RelatedFile - Opens the related file in a vertical split. Optionally accepts an argument to open the related file using other methods:
  • :RelatedFile e opens using :e[dit] command in the current window
  • :RelatedFile sp opens using :sp[lit] command in a horizontal split window
  • :RelatedFile vs opens using :vs[plit] command in a vertical split window
  1. :RelatedTests - Runs the unit tests for the plugin.


  1. Open a source file.
  2. Hit a key to open the related test file.

I bind the :RelatedFile command to a <leader> mapping in my .vimrc:

" Open the related file using ,rf
let mapleader = ","
let g:mapleader = ","
map <Leader>rf :RelatedFile<CR>
map <Leader>re :RelatedFile e<CR>
map <Leader>rs :RelatedFile sp<CR>


I spend far too much time navigating/opening related files that are easy to determine programmatically.

Creating a vim plugin would be the best way to do it but I didn't know how...luckily I stumbled across a post that was created to achieve the same thing:

Optimize Your TDD Workflow by Writing Vim Plugins

It was a good basis for showing me how to create a vim plugin and seeing how little code it was made me dive in.