Comments (20)
You can control the behaviour via
cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
select option value.
from nvim-cmp.
thank you very much! working now
from nvim-cmp.
Thanks @hrsh7th and @carlitux .. in addition (in the event someone might want this as part of their autopairs setup), i've submitted a PR to nvim-autopairs to address the select=false
scenario that @hrsh7th mentioned earlier in this issue thread: windwp/nvim-autopairs#106
from nvim-cmp.
I wamt to your serup function.
from nvim-cmp.
require("cmp_nvim_lsp").setup({})
local lspkind = require("lspkind")
cmp.register_source("look", require("cmp_look").new())
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
return vim_item
end,
},
mapping = {
['<C-p>'] = cmp.mapping.prev_item(),
['<C-n>'] = cmp.mapping.next_item(),
['<C-d>'] = cmp.mapping.scroll(-4),
['<C-f>'] = cmp.mapping.scroll(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
},
sources = {
{ name = "calc" },
{ name = "buffer" },
{ name = "path" },
-- { name = "look" },
{ name = "luasnip" },
{ name = "nvim_lsp" },
},
})
from nvim-cmp.
I tried and getting this:
from nvim-cmp.
Hm... If you use packer.nvim, Please do the PackerUpdate
and PackerCompile
.
It can't reproduce. Sorry.
from nvim-cmp.
@hrsh7th I will try to debug, I already executed the packer commands
from nvim-cmp.
I can't reproduce it with the following minimal config.
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 !isdirectory(s:plug_dir)
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 'onsails/lspkind-nvim'
Plug 'L3MON4D3/LuaSnip'
call plug#end()
PlugInstall | quit
" Setup global configuration. More on configuration below.
lua << EOF
local lspkind = require("lspkind")
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
return vim_item
end,
},
mapping = {
['<C-p>'] = cmp.mapping.prev_item(),
['<C-n>'] = cmp.mapping.next_item(),
['<C-d>'] = cmp.mapping.scroll(-4),
['<C-f>'] = cmp.mapping.scroll(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
},
sources = {
{ name = "buffer" },
},
})
EOF
Could you please your full config?
from nvim-cmp.
Doing simple debug I found this:
{
["<C-Space>"] = {
action = <function 1>,
modes = { "i" },
<metatable> = {
__call = <function 2>
}
},
["<C-d>"] = {
action = <function 3>,
modes = { "i" },
<metatable> = {
__call = <function 4>
}
},
["<C-e>"] = {
action = <function 5>,
modes = { "i" },
<metatable> = {
__call = <function 6>
}
},
["<C-f>"] = {
action = <function 7>,
modes = { "i" },
<metatable> = {
__call = <function 8>
}
},
["<C-n>"] = {
action = <function 9>,
modes = { "i" },
<metatable> = {
__call = <function 10>
}
},
["<C-p>"] = {
action = <function 11>,
modes = { "i" },
<metatable> = {
__call = <function 12>
}
},
["<CR>"] = {
action = <function 13>,
modes = { "i" }
}
}
where https://github.com/hrsh7th/nvim-cmp/blob/main/lua/cmp/core.lua#L77 needs the value to be a function but it is a table with keys: action
and modes
Edit. as the error is packer/start/nvim-cmp/lua/cmp/core.lua:77: attempt to call a table value
Could you please your full config?
it is big, https://gitlab.com/linkux-it/galaxy
from nvim-cmp.
looks like it is not calling __call
maybe lua version?
NVIM v0.6.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -g -O2 -ffile-prefix-map=/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f/build/config -I/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f/src -I/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f/.deps/usr/include -I/usr/include -I/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f/build/src/nvim/auto -I/build/neovim-VDoCtE/neovim-0.6.0~ubuntu1+git202108161153-5a111c1b0-adeb5640f/build/include
Compiled by buildd@lgw01-amd64-022
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"
Run :checkhealth for more info```
from nvim-cmp.
I tried to use ipairs
https://github.com/hrsh7th/nvim-cmp/blob/main/lua/cmp/core.lua#L75 but freeze neovim sometimes and others do nothing
from nvim-cmp.
The config.get().mapping
is dict (not an array). So it should be applied pairs
not ipairs
.
Hm... I saw your configuration files but I hadn't found anything.
Sorry for annoying but I please you to debug the below steps.
- Create minimal vimrc
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 !isdirectory(s:plug_dir)
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 'onsails/lspkind-nvim'
Plug 'L3MON4D3/LuaSnip'
call plug#end()
PlugInstall | quit
" Setup global configuration. More on configuration below.
lua << EOF
local lspkind = require("lspkind")
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
return vim_item
end,
},
mapping = {
['<C-p>'] = cmp.mapping.prev_item(),
['<C-n>'] = cmp.mapping.next_item(),
['<C-d>'] = cmp.mapping.scroll(-4),
['<C-f>'] = cmp.mapping.scroll(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = false,
})
},
sources = {
{ name = "buffer" },
},
})
EOF
-
Use this vimrc
nvim -u /path/to/minimal_vimrc
-
Check the problem.
from nvim-cmp.
After many tests, I found the issue comes with nvim-autopairs. When cmp.setup
is called twice the error appears. https://github.com/windwp/nvim-autopairs/blob/master/lua/nvim-autopairs/completion/cmp.lua
I replicated with calling twice the setup
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 !isdirectory(s:plug_dir)
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 'onsails/lspkind-nvim'
Plug 'L3MON4D3/LuaSnip'
Plug 'windwp/nvim-autopairs'
call plug#end()
PlugInstall | quit
" Setup global configuration. More on configuration below.
lua << EOF
local lspkind = require("lspkind")
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
return vim_item
end,
},
mapping = {
['<C-p>'] = cmp.mapping.prev_item(),
['<C-n>'] = cmp.mapping.next_item(),
['<C-d>'] = cmp.mapping.scroll(-4),
['<C-f>'] = cmp.mapping.scroll(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = false,
})
},
sources = {
{ name = "buffer" },
},
})
cmp.setup({
mapping = {
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = false,
})
},
})
EOF
from nvim-cmp.
@carlitux good day Luis! I'm hoping I haven't missed a detail here, I'm trying to understand why/where you were calling require('cmp').setup() twice; in other words, aside from the example above where you found the bug, why were you calling it twice originally? I'm having a semi-similar issue in that i have no pum items selected in cmp, and if i hit enter, it automatically selects the first item.
from nvim-cmp.
@carlitux Thank you very much for your effort!
I will investigate and fix.
@megalithic You can specify select = false
to your confirm mapping option.
from nvim-cmp.
@megalithic already I don't directly. I use https://github.com/windwp/nvim-autopairs and the plugin does with the config for auto-pairs says:
-- you need setup cmp first put this after cmp.setup()
require("nvim-autopairs.completion.cmp").setup({
map_cr = true, -- map <CR> on insert mode
map_complete = true, -- it will auto insert `(` after select function or method item
})
from nvim-cmp.
@carlitux same here, i tried @hrsh7th's suggestion and that sort of worked, but i wonder if it messes with the autopairs plugin mapping that you defined above.
from nvim-cmp.
@carlitux @megalithic I've fixed the duplicate setup calls.
Could you try with latest nvim-cmp?
from nvim-cmp.
If this issue has fixed. feel free to close it.
from nvim-cmp.
Related Issues (20)
- Completion tips are returned in a different order from the `lsp` service.
- Custom Entries Error after 'get-selected' api HOT 8
- Navigation through code completion does not work anymore HOT 10
- cmp.select_next_item() gets error "attempt to perform arithmetic on local 'cursor' HOT 5
- When attempting to navigate suggestion list getting E5108 Error executing lua: .../custom_entries_view.lua:328: attempt to perform arithmetic on local 'cursor' (a nil value) HOT 3
- GLFW_PROFILE doesn't match GLFW_OPENGL_PROFILE but it does when we write GLFW_OP first HOT 1
- Update "Advanced techniques" in the Wiki HOT 1
- Improperly sized windows HOT 1
- Diagnostics window always opens from behind HOT 3
- Feature Request: complete on close HOT 3
- [Question] How would I fetch the current word that nvim cmp is completing against externally?
- preselection not working in command mode HOT 3
- Key mapping to select first snippet completion
- Disable this plugin for floating windows HOT 4
- Snippets and LSP suggestion are both inserted
- double quotes(quotes, etc) ignored by ghost text HOT 1
- Don't rely on `after/plugin` for registering sources HOT 1
- Strange bug with Svelte 5 emmet expansion - VS Code works fine
- Option to show the completion window above the cursor HOT 2
- Error "Vim:E976: Using a Blob as a String" when trying to type "snippet" word with nvim-cmp and LuaSnip HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvim-cmp.