LoadHeaderFile.vim : load filename from an #include line
| script karma
Downloaded by 1330
Comments, bugs, improvements
script versions (upload new version)
|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.
|If you're using Vim 6.0, just put it in the plugins directory. Otherwise, just source it with all your other functions.|
Click on the package to download.
ip used for rating: 188.8.131.52
||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.