I'm currently interested in the Language Server Protocol and how to implement it in Vim/Neovim.
hrsh7th / cmp-cmdline Goto Github PK
View Code? Open in Web Editor NEWnvim-cmp source for vim's cmdline
License: MIT License
nvim-cmp source for vim's cmdline
License: MIT License
I'm currently interested in the Language Server Protocol and how to implement it in Vim/Neovim.
I'm trying to substitute \(
by using the following command
:s/\\(/<something>
But, in the same moment I write the left parent (
, it shows the error "\( sin complemento", which in English would be something like "not pair found for \(" or "no complement for \(" , which seems to suggest that things are not being escaped properly at some point or maybe they are being escaped twice.
Here's the full traceback:
Error executing vim.schedule lua callback: Vim:E54: \( sin complemento
stack traceback:
[C]: in function 'getcompletion'
...e/pack/packer/start/cmp-cmdline/lua/cmp_cmdline/init.lua:64: in function 'exec'
...e/pack/packer/start/cmp-cmdline/lua/cmpcmdline/init.lua:115: in function 'complete'
.../re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:288: in function 'complete'
.../re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:170: in function 'autoindent'
.../re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:162: in function 'on_change'
.../re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/init.lua:301: in function 'callback'
.../site/pack/packer/start/nvim-cmp/lua/cmp/utils/async.lua:122: in function <.../site/pack/packer/start/nvim-cmp/lua/cmp/utils/async.lua:120>
Right now, if you start typing :set no
, there are no suggestions for the no
-prefixed versions of options, such as nonumber
.
Hi!
First of all thank you very much for your work with cmp! I would send you a merge request fixing this, but I've been reading the code and don't understand how it works :((
The issue I'm having is that completion with :help <query>
works perfectly but it doesn't work at all with :vert help <query>
. I guess vert
could be added as a modifier prefix so that it doesn't affect the rest of the sentence or something like that?
Again, thank you very much for your work!
Not sure if this is problem with Neovim's own getcompletion()
function or the way this plugin is using it, but it starts throwing errors when I set a global variable whose key is not a string.
Setup cmp-cmdline completion.
Execute:
:lua _G[{}] = true
Then start typing another lua command from the command line. I get the following error:
Error executing vim.schedule lua callback: Vim:Error executing vim._expand_pat: attempt to compare table with string
stack traceback:
[C]: in function 'sort'
vim/_editor.lua: in function <vim/_editor.lua:0>
[C]: in function 'getcompletion'
...e/pack/packer/start/cmp-cmdline/lua/cmp_cmdline/init.lua:68: in function 'exec'
...e/pack/packer/start/cmp-cmdline/lua/cmp_cmdline/init.lua:115: in function 'complete'
.../nvim/site/pack/packer/start/nvim-cmp/lua/cmp/source.lua:296: in function 'complete'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:288: in function 'complete'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:170: in function 'autoindent'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:162: in function 'on_change'
...re/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/init.lua:301: in function 'callback'
.../site/pack/packer/start/nvim-cmp/lua/cmp/utils/async.lua:122: in function <.../site/pack/packer/start/nvim-cmp/lua/cmp/utils/async.lua:120>
I am using neovim with the latest nightly.
I have configured cmp-cmdline as :
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
But I find that when I try to use :find
it freezes. It doesn't when I remove cmp-cmdline and use the normal nvim :find
.
This is issue doesn't happen with any other commands that I have used till now.
I have the following set path+='.,**'
as well in my nvim config to enable :find
to search my project dir
Using :set <partialsearch>
gives setting names as completion options.
Would it be possible to also add the current value as a 'preview', basically whatever :set name?
would tell you.
Hello,
I didn't manage to use the completion only for the search. Is it possible?
With the following config, the "default nvim completion" gets disabled after the first search.
Thanks,
Minimal config (nvim 0.7.0):
call plug#begin(stdpath('data') . '/plugged')
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
" For vsnip users.
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
" For luasnip users.
" Plug 'L3MON4D3/LuaSnip'
" Plug 'saadparwaiz1/cmp_luasnip'
" For ultisnips users.
" Plug 'SirVer/ultisnips'
" Plug 'quangnguyen30192/cmp-nvim-ultisnips'
" For snippy users.
" Plug 'dcampos/nvim-snippy'
" Plug 'dcampos/cmp-snippy'
call plug#end()
set completeopt=menu,menuone,noselect
lua <<EOF
-- Setup nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
EOF
:lua print(require('cmp').setup.cmdline)
return a nil too.
cmp-cmdline installed.
-- cmp
use 'hrsh7th/nvim-cmp'
use 'hrsh7th/cmp-vsnip'
use 'hrsh7th/cmp-nvim-lsp'
use 'hrsh7th/cmp-buffer'
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-calc'
use 'hrsh7th/cmp-emoji'
use 'hrsh7th/cmp-cmdline'
config:
local cmp = require'cmp'
...
cmp.setup.cmdline(':', {
sources = {
{ name = 'cmdline' }
}
})
cmp.setup({
...
})
Disclaimer: I'm not super familiar with lua or vimscript or the inner workings of vim. I just use vim a lot.
I recently setup neovim with nvim-cmp
(love it! great work!). However, when I enable cmp-cmdline
I can no longer exit vim with :wqa
. I get the following error:
E141: No file name for buffer nn
Then I essentially have to :q!
everything individually until I hit the last buffer which appears to be the options listed for cmp-cmdline
.
I wanted to guess that the buffer wasn't set to nofile
, but I cannot find where that would even happen. Is very possible its outside this plugin completely. However, when I disable this plugin I have no problem.
nvim-cmp
using the recommended configuration here: https://github.com/hrsh7th/nvim-cmp:vs
or :spl
):wqa
(or :qa
or :qa!
)E141: No file name for buffer 2
is shown
Vim would exit
$ vim --version
NVIM v0.7.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -g -O2 -ffile-prefix-map=/build/neovim-TaFwuh/neovim-0.7.0~ubuntu1+git202203110047-6170574d2-dd05b3569=. -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 -DNVIM_TS_HAS_SET_ALLOCATOR -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-TaFwuh/neovim-0.7.0~ubuntu1+git202203110047-6170574d2-dd05b3569/build/config -I/build/neovim-TaFwuh/neovim-0.7.0~ubuntu1+git202203110047-6170574d2-dd05b3569/src -I/build/neovim-TaFwuh/neovim-0.7.0~ubuntu1+git202203110047-6170574d2-dd05b3569/.deps/usr/include -I/usr/include -I/build/neovim-TaFwuh/neovim-0.7.0~ubuntu1+git202203110047-6170574d2-dd05b3569/build/src/nvim/auto -I/build/neovim-TaFwuh/neovim-0.7.0~ubuntu1+git202203110047-6170574d2-dd05b3569/build/include
Compiled by buildd@lcy02-amd64-015
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
Given:
function! CompleteThis(A,L,P) abort
[...]
endfunction
command! -nargs=1 -complete=custom,CompleteThis RestoreThing call Something()
when cmp-cmdline
is configured like so:
cmp.setup.cmdline(':', {
sources = {
{ name = 'cmdline', keyword_length = 2 },
{ name = 'nvim_lua' },
{ name = 'path' },
},
})
The custom completion function fails to run. The reason appears to be this code in cmp-cmdline
. The regex processing ends up mangling the command name (in this specific instance it is this regex that causes the problem).
If I comment out the code linked above everything works as expected. if I comment out the referenced regex everything works as expected. At least with my configuration, if I change the name of the command to ResToreThing
or RestOreThing
everything works as expected.
Using asterisk sign in cmd cause variety of invalid behaviour:
find ~/project/**/asdf.lua
Of course, wildcards are redundant with this plugin, but they shouldn't cause errors when people use them because of muscle memory.
random document:
hello everyone
goodbye
hello nobody
:sort /he
the screen starts to highlight hello but I get no autocompletion
:sort /hello/
correctly sorts by the string hello
cmp.setup {
sources = {
{ name = 'nvim_lsp' },
{ name = 'nvim_lsp_signature_help' },
{ name = 'path' },
{ name = 'buffer', keyword_length = 4 },
},
}
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer', keyword_length = 4 },
},
})
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' },
}, {
{ name = 'cmdline' },
}),
})
According to docs following setup
cmdline => group_index = 1
cmdline_history => 2
Then if cmdline
outputs any results, then cmdline_history
results should get ignored. But it does not seem to work in cmp-cmdline. My setup:
cmp.setup.cmdline(":", {
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind] .. " " .. vim_item.kind
vim_item.abbr = vim.fn.strcharpart(vim_item.abbr, 0, 50) -- hack to clamp cmp-cmdline-history len
vim_item.menu = ({
cmdline_history = "[HIST]",
cmdline = "[CMD]",
fuzzy_path = "[PATH]",
buffer = "[BUFF]",
})[entry.source.name]
return vim_item
end,
},
sources = cmp.config.sources {
{ name = "cmdline_history", priority = 2, group_index=2 },
{ name = "cmdline", priority = 2, group_index=1 },
{ name = "fuzzy_path", priority = 1, group_index=2 }, -- from tzacher
{ name = "buffer", priority = 1, group_index=2 },
},
})
Then I try to enter :
:PackerSync -> and cmp shows cmd_history
elements first, then cmdline
results.
Expected:
cmdline
result first, no cmd_histoyr
since it is group 2
When running :edit with the setup specified in the README initially everything works as expected with all relative paths popping up. However if a directory is accepted with cmp.complete() and the cursor is moved all the way to the right then no new completions will be offered for the next part.
EX (▇ is cursor position):
:edit ▇
works well with proper completions autosuggested
:edit arbitraryDirectory/▇
does not result in any autosuggestions
A workaround is to delete the trailing slash with one backspace then retype it resulting in autosuggestions working again for only the segment.
I'm using <space>
as the <leader>
.
Reproduce
when typing :map leader
or :map space
or :map <leader>
i get 0 completions, even though i have a lot of mappings starting with leader and e.g. :map <leader>g<cr>
gives me output about these mappings.
Misc
This source is great! I could completely get rid of https://github.com/gelguy/wilder.nvim.
Minor things are annoying though:
:e
to get path completions, i get some paths mixed with some other commands provided by this source. However I have setup the cmp-path source to work with this source.cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path', max_item_count = 20 }
}, {
{ name = 'cmdline', max_item_count = 30, }
}),
})
Only when typing /
or ./
etc. I get completions from (only) the path source. This is normally not necessary with :e
because it assumes a relative path.
The path completions provided by this source are hard to use.
Example: I have a folder ./rc
in my cwd. when typing :e r
i get the completion rc/
ending in a /
. Now i have no possibility to get completions for the contents of the folder easily. When typing <cr>
it executes the cmdline immediately. (I have set ['<CR>'] = cmp.mapping.confirm()
out of personal preference). When typing /
again i get completions from the path source for root. And when typing <tab>
I continue cycling the completions.
To actually descend into the folder I need to do something weird like <space><backspace>
to retrigger completion.
Variable
, displaying the type is just useless. So I tried to modify the formatting
option of the cmp.setup.cmdline(':', {formatting=..}
but it didn't work for me.My current formatting table
cmp.setup({
formatting = {
format = require('lspkind').cmp_format({
with_text = true,
maxwidth = 50,
menu = {
cmp_tabnine = '[T9]',
vsnip = '[VSNIP]',
path = '[PATH]',
nvim_lsp = '[LSP]',
nvim_lua = '[LUA]',
buffer = '[BUF]',
cmdline = '[CMD]',
},
})
},
}
It would be nice to be able to adjust the formatting for the cmdline completion seperately.
Describe the bug
nvim freezes up if I try to type :!
in the cmdline
Minimal config based on this
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'
Plug 'hrsh7th/cmp-cmdline'
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 = "nvim_lsp" },
{ name = "buffer" },
},
}
cmp.setup.cmdline(":", {
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
})
EOF
lua << EOF
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
require'lspconfig'.cssls.setup {
capabilities = capabilities,
}
EOF
To Reproduce
:!
Expected behavior
Should not freeze up
Additional context
Only happens in wsl2. Tested in MacOS and I don't have the issue
I am wondering if there is a configuration that can auto select the first entry whenever I start typing characters
For example I currently use
completion = { completeopt = 'menu,menuone,noinsert' }, -- pre select the first one
to do the trick, but it seems like when I hit on the pre select item, it doesn't auto expand to the full entry, just the character I entered, which is different from what I see in normal editor area
In cmdline's default behavior, we can have completion for vert help
, which is same as help
, however, this is not the case for this source.
All other default mappings work as expected. For example, <C-n>
for next, <C-p>
for previous, <C-e>
to close.
However, <C-y>
to confirm does not work on either command mode or while searching. It places a ^Y
char.
Creating a mapping config does not work:
mapping = {
['<C-y>'] = cmp.mapping.confirm({ select = true }),
}
How can I enable this?
when searching something in the buffer with /
or ?
hlsearch automatically gets turned off everytime cmp window is shown/updated so there is a flicker everytime you type something
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 !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'
Plug 'hrsh7th/cmp-cmdline'
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 = "nvim_lsp" },
{ name = "buffer" },
},
}
require'cmp'.setup.cmdline(':', {
sources = {
{ name = 'cmdline' }
}
})
require'cmp'.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
EOF
lua << EOF
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
require'lspconfig'.cssls.setup {
capabilities = capabilities,
}
EOF
Normally, when you type :e %
and press tab
, the %
will expand to the current buffer's path. However, with cmp-cmdline
, the %
will expand to the path but with a %
prepended to it.
Example:
touch myfile
nvim myfile
:e %<TAB>
Should expand to :e myfile
but instead expands to :e %myfile
.
E5500: autocmd has thrown an exception: Vim(lua):E5108: Error executing lua Keyboard interrupt^@stack traceback:^@^I[C]: in function 'getcompletion'^@^I.../share/nvim/pl
ugged/cmp-cmdline/lua/cmp_cmdline/init.lua:13: in function 'exec'^@^I.../share/nvim/plugged/cmp-cmdline/lua/cmp_cmdline/init.lua:68: in function 'complete'^@^I...el/.loc
al/share/nvim/plugged/nvim-cmp/lua/cmp/source.lua:290: in function 'complete'^@^I...nuel/.local/share/nvim/plugged/nvim-cmp/lua/cmp/core.lua:250: in function 'complete'^
@^I...nuel/.local/share/nvim/plugged/nvim-cmp/lua/cmp/core.lua:163: in function 'autoindent'^@^I...nuel/.local/share/nvim/plugged/nvim-cmp/lua/cmp/core.lua:155: in funct
ion 'on_change'^@^I...nuel/.local/share/nvim/plugged/nvim-cmp/lua/cmp/init.lua:301: in function 'callback'^@^I...al/share/nvim/plugged/nvim-cmp/lua/cmp/utils/autocmd.lua
:31: in function 'emit'^@^I[string ":lua"]:1: in main chunk
cmp-cmdline doesn't seem to complete system variables like $HOME
. I think this would be a nice feature. Perhaps even that it expanded the variable's value upon selection.
I tried to install cmdline but it just don't give any suggestions or completion
Here is my config using packer :
use({
"hrsh7th/cmp-cmdline",
config = "require('custom.plugins.cmdline')",
})
The cmdline config :
require'cmp'.setup.cmdline(':', {
sources = {
{ name = 'cmdline' }
}
})
Hi,
here is how to reproduce the issue:
I have cmp-cmdline added with:
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
Results:
nvim-cmp hangs and can only be stopped with Ctrl-C. Error message below.
E5500: autocmd has thrown an exception: Vim(lua):E5108: Error executing lua Keyboard interrupt^@stack traceback:^@^I[C]: in function 'getcompletion'^@^I.../share/nvim/pl
ugged/cmp-cmdline/lua/cmp_cmdline/init.lua:13: in function 'exec'^@^I.../share/nvim/plugged/cmp-cmdline/lua/cmp_cmdline/init.lua:68: in function 'complete'^@^I...el/.loc
al/share/nvim/plugged/nvim-cmp/lua/cmp/source.lua:290: in function 'complete'^@^I...nuel/.local/share/nvim/plugged/nvim-cmp/lua/cmp/core.lua:250: in function 'complete'^
@^I...nuel/.local/share/nvim/plugged/nvim-cmp/lua/cmp/core.lua:163: in function 'autoindent'^@^I...nuel/.local/share/nvim/plugged/nvim-cmp/lua/cmp/core.lua:155: in funct
ion 'on_change'^@^I...nuel/.local/share/nvim/plugged/nvim-cmp/lua/cmp/init.lua:301: in function 'callback'^@^I...al/share/nvim/plugged/nvim-cmp/lua/cmp/utils/autocmd.lua
:31: in function 'emit'^@^I[string ":lua"]:1: in main chunk
Expected result:
Not hanging, being able to type a system command
Wanted to check if ghost text can be implemented for the cmdline only, it's more useful there than in editor completions.
If not, maybe treat this a feature request :)
When define a user command with -complete=command
argument, cmp-cmdline
can't even give a completion list.
For exxample with the following command, after input Redir
in vim cmdline, <tab>
do not give any further completion.
command! -nargs=1 -complete=command Redir call utils#CaptureCommandOutput(<q-args>)
cmp.setup.cmdline('/', {
sources = {
{name = 'buffer'}
-- { name = 'rg'},
-- {name = 'fuzzy_buffer'}
}
})
magic search in vim simplifies regex but it confuses cmp.cmdline, eg when I search for import word:
/\vimp
the buffers will not show suggestions related to 'imp' but to 'vimp'. Issue is affecting other sources that are attached to cmdline sources
/imp
works ok though.
I hope there is way to filter out the magic characters.
I've Ctrl-n
and Ctrl-p
mapping which works fine for search and cmd mode. But the Tab binding has stopped working
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
cmp.setup({
....,
mapping = cmp.mapping.preset.insert({
...
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<C-n>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_next_item()
else
cmp.complete()
end
end, { "i", "c" }),
}),
....
})
cmp.setup.cmdline("/", {
-- completion = { autocomplete = false },
sources = {
-- { name = 'buffer' }
{ name = "buffer", opts = { keyword_pattern = [=[[^[:blank:]].*]=] } },
},
})
cmp.setup.cmdline(":", {
completion = { autocomplete = false },
entries = {name = 'custom'--[[ , separator = '|' ]] }
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
})
Note: I use vsnip
I am not sure if its just me but :e %
does not expand %
into the file path. This extends to something like :e %:h
.
It seems that keyword_length
is ignored (or misinterpreted) when using a mapping to change buffers.
keyword_length = 3
<leader>n
to switch to next buffer:
and completion appears immediatelyUsing :bn
and then :
uses the set keyword_length
prior to triggering completion as expected.
nnoremap <silent> <leader>n :bnext<CR>
nnoremap <silent> <leader>p :bprevious<CR>
it would be nice to also get completions for :!
and other elements that expand to a shell command
I think getcompletion(keyword, 'shellcmd')
should do.
vim.ui.input
accepts a completion
option, however cmp-cmdline will not complete candidates, but wildmenu will.
I presume same problem with vim.ui.select
es:
:lua vim.ui.input({prompt = "complete me: ", completion = 'dir'}, function(input) print(input) end)
I've noticed cmdline isn't showing completions for some items that normally appear. Gitsigns
and lua vim.lsp
both don't shown any completions.
Using the below mappings and cmdline setup it is not possible to select entries that appear using C-n or C-p. I'm guessing this is because of the c_CTRL-N
and c_CTRL-P
mappings. Also using this which might be relevant set wildmode=longest:full,full
. Any suggestions on a workaround?
mapping = {
["<C-y>"] = cmp.mapping.confirm(),
["<C-n>"] = function()
if cmp.visible() then
cmp.select_next_item()
else
cmp.complete()
end
end,
["<C-p>"] = function()
if cmp.visible() then
cmp.select_prev_item()
else
cmp.complete()
end
end,
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.close(),
},
Hey I have ran PackerSync
today and it broke the /
completions from some reason.
:
completions are working fine, I have tried to add buffer
as source for :
and it worked too, so I don't think its cmp-buffer
This is the setup for my cmp
:
local cmp = require'cmp'
local lspkind = require('lspkind')
cmp.setup({
snippet = {
expand = function(args)
require('snippy').expand_snippet(args.body) -- For `snippy` users.
end,
},
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }),
['<S-Tab>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable,
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping.confirm({ select = true }),
},
formatting = {
format = lspkind.cmp_format({
with_text = false,
maxwidth = 50,
before = function (entry, vim_item)
return vim_item
end
})
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'snippy' },
{ name = 'spell' },
}, {
{ name = 'buffer' },
})
})
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
Neovim version:
NVIM v0.8.0-dev+95b7851
Build type: Debug
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=malloc -Wsuggest-attribute=cold -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=1 -I/home/ogal/.local/nvim-nightly/neovim/build/config -I/home/ogal/.local/nvim-nightly/neovim/src -I/home/ogal/.local/nvim-nightly/neovim/.deps/usr/include -I/usr/include -I/home/ogal/.local/nvim-nightly/neovim/build/src/nvim/auto -I/home/ogal/.local/nvim-nightly/neovim/build/include
Compiled by ogal@ogal
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/home/ogal/.local/share/nvim"
Run :checkhealth for more info
It would be great if mappings were taken from nvim-cmp configuration. Currently I have for example:
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(),
But for cmp-cmdline I still have to use <tab>
.
I have no idea if this is doable, but switching to different completion sources (I'm using path and cmdline for :
in general) after :[%]s/
or :g/
would be incredibly helpful.
👋🏼,
I have noignorecase
and nosmartcase
on as I want case to be consistent when searching, using :s
or pretty much everything. One thing that I do miss is that is also is applied for commands, ie. :g
will not recommend :Git
command.
I'd love it if I was able to set ignorecase
for the actual suggestions on cmp-cmdline
. In that way I could keep my settings but :g
would give me a tabable suggestion!
🙏🏼
I'm not sure if this is a bug or not, but I don't have any completion for lua after .
.
Completes:
:lua
Doesn't complete:
:lua vim.
But :echo getcompletion("lua vim.", "cmdline")
gives some usefull results. Also I can complete with fallback <Tab>
(internal completion).
Hi.
'incsearch' stopped working for me while using cmdline.
Using the default config from cmp, this is what I get:
cmp.txt
When running setfiletype
, no candidates are provided as with vanilla cmdline completion.
This plugin is awesome, the only bug I found is that whenever I want to substitute a word there's no completion e.g.
:%s/Hello/Salut/g
:s/Welcome/Bienvenue/g
There's no completion for this, the most important thing is buffer
completion at this moment:
:s/
:%s/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.