简体   繁体   English

Vim 命令行模式——如何确认选择?

[英]Vim command line mode - how to confirm selection?

In zsh, if you type ls <Tab> in your home dir, it'll show all non-hidden files in your home, then each <Tab> cycle through the file names.在 zsh 中,如果您在主目录中键入ls <Tab> ,它将显示您家中的所有非隐藏文件,然后每个<Tab>循环遍历文件名。

When the current highlighted filename is what I want, if that item is a dir, I type / to confirm my selection, if it's a file, I use <Space> .当当前突出显示的文件名是我想要的时,如果该项目是一个目录,我输入/来确认我的选择,如果它是一个文件,我使用<Space>

As this post instructs, I have added these two lines in my .vimrc to give vim zsh-like completion.正如这篇文章所指示的,我在我的.vimrc中添加了这两行,以完成 vim zsh 式完成。

set wildmode=longest,list,full
set wildmenu

But when vim is cycling through the options, how can I confirm a selection?但是当 vim 循环选择选项时,我如何确认选择?
Like in my home dir I start vim, and :e + some tabs, when the selection is on my document dir, how can I confirm it? Like in my home dir I start vim, and :e + some tabs, when the selection is on my document dir, how can I confirm it? <Enter> would finish the command, <Esc> or <Cc> cancels it, while / appends a backslash so the command becomes :e document// --not what I want. <Enter>将完成命令, <Esc><Cc>取消它,而/附加一个反斜杠,因此命令变为:e document//不是我想要的。

From the vim documentation (:help wildmenu):从 vim 文档(:help wildmenu):

While the "wildmenu" is active the following keys have special meanings:

[...]
<Down> - in filename/menu name completion: move into a subdirectory or submenu
[...]

So I think that gets at least part of what you're after.所以我认为这至少得到了你所追求的一部分。

Just in case anyone else (like me) ends up here and feel like @Geoff answer doesn't feel really vim-like.以防万一其他人(如我)来到这里并感觉@Geoff 的回答并不像 vim 那样。

I found that Ctrl + D does exactly what OP was asking.我发现Ctrl + D完全符合 OP 的要求。 More information in :help cmdline-completion :help cmdline-completion更多信息

我使用<space>来选择。

cnoremap <expr> <space>  wildmenumode()?"\<space>\<BS>":"\<space>"

Old post but I was looking for the same answer.旧帖子,但我正在寻找相同的答案。 According to :help wildmenu :根据:help wildmenu

CTRL-Y      - accept the currently selected match and stop
              completion.

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

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