LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 09-09-2006, 04:01 AM   #1
noir911
Member
 
Registered: Apr 2004
Location: Baltimore, MD
Posts: 681

Rep: Reputation: Disabled
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.
 
Old 09-09-2006, 06:54 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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.
 
Old 10-20-2006, 03:17 PM   #3
Penguin of Wonder
Senior Member
 
Registered: Sep 2005
Location: West Virginia
Distribution: Gentoo
Posts: 1,249

Rep: Reputation: 45
With alittle editing to your code, it really helped me a lot as well. Thanks druuna.
 
Old 03-04-2008, 04:46 AM   #4
hongnguyen70
LQ Newbie
 
Registered: Jan 2008
Posts: 23

Rep: Reputation: 15
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
 
Old 03-04-2008, 06:43 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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.
 
  


Reply

Tags
gcc, vim


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
encryption with Vim (vim -x) mikshaw Linux - Software 2 03-07-2007 09:00 AM
LXer: Vim tips: Using Vim mappings and abbreviations LXer Syndicated Linux News 0 06-18-2006 01:54 PM
LXer: Cream for Vim - Making Vim more user friendly LXer Syndicated Linux News 0 06-17-2006 11:54 PM
Vim/Gcc How To Install? moridon77 Linux - Software 2 06-27-2004 07:14 AM
Question about vim and gcc. sharathkv Linux - Newbie 1 07-31-2003 06:09 AM


All times are GMT -5. The time now is 05:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration