设置运行时路径,从 vim 中的表达式添加目录?
Inn ~/script.vim
,我有:
set runtimepath+=string(substitute(expand("%:p"), 'script\.vim', '', 'g'))
我在 .bashrc
中有一个别名:
alias vimscript="vim -S ~/script.vim"
运行 string(substitute(expand("%:p"), ' script\.vim', '', 'g'))
按预期工作。
问题是,当在设置的运行时路径表达式中使用它时,当我在调用 script.vim
的终端中调用 vimscript
时,它不起作用。当我在 vimscript 调用后在 vim 中运行 set rtp
来检查运行时路径时,未显示所需的附加字符串(但其他字符串都在那里)。
Inn ~/script.vim
, I have:
set runtimepath+=string(substitute(expand("%:p"), 'script\.vim', '', 'g'))
I have an alias in .bashrc
:
alias vimscript="vim -S ~/script.vim"
Running string(substitute(expand("%:p"), 'script\.vim', '', 'g'))
works as intended.
The problem is when using it in the set runtimepath expression, it doesn't work when I call vimscript
in terminal which calls script.vim
. When I run set rtp
in vim after being called by vimscript to check the runtimepath, the desired appended string isn't showed (but the other ones are there).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对 @Laurence Gonsalves 的回答做了一些补充:
还有“concat and allocate”运算符:
.=
,所以可以重写为
Code
会将
,'/some/path'
附加到 &runtimepath,而您可能需要,/some/path
。我猜您想将脚本的路径附加到运行时路径。如果这是真的,那么你的代码应该写成
在脚本内,或者
来自当前编辑会话(假设您正在当前缓冲区中编辑脚本)。
I have some additions to @Laurence Gonsalves answer:
There is also «concat and assign» operator:
.=
, socan be rewritten as
Code
will append
,'/some/path'
to &runtimepath, while you probably need,/some/path
.I guess that you want to append path to your script to runtimepath. If it is true, then your code should be written as
inside a script, or
from current editing session (assuming that you are editing your script in the current buffer).
set
命令的右侧位置不是表达式,而是文字字符串。您可以使用
let
并在选项名称前添加&
来操作选项(set
集的事物)。例如:要使用
let
附加到runtimepath
,您可以执行以下操作:(.
是字符串连接运算符。)The right hand site of a
set
command is not an expression, it's a literal string.You can manipulate options (the things
set
sets) by usinglet
and prefixing the option name with an&
. eg:To append to
runtimepath
with alet
you can do something like:(The
.
is the string concatenation operator.)到 2022 年,我使用了这个:
您也可以使用普通的 vim 变量或其他任何变量。
by 2022 i used this:
You can use a plain vim variable or whatever else just as well.