Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-09-2006, 04:01 AM
|
#1
|
|
Member
Registered: Apr 2004
Location: Baltimore, MD
Posts: 681
Rep: 
|
gcc from within vim
I use "makeprg=gcc\ -o\ %<\ %" in my .vimrc and from within vim I just type ":make" and it compiles my C code. But I have to exit vim everytime and run the compiled code to see the result. I was wondering if I could see the output without exiting vim. I know I could use ":!./code" but I want something that would compile the code and show me the result at the same time without me exiting vim.
|
|
|
|
09-09-2006, 06:54 AM
|
#2
|
|
LQ Veteran
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 8,711
|
Hi,
Is this what you are looking for:
Code:
map <F3> : call CompileGcc()<CR>
func! CompileGcc()
exec "w"
exec "!gcc % -o %<"
endfunc
map <F4> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
exec "!gcc % -o %<"
exec "! ./%<"
endfunc
This, when added to your vimrc, will use F3 to compile and F4 to compile and run. Errors (if any) and output is shown.
Hope this helps.
|
|
|
|
10-20-2006, 03:17 PM
|
#3
|
|
Senior Member
Registered: Sep 2005
Location: West Virginia
Distribution: Gentoo
Posts: 1,249
Rep:
|
With alittle editing to your code, it really helped me a lot as well. Thanks druuna.
|
|
|
|
03-04-2008, 04:46 AM
|
#4
|
|
LQ Newbie
Registered: Jan 2008
Posts: 23
Rep:
|
How to compile vim
Hi druuna
I have found you answered a question about vim compiler so I thought maybe you can help me. I tried to learn vim and have wrote a simple code. I now need to compile it to see how it work but I am not sure how. I have SUSU 9.3 installed and I used YaST to installed gcc so I know it is there. After writting and saving vim code, how do I compile/run it? it may sound stupid but I am just now sure how to go about it, I mean what command should I use?
please help.
Many thank
|
|
|
|
03-04-2008, 06:43 AM
|
#5
|
|
LQ Veteran
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 8,711
|
Hi,
In post #2 I describe how you can attach a function key (F3 and F4 in the example) to a piece of code that will compile (F3) or compile and run (F4) a piece of c code written in vi(m).
I'm not sure what it is you are actually looking for:
A) in general how to compile using gcc,
or
B) compiling (and possibly running) code without leaving the vi editor.
The answer I gave in post #2 deals with B (not having to quit vi to compile and/or run the code you just typed).
Hope this helps.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:19 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|