Hello,

Probably the most straightforward way to do this in your ~/.vimrc file:

  nnoremap <F3> :call CompileScript()<CR>

  function! CompileScript()
    " the name of the current file
    let fname = expand('%')

    " can't compile unless the file is saved
    if &modified
      echo printf('Please save %s before compiling', fname)
      return
    endif

    " decide how to execute the script:
    if &filetype == 'perl'
      execute printf('!perl %s', fname)

    elseif &filetype == 'ruby'
      execute printf('!ruby %s', fname)

    elseif &filetype == 'bash' || &filetype == 'sh'
      execute printf('!source %s', fname)

    else
      echo printf("Don't know how to compile filetype '%s'", &filetype)
    endif
      
  endfunction


I hope that's enough to get you started.

regards,
Peter


--- atstake atstake <[EMAIL PROTECTED]> wrote:

> I'm using vim 6.4.7 on Fedora Core 5. I would like to compile C,
> Perl, ruby & bash script from within vim. I want vim to recognize a file
> by extenstion and if I map it to, say, <F3> vim would be able to compile
> the code based on the extension; eg. if it's a .pl file it would do
> "perl filename", show the result and if there's any error it would take
> me to the line where the error is.
> 
> Is there any easy way to do this with functions? Any example would be
> greatly appreciated.
> 
> Thanks.
> 


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

Reply via email to