How can I refer to an open file in Vim?

In vim, how can I link to the file I am currently editing? I want to be able to map a key to run :!java

in a file that I am currently working on.

+3


source to share


1 answer


You can use %

to reference the current filename of the buffer; modifiers (cp. :help filename-modifiers

) such as :p

can create a full absolute path or shave off the extension.

Note that the c solution !java

will only work with simple classes in the default package, which is not recommended. If you don't want this just for rapid prototyping and throwing things away, I would suggest you use a build system like Ant or Maven and define a target like running there. Then with the correct 'makeprg'

one installed in Vim, you can start the application (also if not directly editing the Java file containing the main class) with



:make run

      

+6


source







All Articles