Vim 文件路径搜索算法

Vim File Path Search Algorithm

TLDR。如何将 vim path/file 名称搜索算法从循环自动完成更改为增量自动完成。 (就像在 ubuntu 终端中自动完成文件路径时一样)。

在vim中打开新文件进行编辑时,例如使用:vsp:tabetab键预测下一部分时使用的算法目标文件的 path/file 有不方便的行为,我想更改。

例如,我有一个包含三个文件的目录:

/one.txt
/onetwo.txt
/onetwothree.txt

当尝试从在同一目录中打开的 vim 实例打开 onetwothree.txt 时,我会输入 :tabe o 然后按 tab 键和 vim 将自动完成文件 name/path,到 :tabe one.txt。然后,我必须再次按 tab 将自动完成更改为 :tabe onetwo.txt,然后第三次再次按 :tabe onetwothree.txt,然后再按 enter 打开文件。 (算法 1)tab 算法具有逐个遍历完整 path/file 名称的行为。

在 ubuntu 终端中,搜索行为要好得多,并且可以输入 :tabe o 并按 tab 只会部分自动完成给你 :tabe one。然后再次输入 t 然后再输入 tab 将自动完成从 :tabe onet:tabe onetwo 然后再次按 ttab 将从 [=33] 自动完成=] 到 :tabe onetwothree.txt。 (算法 2)tab 算法具有部分完成 path/file 名称的行为。

对于第一种算法,在处理大量文件时,按 tab 逐个循环遍历完整 path/file 名称的行为可能不方便。在 ubuntu 终端使用的第二种算法中 tab 自动完成具有部分完成 path/file 名称的行为,并允许快速准确地完成路径。

我意识到在这个简单的示例中,使用第二种算法需要多按两次按键,但在复杂的示例中,许多文件循环遍历每个选项是很痛苦的。

如何更改文件路径搜索算法? .vimrc中是否有指定的设置?

来自 :h cmdline-completion

If you like tcsh's autolist completion, you can use this mapping: :cnoremap X (Where X is the command key to use, is CTRL-L and is CTRL-D) This will find the longest match and then list all matching files.

If you like tcsh's autolist completion, you can use the 'wildmode' option to emulate it. For example, this mimics autolist=ambiguous: :set wildmode=longest,list This will find the longest match with the first 'wildchar', then list all matching files with the next.

所以要么在命令模式下映射<c-l><c-d>,要么将wildmode改编为longest,list

您需要启用 :help 'wildmenu':

set wildmenu

并使用 :help 'wildmode' 调整其行为:

" just an example
set wildmode=longest,list