From e8849309ff87add5248d3da90c1e30970d6c055c Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Sat, 31 Jul 2021 04:03:12 -0500 Subject: [PATCH] chore: general update --- .config/nvim/init.vim | 154 ++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 88 deletions(-) diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 7d04f6e..2683803 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -30,6 +30,8 @@ Plug 'glepnir/dashboard-nvim' Plug 'hoob3rt/lualine.nvim' +Plug 'ziglang/zig.vim' + Plug 'simrat39/rust-tools.nvim' " One Dark Pro Plug 'joshdick/onedark.vim' @@ -40,7 +42,10 @@ Plug 'joshdick/onedark.vim' Plug 'mfussenegger/nvim-dap' " Autocomplete -Plug 'hrsh7th/nvim-compe' +Plug 'nvim-lua/completion-nvim' +Plug 'steelsojka/completion-buffers' +Plug 'nvim-treesitter/completion-treesitter' +Plug 'kristijanhusak/completion-tags' Plug 'hrsh7th/vim-vsnip' Plug 'hrsh7th/vim-vsnip-integ' @@ -55,20 +60,29 @@ Plug 'romgrk/barbar.nvim' call plug#end() +" nvim-completion +autocmd BufEnter * lua require'completion'.on_attach() +" Use and to navigate through popup menu +inoremap pumvisible() ? "\" : "\" +inoremap pumvisible() ? "\" : "\" + +" Set completeopt to have a better completion experience +set completeopt=menuone,noinsert,noselect + +" Avoid showing message extra message when using completion +set shortmess+=c + +let g:completion_enable_snippet = 'vim-vsnip' +let g:completion_enable_auto_popup = 1 + +imap (completion_trigger) + " --Telescope Keybinds-- nnoremap ff lua require('telescope.builtin').find_files() nnoremap fg lua require('telescope.builtin').live_grep() nnoremap fb lua require('telescope.builtin').buffers() nnoremap fh lua require('telescope.builtin').help_tags() - -" Compe Keybinds -inoremap compe#complete() -inoremap compe#confirm('') -inoremap compe#close('') -inoremap compe#scroll({ 'delta': +4 }) -inoremap compe#scroll({ 'delta': -4 }) - " Which Key Keybinds " nnoremap :WhichKey '' " nnoremap :WhichKey ',' @@ -148,22 +162,55 @@ highlight NvimTreeFolderIcon guibg=blue colorscheme onedark lua << EOF - -- NVIM 0.5 LSP Setup -local nvim_lsp = require'lspconfig' -nvim_lsp.pyright.setup{} +-- nvim lspconfig +local nvim_lsp = require('lspconfig') -local opts = { noremap=true, silent=true } -vim.api.nvim_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) -vim.api.nvim_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) -vim.api.nvim_set_keymap('n', 'd', 'lua vim.lsp.buf.type_definition()', opts) -vim.api.nvim_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) -vim.api.nvim_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) -vim.api.nvim_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + --Enable completion triggered by + 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 + +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local servers = { "pyright", "zls", "tsserver" } +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + } + } +end -- Rust Tools require'rust-tools'.setup{ @@ -248,75 +295,6 @@ require'nvim-autopairs'.setup() require'nvim_comment'.setup() -- Autocomplete -vim.o.completeopt = "menuone,noselect" - -require'compe'.setup { - enabled = true; - autocomplete = true; - debug = false; - min_length = 1; - preselect = 'enable'; - throttle_time = 80; - source_timeout = 200; - incomplete_delay = 400; - max_abbr_width = 100; - max_kind_width = 100; - max_menu_width = 100; - documentation = true; - - source = { - path = true; - buffer = true; - calc = true; - nvim_lsp = true; - nvim_lua = true; - vsnip = true; - ultisnips = true; - }; -} - -local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) -end - -local check_back_space = function() - local col = vim.fn.col('.') - 1 - if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then - return true - else - return false - end -end - --- Use (s-)tab to: ---- move to prev/next item in completion menuone ---- jump to prev/next snippet's placeholder -_G.tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn.call("vsnip#available", {1}) == 1 then - return t "(vsnip-expand-or-jump)" - elseif check_back_space() then - return t "" - else - return vim.fn['compe#complete']() - end -end -_G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then - return t "(vsnip-jump-prev)" - else - return t "" - end -end - -vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", {expr = true}) - -- lualine Config require'lualine'.setup {