Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make $(VIM_FILEDIR) valid in nofile buffer #11

Closed
voldikss opened this issue Mar 2, 2020 · 3 comments
Closed

Make $(VIM_FILEDIR) valid in nofile buffer #11

voldikss opened this issue Mar 2, 2020 · 3 comments

Comments

@voldikss
Copy link

voldikss commented Mar 2, 2020

elseif expand('%:p') == ''
for name in disable
for mode in ['$(VIM_', '$(WSL_']
let macro = mode . name . ')'
if stridx(a:command, macro) >= 0
let t = 'macro ' . macro . ' is empty'
call s:warning(t . ' in current buffer')
return 3
elseif stridx(a:cwd, macro) >= 0
let t = 'macro ' . macro . ' is empty'
call s:warning(t . ' in current buffer')
return 4
endif
endfor
endfor
endif

问题:

打开一个 buftype'nofile' 的 buffer,如果执行的命令里面带有 $(VIM_FILEDIR),会报错 Warning: macro $(VIM_FILEDIR) is empty in current buffer.

原因

对于 buftype'nofile' 的 buffer, expand("%:p") 为空字符串,但是 expand("%:p:h") 却返回该缓冲区所在的文件夹路径且不为空,并且在同样的 buffer 里面, $(VIM_FILEDIR) 这个宏在 asyncrun.vim 里也工作正常。

因此可不可以将 $(VIM_FILEDIR) 排除在 disable 之外呢?

@skywind3000
Copy link
Owner

skywind3000 commented Mar 2, 2020

只是 asyncrun 没有做这个检测,就有人用错过,这个东西我想过,nofile 的 buffer 居然有 FILEDIR,道理上说不通,而你在 nofile 的 buffer 里运行 echo expand("%:p") 其实显示的是 Vim 的当前目录 :pwd 返回那个,因为 % 是空字符串,对空字符串求绝对路径,vim 就给了一个当前路径。

并不是真正意义上的 file dir,既然如此你就用 $(VIM_CWD) 就行了嘛,其实就是不写 cwd= 字段。

所以 nofile 之类的 buffer,一般也就运行一些和项目以及当前路径相关的 task.

@voldikss
Copy link
Author

voldikss commented Mar 2, 2020

OK, 已用 $(VIM_CWD) 代替了

@voldikss voldikss closed this as completed Mar 2, 2020
@skywind3000
Copy link
Owner

恩,有一天vim可能真的要靠cd 路径来模拟vscode的open folder 做项目管理这事情。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants