Re: Conditional autocmd question
- On 2007-01-29, Evan Klitzke <eklitzke.lists@...> wrote:
> Hi everyone,See:
> 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?
let &makeprg = "make"
let &makeprg = "gcc -o foo foo.c"
> Particularly I am confused on how to have a conditional autocmd,See:
> and how to extract a substring from the current buffer/file name.
let basename = expand("<afile>:t:r")
:set makeprg=make\ -o\ %<\ %
Gary Johnson | Agilent Technologies
garyjohn@... | Wireless Division
| Spokane, Washington, USA