Comments (25)
require'cmp'.setup {
event = {
on_confirm_done = function(entry)
-- do something
end
}
}
I've added the API for it.
from nvim-cmp.
video.mp4
hi i want this feature it is similar to vscode when you select a item by press <cr>
.
if that item kind is a 'function' it will automatic add bracket (
from nvim-cmp.
I'm not sure why, but mapping the <CR> from nvim-autopairs worked.
- ["<cr>"] = cmp.mapping.confirm({
- behavior = cmp.ConfirmBehavior.Replace,
- select = true,
- }),
+require("nvim-autopairs").setup({})
+require("nvim-autopairs.completion.cmp").setup({
+ map_cr = true,
+ map_complete = true,
+})
@windwp Thx!!
from nvim-cmp.
I've fixed it! Thank you.
5cc6c61
from nvim-cmp.
I think you don't need any glue setting.
local npairs = require('nvim-autopairs')
npairs.setup {}
_G.cmp_npairs_cr = function ()
return npairs.autopairs_cr()
end
vim.api.nvim_set_keymap("i", "<cr>", "v:lua.cmp_npairs_cr()", {expr = true, noremap = true})
The above configuration should be worked.
from nvim-cmp.
@uga-rosa
And please set up mapping option with require'cmp'.setup { ... }
. It's specified in README.md
from nvim-cmp.
from nvim-cmp.
My minimal vimrc works as expected.
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 'windwp/nvim-autopairs'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
call plug#end()
PlugInstall | quit
lua <<EOF
local cmp = require'cmp'
cmp.setup {
-- You should change this example to your chosen snippet engine.
snippet = {
expand = function(args)
-- You must install `vim-vsnip` if you set up as same as the following.
vim.fn['vsnip#anonymous'](args.body)
end
},
-- You must set mapping.
mapping = {
['<C-p>'] = cmp.mapping.item.prev(),
['<C-n>'] = cmp.mapping.item.next(),
['<C-d>'] = cmp.mapping.scroll.up(),
['<C-f>'] = cmp.mapping.scroll.down(),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
},
-- You should specify your *installed* sources.
sources = {
{ name = 'buffer' }
},
}
require('nvim-autopairs').setup({
disable_filetype = { "TelescopePrompt" , "vim" },
})
local remap = vim.api.nvim_set_keymap
local npairs = require('nvim-autopairs')
-- skip it, if you use another global object
_G.MUtils = {}
MUtils.completion_confirm=function()
return npairs.autopairs_cr()
end
remap('i' , '<CR>','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true})
EOF
from nvim-cmp.
Hmmm. I can't find any strange settings, but it doesn't work.
I tried many things, but the only thing I could think of as the cause was packer.nvim. It doesn't seem to be a problem here.
from nvim-cmp.
@hrsh7th hi I use this code to auto add ( when the complete item is a function
is there any way i can do a similar thing with ncim-cmp?
from nvim-cmp.
I think it isn't necessary on currently nvim-cmp.
from nvim-cmp.
i can make a PR to make autocmd and export the last confirm item after confirm function is execute
from nvim-cmp.
@windwp What do you want? I think it isn't necessary.
from nvim-cmp.
OK. I've understand.
I think it should be supported in nvim-cmp itself (by user customizing).
require'cmp'.setup {
item = {
custom = function(completion_item)
if completion_item.kind == cmp.lsp.CompletionItemKind.Method or Function then
completion_item.insertText = completion_item.insertText + '($0)'
completion_item.insertTextFormat = cmp.lsp.InsertTextFormat.Snippet
end
return completion_item
end
}
}
But I will add CmpConfirmDone
autocmd.
from nvim-cmp.
ok thank i will checking it
from nvim-cmp.
I create minimal rc.
Can you see if you can reproduce it?
init.lua
local fn = vim.fn
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
end
require'plugins'
vim.cmd([[autocmd BufWritePost plugins.lua source <afile> | PackerCompile]])
lua/plugins.lua
vim.cmd([[packadd packer.nvim]])
require("packer").startup(function()
use("wbthomason/packer.nvim")
use({
"hrsh7th/nvim-cmp",
requires = {
"hrsh7th/cmp-buffer",
},
config = function()
local cmp = require("cmp")
cmp.setup({
mapping = {
["<C-p>"] = cmp.mapping.prev_item(),
["<C-n>"] = cmp.mapping.next_item(),
["<C-e>"] = cmp.mapping.close(),
["<cr>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
},
sources = {
{ name = "buffer" },
},
})
end,
})
use({
"windwp/nvim-autopairs",
config = function()
local npairs = require("nvim-autopairs")
npairs.setup({})
_G.MUtils = _G.MUtils or {}
MUtils.completion_confirm = function()
return npairs.autopairs_cr()
end
vim.api.nvim_set_keymap("i", "<cr>", "v:lua.MUtils.completion_confirm()", { expr = true, noremap = true })
end,
})
end)
from nvim-cmp.
I can't reproduce (Sorry. I don't use packer.nvim so I change it as vim-plug).
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/vim-vsnip'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'windwp/nvim-autopairs'
call plug#end()
PlugInstall | quit
lua <<EOF
-- nvim-cmp
local cmp = require("cmp")
cmp.setup({
mapping = {
["<C-p>"] = cmp.mapping.prev_item(),
["<C-n>"] = cmp.mapping.next_item(),
["<C-e>"] = cmp.mapping.close(),
["<cr>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
},
sources = {
{ name = "buffer" },
},
})
local npairs = require("nvim-autopairs")
npairs.setup({})
_G.MUtils = _G.MUtils or {}
MUtils.completion_confirm = function()
return npairs.autopairs_cr()
end
vim.api.nvim_set_keymap("i", "<cr>", "v:lua.MUtils.completion_confirm()", { expr = true, noremap = true })
EOF
from nvim-cmp.
I was short on words.
I also wrote this using vim-plug and the problem did not occur. So I think it might be a compatibility issue with packer.nvim, and I want you to check it in other environments.
from nvim-cmp.
just tried this. can reproduce with packer.nvim but not vim-plug
from nvim-cmp.
hi i create a new setup function for nvim-cmp
just check readme of nvim-autopairs
i don't use packer but it should working
from nvim-cmp.
Hm... I will try with packer.nvim
from nvim-cmp.
I tried to use packer.nvim with the following config and it works as expected.
local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
end
vim.cmd([[autocmd BufWritePost plugins.lua source <afile> | PackerCompile]])vim.cmd([[packadd packer.nvim]])
require("packer").startup(function()
use("wbthomason/packer.nvim")
use({
"hrsh7th/nvim-cmp",
requires = {
"hrsh7th/cmp-buffer",
},
config = function()
local cmp = require("cmp")
cmp.setup({
mapping = {
["<C-p>"] = cmp.mapping.prev_item(),
["<C-n>"] = cmp.mapping.next_item(),
["<C-e>"] = cmp.mapping.close(),
["<cr>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
},
sources = {
{ name = "buffer" },
},
})
end,
})
use({
"windwp/nvim-autopairs",
config = function()
local npairs = require("nvim-autopairs")
npairs.setup({})
_G.MUtils = _G.MUtils or {}
MUtils.completion_confirm = function()
return npairs.autopairs_cr()
end
vim.api.nvim_set_keymap("i", "<cr>", "v:lua.MUtils.completion_confirm()", { expr = true, noremap = true })
end,
})
end)
from nvim-cmp.
Hm... I still can't reproduce it with lua/plugins.lua
pattern.
-- init.mini.lua
local fn = vim.fn
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
end
require'plugins'
vim.cmd([[autocmd BufWritePost plugins.lua source <afile> | PackerCompile]])
-- lua/plugins.lua
vim.cmd([[packadd packer.nvim]])
require("packer").startup(function()
use("wbthomason/packer.nvim")
use({
"hrsh7th/nvim-cmp",
requires = {
"hrsh7th/cmp-buffer",
},
config = function()
local cmp = require("cmp")
cmp.setup({
mapping = {
["<C-p>"] = cmp.mapping.prev_item(),
["<C-n>"] = cmp.mapping.next_item(),
["<C-e>"] = cmp.mapping.close(),
["<cr>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
},
sources = {
{ name = "buffer" },
},
})
end,
})
use({
"windwp/nvim-autopairs",
config = function()
local npairs = require("nvim-autopairs")
npairs.setup({})
_G.MUtils = _G.MUtils or {}
MUtils.completion_confirm = function()
return npairs.autopairs_cr()
end
vim.api.nvim_set_keymap("i", "<cr>", "v:lua.MUtils.completion_confirm()", { expr = true, noremap = true })
end,
})
end)
from nvim-cmp.
Ah. I found the cause. I will fix it.
from nvim-cmp.
I still have this issue using lsp zero, which depends on nvim cmp.
-- ....
local cmp = require('cmp')
local cmp_select = { behavior = cmp.SelectBehavior.Select }
local cmp_mappings = lsp.defaults.cmp_mappings({
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<CR>'] = cmp.mapping.confirm({ select = true }),
["<C-Space>"] = cmp.mapping.complete(),
})
-- .....
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
local cmp_status_ok, cmp = pcall(require, "cmp")
if not cmp_status_ok then
return
end
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({}))
lsp.setup()
seems to be possible to use based on this guy's setup https://github.com/redxtech/dotfiles/blob/master/.config/nvim/lua/lsp.lua#L70, but i have no clue what is going wrong.
http://0x0.st/o7qA.mp4 video showing error
from nvim-cmp.
Related Issues (20)
- cmp:GHOST_TEXT Invalid buffer id HOT 4
- [Question] Is there any way to highlight the source type to another color? HOT 4
- Neovim LSP autocompletes everything twice.
- nvim-cmp for rust-analyzer not working on kickstart HOT 3
- lua print(require("cmp")) -> ture
- feature request: support labeldetail field HOT 2
- [NEED HELP] What kind of popup is this? It blocks the completion list and I canβt see it. HOT 3
- The wrong suggestion gets confirmed HOT 1
- Feature Request: Use headlines.nvim for Rendering Markdown in Documentation Window
- Parsing error: Error 08:05:18 notify.error ...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/snippet.lua:411: snippet parsing failed. HOT 5
- luarocks package very outdated
- Cmp Menu is occupying unnecessary space HOT 1
- feature-request: allow more control over completion highlight HOT 2
- How to change the completion sources based on line contents HOT 1
- `<C-p>` does not move the cursor up correctly
- Expanding `%` on cmdline keeps percent sign at the beginning of path
- Completion not working HOT 1
- how to make tab compeletion ignore the word that already compeleted HOT 3
- Long startup times HOT 1
- Emmet-ls completion for sass/scss variables fails
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.