set completeopt=menu,menuone,noselect
call plug#begin('~/.vim/plugged')
" LSP
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'
" Initialize plugin system
call plug#end()
" LSP
"
lua <<EOF
-- Set up nvim-cmp.
local cmp = require'cmp'
cmp.setup({
preselect = cmp.PreselectMode.None,
mapping = cmp.mapping.preset.insert({
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end,
['<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({
i = function(fallback)
if cmp.visible() and cmp.get_active_entry() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
else
fallback()
end
end,
s = cmp.mapping.confirm({ select = false }),
c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }),
}),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
require('lspconfig')['tsserver'].setup{
capabilities = capabilities,
single_file_support = true,
on_attach = function(_, bufnr)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
vim.api.nvim_buf_set_option(bufnr, 'tagfunc', 'v:lua.vim.lsp.tagfunc')
end
}
EOF
Description
Note: my configuration is for .js file
When opening any random .js file and pressing Enter in the empty space, <Lua function 58> is inserted instead of the newline. I couldn't get rid of this behavior by trying every <CR> mapping example I could find in this repository and nothing helps. Also preselect config does not help.
Steps to reproduce
Open .js file
press i to enter insert mode
press Enter
Expected behavior
newline is inserted
Actual behavior
<Lua function 58> is inserted
Additional context
Also it inserts <Lua function 58> in my init.vim file just by pressing enter in the empty line.
FAQ
Announcement
Minimal reproducible full config
Description
When opening any random
.js
file and pressing Enter in the empty space,<Lua function 58>
is inserted instead of the newline. I couldn't get rid of this behavior by trying every<CR>
mapping example I could find in this repository and nothing helps. Alsopreselect
config does not help.Steps to reproduce
.js
filei
to enter insert modeExpected behavior
newline is inserted
Actual behavior
<Lua function 58>
is insertedAdditional context
Also it inserts
<Lua function 58>
in myinit.vim
file just by pressing enter in the empty line.