Open pwnalone opened 7 months ago
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-cmdline' Plug 'hrsh7th/cmp-nvim-lsp' Plug 'hrsh7th/vim-vsnip' Plug 'neovim/nvim-lspconfig' call plug#end() PlugInstall | quit lua << EOF local cmp = require "cmp" cmp.setup { snippet = { expand = function(args) vim.fn["vsnip#anonymous"](args.body) end, }, -- XXX: This works... mapping = cmp.mapping.preset.insert({ ['<C-j>'] = cmp.mapping.select_next_item(), ['<C-k>'] = cmp.mapping.select_prev_item(), }), sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "buffer" }, }), } cmp.setup.cmdline(":", { -- XXX: But this doesn't. mapping = cmp.mapping.preset.cmdline({ ['<C-j>'] = cmp.mapping.select_next_item(), ['<C-k>'] = cmp.mapping.select_prev_item(), }), sources = cmp.config.sources({ { name = "cmdline" }, }), }) EOF lua << EOF local capabilities = require('cmp_nvim_lsp').default_capabilities() require'lspconfig'.cssls.setup { capabilities = capabilities, } EOF
It's possible to set custom key mappings for insert mode like so.
mapping = cmp.mapping.preset.insert({ ['<C-j>'] = cmp.mapping.select_next_item(), ['<C-k>'] = cmp.mapping.select_prev_item(), })
But doing the same for command mode does not work.
mapping = cmp.mapping.preset.cmdline({ ['<C-j>'] = cmp.mapping.select_next_item(), ['<C-k>'] = cmp.mapping.select_prev_item(), })
:h
<C-j>
<C-k>
Adding custom key mappings for command mode autocompletion should work just like it does for insert mode autocompletion.
Adding custom key mappings for command mode autocompletion does not work.
As a temporary workaround, the following appears to work.
mapping = cmp.mapping.preset.cmdline({ ['<C-j>'] = { c = cmp.mapping.select_next_item() }, ['<C-k>'] = { c = cmp.mapping.select_prev_item() }, })
FAQ
Announcement
Minimal reproducible full config
Description
It's possible to set custom key mappings for insert mode like so.
But doing the same for command mode does not work.
Steps to reproduce
:h
).<C-j>
or<C-k>
to navigate the list of completion suggestions.Expected behavior
Adding custom key mappings for command mode autocompletion should work just like it does for insert mode autocompletion.
Actual behavior
Adding custom key mappings for command mode autocompletion does not work.
Additional context
As a temporary workaround, the following appears to work.