There is some way to "extend" autocomplete functionality (like that one supplied by SuperTab plugin) to be used in command line mode so I would autocomplete when searching a text with / command?


When editing a text, in INSERT mode, I use now superTab plugin, so hitting TAB, a menu appear with possible completions items.

I'm looking for a similar feature when searching or editing in command mode (:command) and/or in serach mode (/searchedtext), with autocompletion, retrieving from file text words (ore previous commands!).

E.g. if I have the word validate_first and validate_firstname inside the file, I would like to have an autocompletion menu when hitting /validate, with items:

  • validate_first
  • validate_firstname

enter image description here

  • Could you add an example of what you currently do? And what you would like it to do? – StandardEyre Apr 6 '17 at 17:52
  • question updated; more clear now? :) – Giorgio Robino Apr 6 '17 at 19:55
  • perhaps the searchComplete plugin is what you are looking for? – Christian Brabandt Jan 29 '20 at 7:06
  • It seems to me not working. What's he supposed to do searchCompleted? I do not see any behavior change when using Tab or /. Nothing happens BTW I'm using vim v.8.0 – Giorgio Robino Jan 29 '20 at 12:50

Use Ctrlf from cmdline or open cmdline by prefixing your command with q (e.g., q/) to open the cmdline window, which is a buffer for entering Ex commands. From here, you should be able to use your completion mappings.

:help cmdline-window

You could map a command to open the window when you try to do completion in cmdline:

cmap <Tab> <C-f>a<Tab>

I'm intentionally using cmap instead of cnoremap to allow <Tab> to invoke your completion plugin.

If you use <Tab>, you should also change 'wildchar' so you can still access the incredibly useful wildmenu. See :help wildmenu

If you want completion but your current system doesn't support cmdline-window (or you don't don't want to use it), you can use vim's has built-in vim completion: Ctrlx Ctrlv for vim completion and Ctrln for ins-completion. You can differentiate / from : cmdline with getcmdtype():

cnoremap <expr> <Tab> getcmdtype() == ':' ? '<C-f>A<C-x><C-v>' : '<C-f>A<C-n>'
  • Upvoted, thanks. See also: reddit.com/r/vim/comments/euaocz/… I'm now fine with cnoremap <Tab> <C-F>A<C-N> – Giorgio Robino Jan 30 '20 at 8:29
  • 1
    @GiorgioRobino: If that works for you, then you might want to try my vim completion/ins-completion edit for better completion on vim commands. – idbrii Jan 31 '20 at 21:58

I do not provide an autocompletion solution, but a way of filling your history with terms and then cycling through the terms:

Previous commands can be retrieved with the :his[tory] command

Previous searches can be retrieved with the :his[tory] / command

If you have incsearch enabled, you can search for (e.g.) /valid which will take you to the first match (perhaps validate_firstname). Pressing CTRL-L will add one character from after the current match to the command line. This is not the same as autocomplete with TAB but it does complete the search term.

You can then use :his / to find and repeat previous searches.

Once you have /validate_firstname and /validate in the search history, you can type /val followed by the <Up> and <Down> cursor keys to cycle through the search history.


I answer myself to my old question, sharing a solution partially satisfying to myself (just to reciprocate people answers):

  1. searches autocompletion

    I use plugin:

    Plug 'vim-scripts/CmdlineComplete'

    quoting from: https://github.com/vim-scripts/CmdlineComplete :

When editing the command-line ( : / etc.),

press Ctrl-P or Ctrl-N to complete the word before the cursor, using keywords in the current file.

E.g: you want to search for elephant in the buffer, just type /ele and press Ctrl-P. So long as elephant is in the buffer, you will get ele completed into elephant.

  1. Command line commands history (not a real autocompletion)

    I just use Up-Arrow and Down-Arrow to retrieve recent commands history


Here is a plugin-less solution that I personally use and think works very well:

set wildcharm=<C-z>
cnoremap <expr> <Tab>   getcmdtype() =~ '[\/?]' ? "<C-f>i<C-n>" : "<C-z>"

It makes <Tab> trigger Ctrl-f, enter insert mode, and start vim builtin completion if in search mode. Otherwise, it triggers completion like usual.

This does not prevent Ctrl-z from working in normal mode.

wildcharm is a bit weird but it allows wildmenu tab completion in mappings/macros : https://vimhelp.org/options.txt.html#%27wildcharm%27

  • 1
    wildcharm is specifically for use in mappings/macros. – D. Ben Knoble Apr 13 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.