Loading ...
Sorry, an error occurred while loading the content.

how to execute outer program with a parameter of the filename being edited

Expand Messages
  • guojq
    hi, guys, I am wondering how to execute an outer program with a parameter of the filename being edited automatically. Say, when I am editing any c source
    Message 1 of 3 , Mar 2, 2008
    • 0 Attachment
      hi, guys,

      I am wondering how to execute an outer program with a parameter of the
      filename being edited automatically. Say, when I am editing any c
      source file, I then can use gcc to compile any source files inside vim
      and do not need to input the source file name.
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Ben Schmidt
      ... In an Ex command, % stands for the file name in the current buffer. So you can do ... or you can make use of Vim s amazing :make command that will parse
      Message 2 of 3 , Mar 2, 2008
      • 0 Attachment
        guojq wrote:
        > hi, guys,
        >
        > I am wondering how to execute an outer program with a parameter of the
        > filename being edited automatically. Say, when I am editing any c
        > source file, I then can use gcc to compile any source files inside vim
        > and do not need to input the source file name.

        In an Ex command, % stands for the file name in the current buffer. So you can do

        :!gcc %

        or you can make use of Vim's amazing :make command that will parse the output and
        jump from error to error if you do

        :set makeprg=gcc\ %

        then you can use :make, :cn, :cp, :copen, etc.

        There are other things apart from % that can be replaced, and more complicated
        replacements, e.g. path or basename only, etc., see

        :help cmdline-special
        :help :_%:
        :help :make
        :help :cc

        Cheers,

        Ben.





        Send instant messages to your online friends http://au.messenger.yahoo.com


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tony Mechelynck
        ... see ... for example ... or even ... to give to the make program the name of the current file with .c removed and .o added (as a make target). Best regards,
        Message 3 of 3 , Mar 2, 2008
        • 0 Attachment
          guojq wrote:
          > hi, guys,
          >
          > I am wondering how to execute an outer program with a parameter of the
          > filename being edited automatically. Say, when I am editing any c
          > source file, I then can use gcc to compile any source files inside vim
          > and do not need to input the source file name.

          see
          :help current-file
          :help filename-modifiers
          :help 'makeprg'
          :help :compiler
          :help :make

          for example
          :!someprogram %
          or even
          :make %:r.o

          to give to the make program the name of the current file with .c removed
          and .o added (as a make target).


          Best regards,
          Tony.
          --
          We're only in it for the volume.
          -- Black Sabbath

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        Your message has been successfully submitted and would be delivered to recipients shortly.