lukas-reineke / cmp-under-comparator

nvim-cmp comparator function for completion items that start with one or more underlines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cmp-under-comparator

A tiny function for nvim-cmp to better sort completion items that start with one or more underlines.

In most languages, especially Python, items that start with one or more underlines should be at the end of the completion suggestion.

Before After

Install

Use your favourite plugin manager to install.

Example with Packer

wbthomason/packer.nvim

-- init.lua
require("packer").startup(
    function()
        use "lukas-reineke/cmp-under-comparator"
    end
)

Example with Plug

junegunn/vim-plug

" init.vim
call plug#begin('~/.vim/plugged')
Plug 'lukas-reineke/cmp-under-comparator'
call plug#end()

Setup

Add the under function to the list of comparators in the cmp setup function.

local cmp = require "cmp"
cmp.setup {
    -- ... rest of your setup ...

    sorting = {
        comparators = {
            cmp.config.compare.offset,
            cmp.config.compare.exact,
            cmp.config.compare.score,
            require "cmp-under-comparator".under,
            cmp.config.compare.kind,
            cmp.config.compare.sort_text,
            cmp.config.compare.length,
            cmp.config.compare.order,
        },
    },
}

About

nvim-cmp comparator function for completion items that start with one or more underlines

License:MIT License


Languages

Language:Lua 100.0%