cmp polish, dotenv, improve lsp leader mappings
This commit is contained in:
parent
524afbb9aa
commit
adefe5c331
67
init.lua
67
init.lua
|
@ -62,7 +62,7 @@ vim.cmd 'filetype plugin indent on'
|
||||||
|
|
||||||
-- Enable persistent undo
|
-- Enable persistent undo
|
||||||
if fn.has('persistent_undo') then
|
if fn.has('persistent_undo') then
|
||||||
o.undodir = fn.expand('~/.local/share/nvim/undo')
|
o.undodir = fn.stdpath('data') .. '/undo'
|
||||||
o.undofile = true
|
o.undofile = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -286,6 +286,8 @@ require'packer'.startup(function(use)
|
||||||
-- LSP --
|
-- LSP --
|
||||||
use 'neovim/nvim-lspconfig'
|
use 'neovim/nvim-lspconfig'
|
||||||
use 'hrsh7th/nvim-cmp'
|
use 'hrsh7th/nvim-cmp'
|
||||||
|
use 'rcarriga/cmp-dap'
|
||||||
|
use 'hrsh7th/cmp-nvim-lua'
|
||||||
use 'hrsh7th/cmp-nvim-lsp'
|
use 'hrsh7th/cmp-nvim-lsp'
|
||||||
use 'hrsh7th/cmp-buffer'
|
use 'hrsh7th/cmp-buffer'
|
||||||
use 'hrsh7th/cmp-path'
|
use 'hrsh7th/cmp-path'
|
||||||
|
@ -609,6 +611,12 @@ require'packer'.startup(function(use)
|
||||||
use 'antoinemadec/FixCursorHold.nvim'
|
use 'antoinemadec/FixCursorHold.nvim'
|
||||||
end
|
end
|
||||||
use 'lewis6991/impatient.nvim' -- speeds up load times
|
use 'lewis6991/impatient.nvim' -- speeds up load times
|
||||||
|
use {'ellisonleao/dotenv.nvim', config = function ()
|
||||||
|
require'dotenv'.setup {
|
||||||
|
enable_on_load = false,
|
||||||
|
verbose = true,
|
||||||
|
}
|
||||||
|
end}
|
||||||
|
|
||||||
-- Finish bootstrap if we just cloned
|
-- Finish bootstrap if we just cloned
|
||||||
if packer_bootstrap then
|
if packer_bootstrap then
|
||||||
|
@ -744,16 +752,21 @@ local feedkey = function(key, mode)
|
||||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||||||
end
|
end
|
||||||
local cmp = require'cmp'
|
local cmp = require'cmp'
|
||||||
|
local cmp_dap = require'cmp_dap'
|
||||||
cmp.setup {
|
cmp.setup {
|
||||||
|
enabled = function ()
|
||||||
|
return vim.bo.buftype ~= 'prompt' or cmp_dap.is_dap_buffer()
|
||||||
|
end,
|
||||||
preselect = cmp.PreselectMode.None,
|
preselect = cmp.PreselectMode.None,
|
||||||
snippet = {
|
snippet = {
|
||||||
expand = function(args)
|
expand = function(args)
|
||||||
vim.fn['vsnip#anonymous'](args.body)
|
vim.fn['vsnip#anonymous'](args.body)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
mapping = {
|
mapping = cmp.mapping.preset.insert {
|
||||||
-- Next item, or expand or jump snippet, or fallback
|
-- Next item, or expand or jump snippet, or fallback
|
||||||
['<Tab>'] = cmp.mapping(function(fallback)
|
['<Tab>'] = cmp.mapping(
|
||||||
|
function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_next_item()
|
cmp.select_next_item()
|
||||||
elseif vim.fn['vsnip#available'](1) == 1 then
|
elseif vim.fn['vsnip#available'](1) == 1 then
|
||||||
|
@ -761,9 +774,12 @@ cmp.setup {
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
end, {'i', 's'}),
|
end,
|
||||||
|
{'i', 's'}
|
||||||
|
),
|
||||||
-- Prev item, or jump snippet back, or fallback
|
-- Prev item, or jump snippet back, or fallback
|
||||||
['<S-Tab>'] = cmp.mapping(function(fallback)
|
['<S-Tab>'] = cmp.mapping(
|
||||||
|
function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_prev_item()
|
cmp.select_prev_item()
|
||||||
elseif vim.fn['vsnip#available'](-1) == 1 then
|
elseif vim.fn['vsnip#available'](-1) == 1 then
|
||||||
|
@ -771,7 +787,13 @@ cmp.setup {
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
end, {'i', 's'}),
|
end,
|
||||||
|
{'i', 's'}
|
||||||
|
),
|
||||||
|
-- Scroll documentation up
|
||||||
|
['<C-e'] = cmp.mapping(cmp.mapping.scroll_docs(4), {'i', 'c'}),
|
||||||
|
-- Scroll documentation down
|
||||||
|
['<C-y>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), {'i', 'c'}),
|
||||||
-- Complete common substring
|
-- Complete common substring
|
||||||
['<C-l>'] = cmp.mapping(cmp.mapping.complete_common_string(), {'i', 'c'}),
|
['<C-l>'] = cmp.mapping(cmp.mapping.complete_common_string(), {'i', 'c'}),
|
||||||
-- Complete
|
-- Complete
|
||||||
|
@ -782,6 +804,7 @@ cmp.setup {
|
||||||
sources = {
|
sources = {
|
||||||
{ name = 'path' },
|
{ name = 'path' },
|
||||||
{ name = 'nvim_lsp' },
|
{ name = 'nvim_lsp' },
|
||||||
|
{ name = 'nvim_lua' },
|
||||||
{ name = 'vsnip' },
|
{ name = 'vsnip' },
|
||||||
},
|
},
|
||||||
-- Experimental features
|
-- Experimental features
|
||||||
|
@ -790,6 +813,31 @@ cmp.setup {
|
||||||
ghost_text = true,
|
ghost_text = true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
cmp.setup.cmdline(':', {
|
||||||
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
|
sources = cmp.config.sources({
|
||||||
|
{ name = 'path' }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{
|
||||||
|
name = 'cmdline',
|
||||||
|
option = {
|
||||||
|
ignore_cmds = { 'Man', '!' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
cmp.setup.cmdline({'/', '?'}, {
|
||||||
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
|
sources = {
|
||||||
|
{ name = 'buffer' }
|
||||||
|
},
|
||||||
|
})
|
||||||
|
cmp.setup.filetype({'dap-repl', 'dapui_watches', 'dapui_hover'}, {
|
||||||
|
sources = {
|
||||||
|
{ name = 'dap' },
|
||||||
|
},
|
||||||
|
})
|
||||||
local capabilities = require'cmp_nvim_lsp'.default_capabilities()
|
local capabilities = require'cmp_nvim_lsp'.default_capabilities()
|
||||||
|
|
||||||
---- lsp: language servers ----
|
---- lsp: language servers ----
|
||||||
|
@ -800,8 +848,9 @@ local function on_attach(client, bufnr)
|
||||||
|
|
||||||
require'which-key'.register({
|
require'which-key'.register({
|
||||||
['<Leader>l'] = {
|
['<Leader>l'] = {
|
||||||
d = {vim.lsp.buf.definition, 'Goto definition'},
|
D = {vim.lsp.buf.declaration, 'Declaration'},
|
||||||
D = {vim.lsp.buf.implementation, 'Goto implementation'},
|
d = {vim.lsp.buf.definition, 'Definition'},
|
||||||
|
i = {vim.lsp.buf.implementation, 'Implementation'},
|
||||||
a = {vim.lsp.buf.code_action, 'Code action'},
|
a = {vim.lsp.buf.code_action, 'Code action'},
|
||||||
r = {vim.lsp.buf.rename, 'Rename'},
|
r = {vim.lsp.buf.rename, 'Rename'},
|
||||||
t = {vim.lsp.buf.type_definition, 'Type definition'},
|
t = {vim.lsp.buf.type_definition, 'Type definition'},
|
||||||
|
@ -839,8 +888,6 @@ local function on_attach(client, bufnr)
|
||||||
vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc'
|
vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc'
|
||||||
|
|
||||||
require'nvim-navic'.attach(client, bufnr)
|
require'nvim-navic'.attach(client, bufnr)
|
||||||
|
|
||||||
au('CursorMoved', { callback = vim.lsp.buf.clear_references, buffer = bufnr, })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Enable language servers
|
-- Enable language servers
|
||||||
|
|
Loading…
Reference in a new issue