This is not a direct answer to your question, because I wonder if Vim might already have a more comprehensive solution for your problem.
Vim has support for running a compilation process, opening the compilation output (in the QuickFix List), and jumping to lines where errors were reported.
If you use a GNU Makefile, and you are in the same folder, then all you need to do to compile is type:
But if you compile in a different way, you should first tell Vim how:
:set makeprg=gcc\ file.c\ -o\ myapp
" Or to avoid escaping those spaces, you can instead do:
:let &makeprg="gcc file.c -o myapp"
And then you can compile using your specified method, by doing:
If you don't want to run the compilation from inside Vim, but you still want to open the logfile in the QuickFix List, then do this:
Viewing the errors
The QuickFix List is useful because it can recognise some error log formats, and help you to navigate them. To step forwards or backwards through errors, use:
To view all the errors, open the QuickFix Window:
In that window you can jump to source of an error by pressing Enter. To open in a newly split window, hit Ctrl+W Enter.
For more details on the whole process, see: