Code Monkey home page Code Monkey logo

autosuggest.vim's Introduction

autosuggest.vim

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

Key FeaturesUsageRequirementsInstallationConfigurationCommands

demo

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

Requirements

  • Vim >= 9.0

Installation

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

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 <tab> 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<space>)
    }
}

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()

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

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

nnoremap <leader>f :e<space>**/*<left>
nnoremap <leader>b :buffer<space>
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 - browse documentation from devdocs.io.

  2. easyjump.vim - makes code navigation a breeze.

  3. fFtT.vim - accurately target words in a line.

  4. scope.vim - fuzzy find anything.

  5. vimcomplete - enhances autocompletion in Vim.

Similar Plugins

Contributing

Pull requests are welcome.

autosuggest.vim's People

Contributors

girishji avatar kwbr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.