简体   繁体   English

命令模式下的vim路径补全

[英]vim path completion in command mode

In vim, If you hit :e <tab><tab> , vim complete some path.在 vim 中,如果你点击:e <tab><tab> ,vim 会完成一些路径。

However, I want to open a/b/c/d.cpp , I stroke :e <tab><tab> and find AA .但是,我想打开a/b/c/d.cpp ,我中风:e <tab><tab>并找到AA

I want to find subdirectory of AA .我想找到AA子目录。 Alternatively, I hit / key.或者,我按/键。

example :e AA//BB//CC//DD.cpp示例:e AA//BB//CC//DD.cpp

Are there another good way?还有别的好办法吗? In summary, I want to know complete path for subdirectory in command :e .总之,我想知道命令:e子目录的完整路径。

Command-line completion lets you use wildcards.命令行完成允许您使用通配符。

The basic * means "any character":基本的*表示“任何字符”:

:e *<Tab>          " similar to plain <Tab>
:e foo*<Tab>       " completes only files starting with 'foo'

The fancier ** means "any subdirectory":更高级的**表示“任何子目录”:

:e **/<Tab>        " completes every file under every subdirectory
                   " of the current working directory
:e **/*foo<Tab>    " completes every file ending with 'foo' under every subdirectory
                   " of the current working directory

See :help file-searching .请参阅:help file-searching

By the way, it's "command-line mode".顺便说一下,它是“命令行模式”。 "Command mode" is just another name for "normal mode". “命令模式”只是“正常模式”的另一个名称。

This answer is based on the assumption you want the path for picking out the correct file for editing.这个答案是基于你想要选择正确文件进行编辑的路径的假设。

May I suggest to use :find after setting the path properly.我可以建议在正确设置路径后使用:find This will save extra lot of typing.这将节省额外的大量打字。

You can start by setting :set path+=** (this will search sub-dirs as well).您可以从设置:set path+=** (这也将搜索子目录)开始。 Now you can simply do现在你可以简单地做

:find d.cpp

vim will do the rest for you. vim 将为您完成剩下的工作。 It will find out the path to d.cpp and open it.它会找出d.cpp的路径并打开它。 What is nice about it is it allows to use wildcard, for example, as :find d.* or :find *.cpp .它的优点在于它允许使用通配符,例如:find d.*:find *.cpp

If you don't want to use find and continue with edit , May be it will be useful to :set wildmenu .如果您不想使用find并继续使用edit ,那么:set wildmenu可能会很有用。 This will show all available options that you can iterate with tab这将显示您可以使用选项卡迭代的所有可用选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM