Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/girishji/autosuggest.vim

Autocompletion for Vim's command-line.
https://github.com/girishji/autosuggest.vim

autocomplete menu vim vim-cmd vim-plugin vim-search

Last synced: about 2 months ago
JSON representation

Autocompletion for Vim's command-line.

Awesome Lists containing this project

README

        

autosuggest.vim

Autocompletion for Vim's Command-line Mode (`/`, `?`, and `:` commands).


Key Features
Usage
Requirements
Installation
Configuration
Commands

![demo](https://gist.githubusercontent.com/girishji/40e35cd669626212a9691140de4bd6e7/raw/f3e69c22e085f1029a048de422ac37a055e5ac80/autosuggest-demo.gif)

## Key Features

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

## Usage

Vim's default keybindings are not altered in any way.

- `/` or `?` to search forward or backward.
- `:` to enter commands.
- `` and `` (or `` and ``) to select menu items.
- `` to dismiss popup menu.
- `` to accept selection.
- `` to dismiss search.
- `` to force close popup menu.

> [!NOTE]
> For multi-word search, type the separator character (like ``) 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](https://github.com/girishji/vimcomplete).

## Requirements

- Vim >= 9.0

## Installation

Install it via [vim-plug](https://github.com/junegunn/vim-plug).

Show instructions



Using vim9 script:

```vim
vim9script
plug#begin()
Plug 'girishji/autosuggest.vim'
plug#end()
```

Using legacy script:

```vim
call plug#begin()
Plug 'girishji/autosuggest.vim'
call plug#end()
```

Install using Vim's built-in package manager.

Show instructions



```bash
$ 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.

```vim
packadd autosuggest.vim
```

## Configuration

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 to open popup menu
},
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)
}
}
```

> [!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`, then use
> the following:
> ```
> exclude: ['^e$'], # exclude ':e' but not ':e'
> onspace: ['e'], # show menu when 'e:' is typed
> ```

Options can be modified using `g:AutoSuggestSetup()`. If you are using
[vim-plug](https://github.com/junegunn/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()
```

### Highlight Groups

The `AS_SearchCompletePrefix` highlight group influences the fragment of a menu item that matches the text being searched. The appearance of the popup menu is determined by Vim's highlight groups `Pmenu`, `PmenuSel`, `PmenuSbar`, and `PmenuThumb`. For command completion, the `WildMenu` group (refer to `:h hl-WildMenu`) can be utilized.

### Case Sensitive Search

Set `ignorecase` and `smartcase` using `set` command. See `:h 'ignorecase'` and
`h 'smartcase'`.

### Key Mapping

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 b :buffers:buffer
```

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 b :AutoSuggestDisable:buffers:let nr = input("Which one: ")exe $'buffer {nr}'AutoSuggestEnable
```

### Find Files and Switch Buffers Quickly

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 `` to choose from menu.

```
nnoremap f :e**/*
nnoremap b :buffer
autocmd VimEnter * g:AutoSuggestSetup({ cmd: { onspace: ['buffer'] }})
```

### Performance

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.

## Commands

Enable or disable this plugin:

- `:AutoSuggestEnable`
- `:AutoSuggestDisable`

## Other Plugins to Enhance Your Workflow

1. [**Devdocs.vim**](https://github.com/girishji/devdocs.vim) - browse documentation from [devdocs.io](https://devdocs.io).

2. [**VimBits**](https://github.com/girishji/vimbits) - curated suite of lightweight Vim plugins.

3. [**Scope.vim**](https://github.com/girishji/scope.vim) - fuzzy find anything.

4. [**Vimcomplete**](https://github.com/girishji/vimcomplete) - enhances autocompletion in Vim.

## Similar Plugins

- [cmp-cmdline](https://github.com/hrsh7th/cmp-cmdline)
- [wilder.nvim](https://github.com/gelguy/wilder.nvim)
- [sherlock](https://github.com/vim-scripts/sherlock.vim)

## Contributing

Pull requests are welcome.