Attention: This plugin has been discontinued. It has been superseded by VimSuggest, which offers significant improvements. Please migrate to it.
Key Features • Usage • Requirements • Installation • Configuration • Commands
- Preview candidates for search pattern autocompletion and command autocompletion.
- Switch between normal popup menu and flat menu.
- Autocomplete multiple words during search.
- Fuzzy search.
- All Vim idioms work as expected (ex. 'c', 'y', 'd' with pattern).
- Does not hang or slow down when searching large files or expanding wildcards.
- Search-highlighting, incremental-search, and history recall work as expected.
- Written in Vim9script.
Vim's default keybindings are not altered in any way.
/
or?
to search forward or backward.:
to enter commands.<Tab>
and<Shift-tab>
(or<Ctrl-N>
and<Ctrl-P>
) to select menu items.<Ctrl-E>
to dismiss popup menu.<Enter>
to accept selection.<Esc>
to dismiss search.<Ctrl-C>
to force close popup menu.
Note
For multi-word search, type the separator character (like <Space>
) after the first word to trigger autocompletion for second word. Type \n
at the end of the last word in a line to continue to next line. Setting fuzzy search option disables multi-word search.
Note
For insert-mode autocompletion see Vimcomplete.
- Vim >= 9.0
Install it via vim-plug.
Show instructions
Using vim9 script:
vim9script
plug#begin()
Plug 'girishji/autosuggest.vim'
plug#end()
Using legacy script:
call plug#begin()
Plug 'girishji/autosuggest.vim'
call plug#end()
Install using Vim's built-in package manager.
Show instructions
$ mkdir -p $HOME/.vim/pack/downloads/opt
$ cd $HOME/.vim/pack/downloads/opt
$ git clone https://github.com/girishji/autosuggest.vim
Add the following line to your $HOME/.vimrc file.
packadd autosuggest.vim
Default options are as follows:
vim9script
var options = {
search: {
enable: true, # 'false' will disable search completion
pum: true, # 'false' for flat menu, 'true' for stacked menu
maxheight: 12, # max height of stacked menu in lines
fuzzy: false, # fuzzy completion
alwayson: true, # when 'false' press <tab> to open popup menu
popupattrs: {}, # dictionary of attributes passed to popup window
},
cmd: {
enable: true, # 'false' will disable command completion
pum: true, # 'false' for flat menu, 'true' for stacked menu
fuzzy: false, # fuzzy completion
exclude: [], # patterns to exclude from command completion (use \c for ignorecase)
onspace: [], # show popup menu when cursor is in front of space (ex. :buffer<space>)
alwayson: true, # when 'false' press <tab> to open popup menu
popupattrs: {}, # dictionary of attributes passed to popup window
}
}
Note
The exclude
option mentioned above uses regex pattern match rather than
string comparison. For instance, if you would like to exclude :e
from
autosuggestion but would like to see menu when you type :e<space>
, then use
the following:
exclude: ['^e$'], # exclude ':e' but not ':e<sapce>'
onspace: ['e'], # show menu when 'e:<space>' is typed
Options can be modified using g:AutoSuggestSetup()
. If you are using
vim-plug use the VimEnter
event as
follows.
autocmd VimEnter * g:AutoSuggestSetup(options)
It is also possible to verify if the options are correctly set (debugging purposes only):
echo g:AutoSuggestGetOptions()
The appearance of a popup window is controlled by the highlight groups listed in :h popup-usage
. By default, many of these groups are linked to the Pmenu
highlight groups. You can customize them by configuring the popupattrs
dictionary (see above).
To modify the highlight color of the selected item, adjust the PopupSelected
group, which defaults to PmenuSel
. Additionally, the AutoSuggestSearchMatch
and AutoSuggestSearchMatchSel
groups can be used to configure the highlight for matched text in both regular and selected menu items.
Set ignorecase
and smartcase
using set
command. See :h 'ignorecase'
and :h 'smartcase'
.
If you defined a keymap that puts text on the command line or waits for input, you may find that the command line may get cleared by the popup. This undesirable outcome can be prevented by one of two methods: specify keywords that should be ignored by the autocompletion mechanism, or disable and enable the plugin within the keymap.
For instance, let's say you have a keymap as follows. First command lists buffers and second one chooses.
nnoremap <leader>b :buffers<cr>:buffer<space>
This will not work because the second buffer
command is just text on the
command line. It causes the popup to open and clear the output of previous
buffers
command.
First solution is to simply exclude the word buffer
from autocompletion.
Include this in your options.
var options = {
cmd: {
exclude: ['^buffer']
}
}
Another solution is to disable and enable.
:nnoremap <leader>b :AutoSuggestDisable<cr>:buffers<cr>:let nr = input("Which one: ")<Bar>exe $'buffer {nr}'<bar>AutoSuggestEnable<cr>
You can define some interesting keymappings with the help of this plugin. Here
are two examples. First one will help you open file under current working
directory. Second mapping switches buffers. Type a few letters to narrow the
search and use <tab>
to choose from menu.
nnoremap <leader>f :e<space>**/*<left>
nnoremap <leader>b :buffer<space>
autocmd VimEnter * g:AutoSuggestSetup({ cmd: { onspace: ['buffer'] }})
Care is taken to ensure that responsiveness does not deteriorate when searching large files or expanding wildcards. Large files are searched in batches. Between each search attempt input keystrokes are allowed to be queued into Vim's main loop. Wildcard expansions are first executed in a separate job and aborted after a timeout.
Enable or disable this plugin:
:AutoSuggestEnable
:AutoSuggestDisable
-
Devdocs.vim - browse documentation from devdocs.io.
-
VimBits - curated suite of lightweight Vim plugins.
-
Scope.vim - fuzzy find anything.
-
Vimcomplete - enhances autocompletion in Vim.
Pull requests are welcome.