From e2883114f1a87d900d618ac6786186282d111460 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 8 Aug 2022 11:07:10 +0200 Subject: [PATCH] nvim: add org, completion, lsp --- .config/nvim/init.lua | 3 ++ .config/nvim/lua/completion.lua | 70 ++++++++++++++++++++++++++++++++ .config/nvim/lua/fileformats.lua | 9 ++++ .config/nvim/lua/keymaps.lua | 2 +- .config/nvim/lua/lsp.lua | 44 ++++++++++++++++++++ .config/nvim/lua/plugins.lua | 27 +++++++++++- .config/nvim/lua/settings.lua | 17 ++++---- 7 files changed, 163 insertions(+), 9 deletions(-) create mode 100644 .config/nvim/lua/completion.lua create mode 100644 .config/nvim/lua/fileformats.lua create mode 100644 .config/nvim/lua/lsp.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index b4f48f3..7253ed5 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,3 +1,6 @@ require('plugins') require('settings') require('keymaps') +require('fileformats') +require('lsp') +require('completion') diff --git a/.config/nvim/lua/completion.lua b/.config/nvim/lua/completion.lua new file mode 100644 index 0000000..4e27213 --- /dev/null +++ b/.config/nvim/lua/completion.lua @@ -0,0 +1,70 @@ +require('plugins') + +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({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = false }), + [''] = 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' }, + }) +}) + +-- 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' } + }) +}) + +-- 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' }, + }) +}) diff --git a/.config/nvim/lua/fileformats.lua b/.config/nvim/lua/fileformats.lua new file mode 100644 index 0000000..0cd2229 --- /dev/null +++ b/.config/nvim/lua/fileformats.lua @@ -0,0 +1,9 @@ +-- org +require('orgmode').setup_ts_grammar() +require'nvim-treesitter.configs'.setup { + highlight = { + enable = true, + additional_vim_regex_highlighting = {'org'} + }, + ensure_installed = {'org'}, +} diff --git a/.config/nvim/lua/keymaps.lua b/.config/nvim/lua/keymaps.lua index 8b57b46..05eb787 100644 --- a/.config/nvim/lua/keymaps.lua +++ b/.config/nvim/lua/keymaps.lua @@ -1,5 +1,5 @@ function map(mode, shortcut, command) - vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true }) + vim.keymap.set(mode, shortcut, command, { noremap = true, silent = true }) end map('n', '', ':tabprevious') diff --git a/.config/nvim/lua/lsp.lua b/.config/nvim/lua/lsp.lua new file mode 100644 index 0000000..31e8a48 --- /dev/null +++ b/.config/nvim/lua/lsp.lua @@ -0,0 +1,44 @@ +require('plugins') +require('keymaps') + +map('n', '', vim.diagnostic.goto_prev) +map('n', '', vim.diagnostic.goto_next) + +-- Only map the following keys after the language server attaches to the +-- current buffer +-- TODO: get completion and key mappings to work. +local on_attach = function(client, bufnr) + -- Enable completion triggered by + 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 }) + 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', '', vim.lsp.buf.signature_help) + maplsp('n', 'wa', vim.lsp.buf.add_workspace_folder) + maplsp('n', 'wr', vim.lsp.buf.remove_workspace_folder) + maplsp('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end) + maplsp('n', 'D', vim.lsp.buf.type_definition) + maplsp('n', 'rn', vim.lsp.buf.rename) + maplsp('n', 'ca', vim.lsp.buf.code_action) + maplsp('n', 'gr', vim.lsp.buf.references) + maplsp('n', '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 + } +} diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index c5e82a5..9b699f1 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -7,7 +7,32 @@ end require('packer').startup(function(use) use 'https://github.com/wbthomason/packer.nvim' - use 'https://github.com/GuiLra/vim' + 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' if packer_bootstrap then require('packer').sync() diff --git a/.config/nvim/lua/settings.lua b/.config/nvim/lua/settings.lua index d8e47f4..1501983 100644 --- a/.config/nvim/lua/settings.lua +++ b/.config/nvim/lua/settings.lua @@ -1,11 +1,14 @@ -vim.o.number = true -- line numbers -vim.o.list = true -- show whitespace +vim.o.number = true -- line numbers +vim.o.list = true -- show whitespace +vim.o.colorcolumn = '80,100' -- line length marker -vim.o.expandtab = true -- indent using spaces -vim.o.tabstop = 4 -- 1 tab = 4 spaces -vim.o.shiftwidth = 4 -- 1 indentation = 4 spaces +vim.o.expandtab = true -- indent using spaces +vim.o.tabstop = 4 -- 1 tab = 4 spaces +vim.o.shiftwidth = 4 -- 1 indentation = 4 spaces + +vim.o.completeopt = 'menu,menuone,noselect' -- completion popup -- theme -vim.o.termguicolors = true +vim.o.termguicolors = true -- 24 bit colours vim.o.background = 'dark' -vim.cmd('colorscheme omni') +vim.cmd('colorscheme amora')