vim script to open related files
Vim script
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Vim script to open related files by command, or by keymap(i.e. \n or any)

Screen Shot

How it works

  • When initialized, set related files

  • In vim window, when NextFile() is called, by key mapping, n, is pressed

    • Get the current file name
    • Get the related files
    • Browse the related files and open in current, splitted, or vertically splitted window


  • \r to open related files
  • <Enter> to open a file
  • o to open in a split window
  • v to open in a vertically split window
  • NEW!! <Enter> on directory will list files in the directory


  • Download the following files into ~/.vim/plugin directory

    • nextfiles.vim
    • singular_expressions.txt
    • plural_expressions.txt
  • To your ~/.vimrc, add a keyboard map to call NextFiles() function

    • The following is my preference. \r to see related files
    nmap <Leader>r <ESC>:call NextFile()&l6;CR>

Or, you may assign \n to see next file on the cursor

    nmap <Leader>n <ESC>:call NextFile()&l6;CR>
  • For Rails developers, there is pre-defined mapping like the following. You may want to change this. If so, you can re-define this in your .vimrc
    let g:nextFilesMap["Ruby On Rails"] = {
      \ "Ruby On Rails" : {
        \ "Controller" : { "expression" : "app/controllers/(.*)_controller.rb$", "transform" : "pluralize" },
        \ "Funtional Test" : { "expression" : "test/functional/(.*)_controller_test.rb$", "transform" : "pluralize" },
        \ "View" : { "expression" : "app/view/(.*)/", "transform" : "pluralize" },
        \ "Model" : { "expression" : "app/models/(.*).rb$", "transform" : "singularize" },
        \ "Unit Test" : { "expression" : "test/unit/(.*)_test.rb$", "transform" : "singularize" }
      \ }
    \ }