From 706089cafe16a0b9a6faad2d111269f4faf9b4a4 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 20 Jan 2022 12:32:35 +0100 Subject: Adjusts nvim config --- .config/nvim/init.vim | 132 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 3 deletions(-) (limited to '.config/nvim/init.vim') diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index e143cd6..b152723 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -15,6 +15,20 @@ Plug 'nvim-telescope/telescope.nvim' Plug 'airblade/vim-gitgutter' +Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} + +Plug 'iamcco/markdown-preview.nvim', {'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']} +" if install fails do `:call mkdp#util#install() manually` + +Plug 'neovim/nvim-lspconfig' +Plug 'williamboman/nvim-lsp-installer' +Plug 'hrsh7th/nvim-cmp' +Plug 'hrsh7th/cmp-nvim-lsp' +Plug 'saadparwaiz1/cmp_luasnip' +Plug 'L3MON4D3/LuaSnip' + +Plug 'https://gitlab.com/dweipert.de/rclone.nvim' + call plug#end() @@ -36,10 +50,13 @@ hi Normal guibg=NONE ctermbg=NONE " Nerdtree let g:NERDTreeShowHidden=1 +let g:NERDTreeGitStatusShowIgnored=1 -autocmd StdinReadPre * let s:std_in=1 -autocmd VimEnter * NERDTree | if argc() > 0 || exists('s:std_ine') | wincmd p | endif -autocmd VimEnter * if argc() > 0 | silent NERDTreeFind | wincmd p | endif +if !&diff + autocmd StdinReadPre * let s:std_in=1 + autocmd VimEnter * NERDTree | if argc() > 0 || exists('s:std_ine') | wincmd p | endif + autocmd VimEnter * if argc() > 0 | silent NERDTreeFind | wincmd p | endif +endif autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif @@ -54,6 +71,115 @@ nnoremap fg Telescope live_grep nnoremap Telescope buffers +" Treesitter + +lua < + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + + -- See :help vim.lsp.* for documentation on any of the below functions + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) + +vim.o.completeopt = 'menuone,noselect' + +local lsp_installer = require('nvim-lsp-installer') +lsp_installer.on_server_ready(function(server) + server:setup({ + on_attach = on_attach, + capabilities = capabilities, + }) +end) + +local cmp = require('cmp') +local luasnip = require('luasnip') +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, + [''] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} +EOF + + " " " Keys " " -- cgit v1.2.3