简体   繁体   中英

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.

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> .

As this post instructs, I have added these two lines in my .vimrc to give vim zsh-like completion.

set wildmode=longest,list,full
set wildmenu

But when vim is cycling through the options, how can I confirm a selection?
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.

From the vim documentation (: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.

I found that Ctrl + D does exactly what OP was asking. More information in :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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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