Search code examples
vimjavac

javac current file code in vim file?


I want to source a vim file in vimrc file. I wrote code in vim file.

set makeprg=javac %

and vim said he doesn't know that option. how do i write code that javac current file?

what I want to do is compiling current file in vim while coding..


Solution

  • On the command-line a space is used to separate 2 arguments. So, when you execute:

    set makeprg=javac %
    

    The :set command assigns the value javac to the option 'makeprg', then it tries to enable the option '%', which doesn't exist, hence the error.

    If you want the space to be included inside the value of the 'makeprg' option, you need to escape it:

    set makeprg=javac\ %