Find the answer to your Linux question:
Results 1 to 8 of 8
hi,,i am new on linux programming..i want to know how can i compile a c program on vim editor?which commands should i use? thanks for reading.....
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2005
    Posts
    20

    vim compile


    hi,,i am new on linux programming..i want to know how can i compile a c program on vim editor?which commands should i use?
    thanks for reading..

  2. #2
    Linux Engineer
    Join Date
    Apr 2005
    Location
    Buenos Aires, Argentina
    Posts
    908
    compile a program on vim? vim is an editor.. it has nothing to do with compiling!
    serzsite.com.ar
    "All the drugs in this world won\'t save you from yourself"

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Well, it can be done by executing shell commands, but this is not what I recommend.

    Write your program in vi, then type, in command mode, ":wq" and enter. This will save your file and exit you from vi.

    Now, back on the commandline, enter:
    Code:
    gcc -Wall -o foo foo.c
    This will use gcc to compile your program, display all errors, and name the resulting executable "foo".

    If you get an error about "gcc: command not found", you need to install gcc. The path for this is distro-dependent.

    Okie dokie?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru dylunio's Avatar
    Join Date
    Aug 2004
    Location
    Cymru
    Posts
    4,157
    You can run shell commands in vim, so to compile something you'd use: Esc
    Code:
    :!gcc -Wall -o foo foo.c
    within the editor.
    Registered Linux User #371543!
    Get force-get May The Source Be With You
    /dev/null
    /dev/null2

  6. #5
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    Quote Originally Posted by Cabhan
    Well, it can be done by executing shell commands, but this is not what I recommend.
    How would you recommend compiling something then?

  7. #6
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    I'd recommend doing it outside vim, in the shell proper, as opposed to the within-vim option indicated by dylunio.

    Ah, I see how that's ambiguous. I apologize.

    And actually, now looking at it, I see that it may not be such a bad solution at all. *shrugs* I guess I just prefer to operate outside vim for running my apps.

    So yeah, you can either exit to the shell proper or use dylunio's within-vim option. Bother are viable.

  8. #7
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    I know what you mean. I thought you meant not to use the shell.
    But I have a similar qualm with the Emacs shell. I really don't use it much for compiling because of its rudimentary functionality ( although in Emacs' defense, the documentation doesn't claim the shell to be otherwise! ) such as lack of tab-completion.
    Oh well...

  9. #8
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    Well, Vim has a nice, little feature called 'quickfix' that enables you to invoke make utility from within and provides a nice navigation over spotted errors. Type ":help quickfix" in Vim to learn more. Regards...
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •