sponsor Vim development Vim logo Vim Book Ad

LoadHeaderFile.vim : load filename from an #include line

 script karma  Rating 22/9, Downloaded by 1545    Comments, bugs, improvements  Vim wiki

created by
Garner Halloran
script type
Here are the mappings I use for this script (which I'll use in my description)

map <F12> :call LoadHeaderFile( getline( "." ), 0 )<CR>
map <C-F12> :call LoadHeaderFile( getline( "." ), 1 )<CR>

To use the script, just have your cursor on a #include line and hit F12 to load the .h file or C-F12 to load the corresponding .cpp file.  It splits the window when it loads the file.  If it can't find the file it just gives you an error that it can't find the file.

You have to have your path set up correctly for it to work.  If you don't know how to do that, simply add a "se path=.,c:/path/**,c:/another path/**" to you _vimrc.  Obviously there is a better explanation of paths in the help.

The code works on includes with <> or "".  It only checks for .h and .cpp, but you could modify it to do more.  I kept it simple so it's quicker.

And as I'm typing this up I noticed that the #include has to be at the beginning of the line...can't have spaces or tabs.  I'll fix that in the next version :)

If you see any flaws or ways to improve this script, please let me know since I'm still learning how to script.
install details
If you're using Vim 6.0, just put it in the plugins directory.  Otherwise, just source it with all your other functions.

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
LoadHeaderFile.vim 1.1 2001-07-05 6.0 Garner Halloran A little more efficient pattern searching.  Added support for loading header files that don't end in .h (ie fstream).  Added support for loading .c files instead of just .cpp files.  Added loaded_LoadHeaderFile so you can disable the plugin.  Fixed bug where it didn't recognize a #include if it wasn't at the beginning of a line.
LoadHeaderFile.vim 1.0 2001-06-22 6.0 Garner Halloran 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.
SourceForge.net Logo