On 2007-01-29, Evan Klitzke <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
> I have the F2 key mapped as a "compile" function for the programs I
> write, e.g. if I am editing a .tex file I have an autocmd to execute
> pdflatex, if I am editing a .py file I have an autocmd to execute
> python. The case of .c files is somewhat trickier: I want to use autocmd
> to map F2 to :make if a Makefile exists in the current directory,
> otherwise it should try to compile the file with gcc. For example, if I
> am editing foo.c, hitting F2 should execute "gcc -o foo foo.c". Do you
> have any recommendations on how to do this?
See:
:help filereadable()
Example:
if filereadable("Makefile")
let &makeprg = "make"
else
let &makeprg = "gcc -o foo foo.c"
endif
See also:
help let-option
help make
help makeprg
help 30.1
> Particularly I am confused on how to have a conditional autocmd,
> and how to extract a substring from the current buffer/file name.
See:
:help <afile>
:help fnamemodify()
:help expand()
:help filename-modifiers
:help extension-removal
Example 1:
let basename = expand("<afile>:t:r")
Example 2:
:set makeprg=make\ -o\ %<\ %
HTH,
Gary
--
Gary Johnson | Agilent Technologies
[EMAIL PROTECTED] | Wireless Division
| Spokane, Washington, USA