nvim: modularise plugin config

This commit is contained in:
tastytea 2022-08-08 13:57:38 +02:00
parent 0eaee2bc1a
commit a7d3f4c9ee
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
6 changed files with 154 additions and 140 deletions

View File

@ -4,3 +4,7 @@ require('keymaps')
require('fileformats')
require('lsp')
require('completion')
if packer_bootstrap then
require('packer').sync()
end

View File

@ -1,71 +1,82 @@
require('plugins')
require('lsp')
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
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 = false }),
['<tab>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- For luasnip users.
}, {
{ name = 'buffer' },
})
})
use 'https://github.com/hrsh7th/cmp-nvim-lsp'
use 'https://github.com/hrsh7th/cmp-buffer'
use 'https://github.com/hrsh7th/cmp-path'
use 'https://github.com/hrsh7th/cmp-cmdline'
use 'https://github.com/hrsh7th/cmp-nvim-lua'
use {
'https://github.com/hrsh7th/nvim-cmp',
config = function()
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
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 = false }),
['<tab>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- For luasnip users.
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' },
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' },
}, {
{ 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' }
}
})
-- 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' }
}
})
-- 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' }
})
})
-- 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' }
})
})
-- setup lspconfig
local capabilities = require('cmp_nvim_lsp').update_capabilities(
vim.lsp.protocol.make_client_capabilities())
-- add for each enabled lsp server
require('lspconfig')['clangd'].setup {
capabilities = capabilities
-- setup lspconfig
local capabilities = require('cmp_nvim_lsp').update_capabilities(
vim.lsp.protocol.make_client_capabilities())
-- add for each enabled lsp server
require('lspconfig')['clangd'].setup {
capabilities = capabilities
}
cmp.setup.filetype('lua', {
sources = cmp.config.sources({
{ name = 'nvim_lua' },
}, {
{ name = 'buffer' },
})
})
end
}
cmp.setup.filetype('lua', {
sources = cmp.config.sources({
{ name = 'nvim_lua' },
}, {
{ name = 'buffer' },
})
})

View File

@ -1,11 +1,17 @@
require('plugins')
-- org
require('orgmode').setup_ts_grammar()
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
additional_vim_regex_highlighting = {'org'}
},
ensure_installed = {'org'},
use {
'https://github.com/nvim-orgmode/orgmode',
config = function()
require('orgmode').setup{}
require('orgmode').setup_ts_grammar()
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
additional_vim_regex_highlighting = {'org'}
},
ensure_installed = {'org'},
}
end
}

View File

@ -1,44 +1,49 @@
require('plugins')
require('keymaps')
map('n', '<f5>', vim.diagnostic.goto_prev)
map('n', '<f6>', vim.diagnostic.goto_next)
use {
'https://github.com/neovim/nvim-lspconfig',
config = function()
map('n', '<f5>', vim.diagnostic.goto_prev)
map('n', '<f6>', vim.diagnostic.goto_next)
-- Only map the following keys after the language server attaches to the
-- current buffer
-- TODO: get key mappings to work.
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Only map the following keys after the language server attaches to the
-- current buffer
-- TODO: get key mappings to work.
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
local function maplsp(mode, shortcut, command)
vim.keymap.set(mode, shortcut, command,
{ noremap = true, silent = true, buffer=bufnr })
local function maplsp(mode, shortcut, command)
vim.keymap.set(mode, shortcut, command,
{ noremap = true, silent = true, buffer=bufnr })
end
maplsp('n', 'gD', vim.lsp.buf.declaration)
maplsp('n', 'gd', vim.lsp.buf.definition)
maplsp('n', 'K', vim.lsp.buf.hover)
maplsp('n', 'gi', vim.lsp.buf.implementation)
maplsp('n', '<C-k>', vim.lsp.buf.signature_help)
maplsp('n', '<space>wa', vim.lsp.buf.add_workspace_folder)
maplsp('n', '<space>wr', vim.lsp.buf.remove_workspace_folder)
maplsp('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end)
maplsp('n', '<space>D', vim.lsp.buf.type_definition)
maplsp('n', '<space>rn', vim.lsp.buf.rename)
maplsp('n', '<space>ca', vim.lsp.buf.code_action)
maplsp('n', 'gr', vim.lsp.buf.references)
maplsp('n', '<space>f', vim.lsp.buf.formatting)
end
-- setup servers
require'lspconfig'.clangd.setup{
cmd = {
'clangd',
'--compile-commands-dir=build',
'--clang-tidy', -- needs >=clangd-9
'--ranking-model=decision_forest' -- needs >=clangd-12
}
}
end
maplsp('n', 'gD', vim.lsp.buf.declaration)
maplsp('n', 'gd', vim.lsp.buf.definition)
maplsp('n', 'K', vim.lsp.buf.hover)
maplsp('n', 'gi', vim.lsp.buf.implementation)
maplsp('n', '<C-k>', vim.lsp.buf.signature_help)
maplsp('n', '<space>wa', vim.lsp.buf.add_workspace_folder)
maplsp('n', '<space>wr', vim.lsp.buf.remove_workspace_folder)
maplsp('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end)
maplsp('n', '<space>D', vim.lsp.buf.type_definition)
maplsp('n', '<space>rn', vim.lsp.buf.rename)
maplsp('n', '<space>ca', vim.lsp.buf.code_action)
maplsp('n', 'gr', vim.lsp.buf.references)
maplsp('n', '<space>f', vim.lsp.buf.formatting)
end
-- setup servers
require'lspconfig'.clangd.setup{
cmd = {
'clangd',
'--compile-commands-dir=build',
'--clang-tidy', -- needs >=clangd-9
'--ranking-model=decision_forest' -- needs >=clangd-12
}
}

View File

@ -5,39 +5,20 @@ if fn.empty(fn.glob(install_path)) > 0 then
vim.cmd [[packadd packer.nvim]]
end
require('packer').startup(function(use)
use 'https://github.com/wbthomason/packer.nvim'
use 'https://github.com/owozsh/amora'
-- file formats
use {
'https://github.com/nvim-orgmode/orgmode',
config = function()
require('orgmode').setup{}
end
}
-- source code
use 'https://github.com/tpope/vim-commentary'
---- lsp
use {
'https://github.com/nvim-treesitter/nvim-treesitter',
run = function()
require('nvim-treesitter.install').update({ with_sync = true })
end
}
use 'https://github.com/neovim/nvim-lspconfig'
---- completion
use 'https://github.com/L3MON4D3/LuaSnip'
use 'https://github.com/hrsh7th/cmp-nvim-lsp'
use 'https://github.com/hrsh7th/cmp-buffer'
use 'https://github.com/hrsh7th/cmp-path'
use 'https://github.com/hrsh7th/cmp-cmdline'
use 'https://github.com/hrsh7th/cmp-nvim-lua'
use 'https://github.com/hrsh7th/nvim-cmp'
packer = require('packer')
packer.init()
use = packer.use
if packer_bootstrap then
require('packer').sync()
use 'https://github.com/wbthomason/packer.nvim'
-- common dependencies
use {
'https://github.com/nvim-treesitter/nvim-treesitter',
run = function()
require('nvim-treesitter.install').update({ with_sync = true })
end
end)
}
use 'https://github.com/L3MON4D3/LuaSnip'
vim.cmd([[
augroup packer_user_config

View File

@ -11,7 +11,14 @@ vim.o.completeopt = 'menu,menuone,noselect' -- completion popup
-- theme
vim.o.termguicolors = true -- 24 bit colours
vim.o.background = 'dark'
vim.cmd('colorscheme amora')
packer.use {
'https://github.com/owozsh/amora',
config = function()
vim.cmd('colorscheme amora')
end
}
use 'https://github.com/tpope/vim-commentary' -- toggle comments
-- remove trailing whitespace
function remove_trailing_whitespace()