Vim logo vim online Vim Book Ad

basic Tip #264: F5 Compile and Run, F8 Compile (ala Visual Studio)

 tip karma   Rating 7/10, Viewed by 1185 

created:   June 22, 2002 9:18      complexity:   basic
author:   Tadghe Danu      as of Vim:   6.0

I love vim, it's my default editor on my Sun, Windows, Linux and *BSD boxen.  That said, I hate having to flip windows to compile while doing the write->compile->debug loop.

If you're used to Visual Studio and the ability it has to just hit F5 to compile and run the current file or F8 to compile or step through the code you'll appreciate this...

This is my Windows version of this scriplet/tiplet.  For other platforms, you'll want to change the IF ELSE loops.  You should actually never see the "Unsuccessful" message from the compile/run loop unless the compiler completely bombs out.   This is from my _vimrc...


map <F5> :call CompileRunGcc()<CR>

map <F8> : call CompileGcc()<CR>

func! CompileRunGcc()
exec "w"   "Save the file
exec "!gcc % -o %< && cr 10 && IF EXIST %<.exe (%<) ELSE banner -c = Compile Unsuccessful "  
exec "i" "jump back where we were


endfunc

func! CompileGcc()
exec "w"
exec "!gcc % -o %<  && IF EXIST %<.exe (cr 5 && banner -c # Success) ELSE banner -c # Compile Unsuccessful "
exec "i"

endfunc

 rate this tip  Life Changing Helpful Unfulfilling 

<<color active line | Fast help in full window >>

Additional Notes

[email protected], June 23, 2002 23:33
You might like to take a look at vim's quickfix mode.

:help quickfix

Also, on unix systems one setup I used for a while (and still have, though I'm more often than not using gvim now) involves running vim from within screen, then you simply have to double-tap ctrl-a to get a shell window.
$ xterm -name VIM -geometry 132x60 -e screen vim
I especially like this method for editing HTML/XML/TeX etc where the post-edit operation isn't a compile, but something like moving files around, rsync, or whatever.

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 [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo