vim能否设置相对于其当前工作目录的路径?
我使用:find命令在vim能否设置相对于其当前工作目录的路径?,vim,Vim,我使用:find命令在vim中查找文件。我的路径设置如下: set path=$PWD/** 在我使用:Explore和c映射来更新CWD之前,这一切都很有效,此时PWD和CWD不再相同。每次目录更改后,我需要再次设置路径。有人能解决这个问题吗 附言 不允许使用插件=p您可以使用以下命令将'path'选项更新到CWD let &path = getcwd() . '/**' 不幸的是,没有目录更改要挂接到的事件。你可以: 使用:autocmd FileType netrw nnorem
vim
中查找文件。我的路径设置如下:
set path=$PWD/**
在我使用:Explore
和c
映射来更新CWD之前,这一切都很有效,此时PWD和CWD不再相同。每次目录更改后,我需要再次设置路径。有人能解决这个问题吗
附言
不允许使用插件=p您可以使用以下命令将
'path'
选项更新到CWD
let &path = getcwd() . '/**'
不幸的是,没有目录更改要挂接到的事件。你可以:
:autocmd FileType netrw nnoremap c…
我想您需要设置
autochdir
:
'autochdir' 'acd' boolean (default off)
global
{not in Vi}
{only available when compiled with it, use
exists("+autochdir") to check}
When on, Vim will change the current working directory whenever you
open a file, switch buffers, delete a buffer or open/close a window.
It will change to the directory containing the file which was opened
or selected.
This option is provided for backward compatibility with the Vim
released with Sun ONE Studio 4 Enterprise Edition.
Note: When this option is on some plugins may not work.
但是,如果您使用
netrw
或sensitive
例如,这是一个错误。netrw的c
用于将Vim的当前目录更改为netrw中的“浏览目录”:它类似于:cd/path/to/some/directory
。如果您不希望Vim的当前目录发生更改,那么首先为什么要使用c
?@romainl我确实希望cwd发生更改,但我也希望路径发生更改。在我的配置中,路径应该基于cwd。我真正需要的是一个每次cwd改变时都被调用的函数。这个函数将更新我的路径,就像Ingo Karkat的例子一样。然后你只需要设置路径=**
,它将始终相对于当前目录:在/path/a
中启动vim,:find
将在/path/a/**
中查找文件<代码>:cd/path/b,:find
将在/path/b/**
中查找文件。如果要保留$PWD
,可以执行设置路径=$PWD,**
<代码>设置路径=**是我使用的,顺便说一下。实际上,我最终使用了w/set path=**并使用了Command-T插件