Vim 使用带有Web包别名目录的gf
我的网页包中定义了一个别名Vim 使用带有Web包别名目录的gf,vim,Vim,我的网页包中定义了一个别名common components,它解析为static/js/components。我希望能够使用gf使用别名打开导入的文件(例如通用组件/button/button.jsx)。我的研究为我指明了在.vimrc中使用includeexpr和subfixesadd的方向,如下所示: set includeexpr=substitute(v:fname,'^\\common-components','static/js/components','') set suffix
common components
,它解析为static/js/components
。我希望能够使用gf
使用别名打开导入的文件(例如通用组件/button/button.jsx
)。我的研究为我指明了在.vimrc中使用includeexpr
和subfixesadd
的方向,如下所示:
set includeexpr=substitute(v:fname,'^\\common-components','static/js/components','')
set suffixesadd=.js,.jsx
但是,当将鼠标悬停在路径上时,使用gf
会出现错误:
E65: Illegal back reference
E447: Can't find file "common-components/button/button.jsx" in path
不确定从哪里开始查找,因为我似乎找不到substitute
的函数签名,所以我不确定从哪里开始调试
我使用,并希望能够导入文件,同时也尊重别名。例如,将鼠标悬停在React组件上并点击if
(光标下的导入映射)应使用common components/button/button.jsx导入顶部的文件
set includeexpr=substitute(v:fname,'^common-components','static/js/components','')
应将此转变为:
common-components/button/button
为此:
static/js/components/button/button
然后,Vim应寻找:
static/js/components/button/button.js
static/js/components/button/button.jsx
在:help“path”中的目录中
您的模式中的\\
阻止了替换工作,因此您得到了未更改的v:fname
,Vim找不到它,因为它不存在。您必须在集合中转义空格,或避免它们。感谢您的回复。不幸的是,这个解决方案不起作用。当我找到新编辑的.vimrc时,我得到了未知选项:“^common components”
删除空格应该会有所帮助@你能详细说明一下吗?我没有看到我在上面的任何地方使用空格snippet@Tycholiz查看我的答案的历史记录:初始版本中有空格,这导致了您报告的错误。同时我把它们移走了。