Git Product home page Git Product logo

autocomplete.nvim's Introduction

autocomplete.nvim

Very simple and minimal autocompletion for cmdline and buffer using LSP and Tree-sitter with signature help.

Originally I made this just for my dotfiles as I did not needed most of stuff existing plugins provided I had some issues with the ones that were close to what I wanted so as a learning exercise I decided to try and implement it by myself. Then I just extracted the code to separate plugin in case anyone else wanted to use it too. Just a warning, there might be some bugs and as this requires Neovim 0.10+ (e.g nightly), that one can also have bugs by itself.

demo.mp4

Requirements

Requires Neovim Nighly/development version. This version supports stuff like popup menu for completion menu and closing windows properly from cmdline callbacks.

For installation instructions/repository go here

If you want to use Tree-sitter autocompletion (as fallback when you dont have LSP server running) you also need to have nvim-treesitter plugin

Installation

Just use lazy.nvim or :h packages with git submodules or something else I don't care. Read the documentation of whatever you want to use.

Usage

Just require either buffer or cmd module or both and call setup on them.
NOTE: You dont need to provide the configuration, below is just default config, you can just call setup with no arguments for default.

-- LSP signature help
require("autocomplete.signature").setup {
    border = nil, -- Signature help border style
    width = 80, -- Max width of signature window
    height = 25, -- Max height of signature window
    debounce_delay = 100
    keymap = {}, -- Keymap to toggle signature help on or off in insert mode
    -- keymap = { toggle_signature = '<C-Space>' },
}

-- buffer autocompletion with LSP and Tree-sitter
require("autocomplete.buffer").setup {
    entry_mapper = nil, -- Custom completion entry mapper
    debounce_delay = 100
}

-- cmdline autocompletion
require("autocomplete.cmd").setup {
    mappings = {
        accept = '<C-y>',
        reject = '<C-e>',
        complete = '<C-space>',
        next = '<C-n>',
        previous = '<C-p>',
    },
    border = nil, -- Cmdline completion border style
    columns = 5, -- Number of columns per row
    rows = 0.3, -- Number of rows, if < 1 then its fraction of total vim lines, if > 1 then its absolute number
    close_on_done = true, -- Close completion window when done (accept/reject)
    debounce_delay = 100,
}

You also probably want to enable popup in completeopt to show documentation preview:

vim.o.completeopt = 'menuone,noinsert,popup'

And you also ideally want to set the capabilities so Neovim will fetch documentation when resolving completion items:

-- Here we grab default Neovim capabilities and extend them with ones we want on top
local capabilities = vim.tbl_deep_extend('force', 
    vim.lsp.protocol.make_client_capabilities(), 
    require('autocomplete.capabilities'))

-- Now set capabilities on your LSP servers
require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
    capabilities = capabilities
}

If you want to disable <CR> to accept completion (as with autocomplete its very annoying) you can do this:

vim.keymap.set("i", "<CR>", function()
    return vim.fn.pumvisible() ~= 0 and "<C-e><CR>" or "<CR>"
end, { expr = true, replace_keycodes = true })

Similar projects

I used some of this projects as reference and they are also good alternatives:

autocomplete.nvim's People

Contributors

deathbeam avatar github-actions[bot] avatar bassamsdata 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.