Vim - 以当前文件作为参数运行 ant 命令

发布于 2024-12-04 00:33:29 字数 266 浏览 2 评论 0原文

在我的 IDE (webstorm) 中,我配置了一个外部工具来运行 ant,如下所示:

ant myTarget -DfileNoExt="$FileNameWithoutExtension$"

运行命令时 IDE 会扩展 $FileNameWithoutExtension$

我正在过渡到使用 Vim。我是 Vim n00b。

我如何使用 Vim(特别是 MacVim)做同样的事情?

In my IDE (webstorm) I have configured an external tool to run ant like so:

ant myTarget -DfileNoExt="$FileNameWithoutExtension$"

the $FileNameWithoutExtension$ is expanded by the IDE when the command is run.

I am transitioning to using Vim. I am a Vim n00b.

How do I do the same with Vim (MacVim specifically)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心碎的声音 2024-12-11 00:33:29

Vim 会将 % 扩展为当前文件。您可以对其使用修饰符(请参阅:help filename-modifiers)。您可以告诉 vim 使用 ant 作为您的 make 程序:

compiler ant
setlocal makeprg=ant\ myTarget\ -DfileNoExt=\"%:t:r\"

现在您可以使用 :make 来构建当前文件。您应该在快速修复中遇到构建错误(使用 :copen 查看)。

您可能希望将上述脚本放入文件 ~/.vim/after/ftplugin/java.vim 中。这将为您打开的每个 java 文件加载它。


请注意,如果您想使用不同的目标,:make 会将所有参数传递给 ant。因此 :make otherTarget 将执行 ant myTarget -DfileNoExt="file" otherTarget

Vim will expand % as the current file. You can use modifiers on it (see :help filename-modifiers). You can tell vim to use ant as your make program:

compiler ant
setlocal makeprg=ant\ myTarget\ -DfileNoExt=\"%:t:r\"

Now you can use :make to build your current file. You should get build errors in your quickfix (view it with :copen).

You probably want to put the above script into a file ~/.vim/after/ftplugin/java.vim. That will load it for every java file you open.


Note that if you want to use different targets, :make will pass all arguments to ant. So :make otherTarget will execute ant myTarget -DfileNoExt="file" otherTarget.

安稳善良 2024-12-11 00:33:29

你可以在 vim.rc 中映射热键或你自己的按键序列(在 mac 中不确定,应该有类似的资源文件)

将此行添加到你的 vim 资源文件中:

imap <F5> <ESC><ESC>:!ant mytarget -Dfilenoext=\"%<\"

这意味着当你编辑源代码时,按 F5 将运行你的蚂蚁工具
有关更多信息,您可以阅读 http://vim.wikia.com/wiki/Compile_Java_with_Sun_JDK_javac 和 < a href="http://www.vim.org/scripts/script.php?script_id=155" rel="nofollow">http://www.vim.org/scripts/script.php?script_id=155

you can map either Hotkey or Your own key-sequence in vim.rc(not sure in mac, should have similar resource file)

add this line to your vim resource file:

imap <F5> <ESC><ESC>:!ant mytarget -Dfilenoext=\"%<\"

which means when you editing the source code, press F5 will run your ant tool
for more, you can read http://vim.wikia.com/wiki/Compile_Java_with_Sun_JDK_javac and http://www.vim.org/scripts/script.php?script_id=155

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文