简体   繁体   English

是否可以在 Vim 中重新加载编译器插件?

[英]Is it possible to reload compiler plugins in Vim?

I am creating a small compiler plugin in Vim and I'm finding very slow to debug it.我正在 Vim 中创建一个小型编译器插件,但我发现调试它的速度很慢。 It seems like there are ways to debug the errorformat but some times I just want to force Vim to reload my compiler plugin that I created in ~/.vim/after/compiler/似乎有一些方法可以调试错误格式,但有时我只想强制 Vim 重新加载我在~/.vim/after/compiler/中创建的编译器插件

It doesn't look like I can just source the file as it fails because of CompilerSet .看起来我不能只获取文件,因为它因为CompilerSet而失败。 Is there any other way of reloading a compiler plugin?还有其他方法可以重新加载编译器插件吗?

Simply running :compiler {name} should reload your full compiler script.只需运行:compiler {name}即可重新加载完整的编译器脚本。

See :help:compiler with the details of how a compiler plug-in is loaded.有关如何加载编译器插件的详细信息,请参阅:help:compiler

An alternative is to source the compiler plug-in file directly.另一种方法是直接获取编译器插件文件。 In order to handle the :CompilerSet command, you can either define the user command yourself before you run the plug-in file, or use a snippet in your plug-in file itself to define it if not defined already.为了处理:CompilerSet命令,您可以在运行插件文件之前自己定义用户命令,或者使用插件文件本身中的片段来定义它(如果尚未定义)。

Many of the compiler plug-ins shipped with Vim include this snippet at the top: Vim 附带的许多编译器插件在顶部包含以下代码段:

if exists(":CompilerSet") != 2      " older Vim always used :setlocal
  command -nargs=* CompilerSet setlocal <args>
endif

So apparently that's all you need...所以显然这就是你所需要的......

But using :compiler {name} each time to fully source it should be a better approach, assuming that's a possibility to you.但是每次都使用:compiler {name}来完全获取它应该是一种更好的方法,假设这对你来说是可能的。

(Tangentially) I find tpope's scriptease plugin to have many benefits when working on a vim plugin (and also when writing answers to vim questions where I have to dig deep into runtime files). (切题地)我发现 tpope 的scriptease插件在处理 vim 插件时有很多好处(以及在编写 vim 问题的答案时,我必须深入研究运行时文件)。

Highlights:强调:

  • :PP is both a pretty-printer and a repl :PP既是漂亮的打印机又是 repl
  • :Runtime helps reload files :Runtime帮助重新加载文件
  • :Breakadd is much smarter :Breakadd更聪明
  • :Vedit and cousins open up files on the runtime path :Vedit和堂兄弟在运行时路径上打开文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM