简体   繁体   English

在vim中查找可执行文件的路径

[英]Find path of an executable in vim

On some machines I'm using an external executable to format text (it's named 'par'). 在某些机器上,我使用外部可执行文件来格式化文本(它名为'par')。 Therefore I'd like to detect if the executable is installed. 因此,我想检测是否安装了可执行文件。

Edit: I just want to detect if the executable is available in my .vimrc itself. 编辑:我只想检测我的.vimrc本身是否有可执行文件。 So I prefer internal functions over external utils like 'which'. 所以我更喜欢内部函数而不是像'which'这样的外部工具。 Prince Goulash's solution is already very helpful and I'm going with it, despite I'd prefer finding the exact path. Prince Goulash的解决方案已经非常有用,我会继续使用它,尽管我更喜欢找到确切的路径。 Thanks. 谢谢。

You can use the vimscript function executable() , which returns 1 if its argument exists and is executable, and 0 otherwise. 您可以使用vimscript函数executable() ,如果其参数存在且可执行,则返回1,否则返回0。 It doesn't return the path of the file, though. 但它不会返回文件的路径。 See help executable for more info. 有关详细信息,请参阅help executable

In linux, I'd use which : 在linux中,我会使用哪个

:!which par

If you want to put it into the file, try this: 如果要将其放入文件中,请尝试以下操作:

:r !which par

Edit: Actually, hash might be the better tool to use. 编辑:实际上, 哈希可能是更好的工具。

in unix... 在unix ...

whereis par

should return a path, if it is executable by the current user 应返回路径,如果它可由当前用户执行

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

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