if has('vim_starting')
set encoding=utf-8
endif
scriptencoding utf-8
if &compatible
set nocompatible
endif
let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end
execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit
" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<CR>'] = cmp.mapping.confirm({ select = true })
},
sources = {
{ name = "buffer", group_index = 1, option = { keyword_pattern = [[\k\+]] } },
-- If nothing else matches, complete words from other buffers
{
name = "buffer",
group_index = 2,
option = {
keyword_pattern = [[\k\+]],
get_bufnrs = function()
return vim.api.nvim_list_bufs()
end
},
},
},
}
EOF
lua << EOF
local capabilities = require('cmp_nvim_lsp').default_capabilities()
require'lspconfig'.cssls.setup {
capabilities = capabilities,
}
EOF
Description
I often have a lot of buffers open, so I don't want to show buffer keywords from all my buffers.
However, I want to fall back to showing keywords from all buffers if there's nothing else to complete. This doesn't work. It seems like any sources after the first one of the same type is just ignored.
Steps to reproduce
Use these sources:
sources = {
{ name = "buffer", group_index = 1, option = { keyword_pattern = [[\k\+]] } },
-- If nothing else matches, complete words from other buffers
{
name = "buffer",
group_index = 2,
option = {
keyword_pattern = [[\k\+]],
get_bufnrs = function()
return vim.api.nvim_list_bufs()
end
},
},
},
Test with:
file1.txt:
VERY
file2.txt:
VERY_LONG_KEYWORD
Place the cursor on a new line in file1.txt and start typing VE, a completion for VERY is suggested. When you keep typing VERY_L then the keyword from file2.txt should be suggested, but it isn't.
Expected behavior
When typing, keywords from the current buffer should be suggested. If the text doesn't match any keywords in the current buffer, keywords from all buffers should be suggested.
FAQ
Announcement
Minimal reproducible full config
Description
I often have a lot of buffers open, so I don't want to show buffer keywords from all my buffers.
However, I want to fall back to showing keywords from all buffers if there's nothing else to complete. This doesn't work. It seems like any sources after the first one of the same type is just ignored.
Steps to reproduce
Use these sources:
Test with:
file1.txt:
file2.txt:
Place the cursor on a new line in file1.txt and start typing
VE
, a completion forVERY
is suggested. When you keep typingVERY_L
then the keyword from file2.txt should be suggested, but it isn't.Expected behavior
When typing, keywords from the current buffer should be suggested. If the text doesn't match any keywords in the current buffer, keywords from all buffers should be suggested.
Actual behavior
Additional context
No response