Compile and run program in Vim

292 views
Skip to first unread message

Jakub Marian

unread,
Dec 16, 2008, 12:53:20 PM12/16/08
to vim...@googlegroups.com

Hello, I use Vim to write programs in Pascal and some other languages. I set
up everything so Vim's quickfix works - :make saves and compiles currently
opened file, :cope displays errors properly... But there's still one thing I
would like to achive and I don't know how. It's quite unpleasant that I have
to run the program manually after I compile it using :make. So my question
is:

Is there any way to compile currently opened file and, if there were no
errors during compilation, execute it - all of that by one command like
":run"?

It may not be the ideal solution when working in console, but when I work in
any kind of graphical environment (and especially when I develop
applications with graphical interface), it would be very helpful.

I know, I could write some sort of script or program that :make would call
instead of the compiler and that would call the compiler itself and catch
its messages - and if there were any errors, pass the messages to standard
output, else execute the compiled program. But would be a very proprietary
solution and I couldn't "migrate" between computers using .vimrc file only.
--
View this message in context: http://www.nabble.com/Compile-and-run-program-in-Vim-tp21035479p21035479.html
Sent from the Vim - General mailing list archive at Nabble.com.

Boyko Bantchev

unread,
Dec 16, 2008, 5:26:50 PM12/16/08
to vim...@googlegroups.com
2008/12/16 Jakub Marian <kub...@gmail.com>:
> .......

> Is there any way to compile currently opened file and, if there were no
> errors during compilation, execute it - all of that by one command like
> ":run"?
> .......

I wanted to do this, and several other simple things with C and C++
programs, so I wrote a script:
http://www.vim.org/scripts/script.php?script_id=2434
You can find other, much more ambitious IDE-like scripts as well,
but mine is small enough to be easy to modify, use parts of it etc.
You could see if it answers your needs and do with it whatever you
like to use it with Pascal.

Regards,
Boyko

Jakub Marian

unread,
Dec 17, 2008, 10:12:28 AM12/17/08
to vim...@googlegroups.com

One big THANK YOU. After few changes this script does exactly what I need. I
was really helpful, thanks. :)
--
View this message in context: http://www.nabble.com/Compile-and-run-program-in-Vim-tp21035479p21054544.html
Reply all
Reply to author
Forward
0 new messages