diff --git a/init.vim b/init.vim index 2290f45..792aa06 100644 --- a/init.vim +++ b/init.vim @@ -12,6 +12,7 @@ source plug.vim source airline.vim source syntastic.vim source fzf.vim +source rust.vim source mapping.vim source jsonnet.vim source nerdtree.vim diff --git a/mapping.vim b/mapping.vim index 79d60c0..39ff7eb 100644 --- a/mapping.vim +++ b/mapping.vim @@ -11,3 +11,20 @@ nmap :NERDTreeToggle nmap :NERDTreeFind " use similar key, esc, to exit terminal mode tnoremap + +" from: https://sharksforarms.dev/posts/neovim-rust/ +" Code navigation shortcuts +nnoremap lua vim.lsp.buf.definition() +nnoremap K lua vim.lsp.buf.hover() +nnoremap gD lua vim.lsp.buf.implementation() +nnoremap lua vim.lsp.buf.signature_help() +nnoremap 1gD lua vim.lsp.buf.type_definition() +nnoremap gr lua vim.lsp.buf.references() +nnoremap g0 lua vim.lsp.buf.document_symbol() +nnoremap gW lua vim.lsp.buf.workspace_symbol() +nnoremap gd lua vim.lsp.buf.definition() +nnoremap ga lua vim.lsp.buf.code_action() + +" Goto previous/next diagnostic warning/error +nnoremap g[ lua vim.lsp.diagnostic.goto_prev() +nnoremap g] lua vim.lsp.diagnostic.goto_next() diff --git a/plug.vim b/plug.vim index 983386a..6be11b2 100644 --- a/plug.vim +++ b/plug.vim @@ -28,13 +28,37 @@ Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } Plug 'junegunn/fzf.vim' " auto detect tab and space handling rather than setting per project Plug 'tpope/vim-sleuth' + + " support for the Rust programming language Plug 'rust-lang/rust.vim' -Plug 'simrat39/rust-tools.nvim' -" support for Rust's build tool/dependency manager -Plug 'timonv/vim-cargo' -" support for lsp + +" the rest of the rust config came from: https://sharksforarms.dev/posts/neovim-rust/ +" Collection of common configurations for the Nvim LSP client Plug 'neovim/nvim-lspconfig' + +" Completion framework +Plug 'hrsh7th/nvim-cmp' + +" LSP completion source for nvim-cmp +Plug 'hrsh7th/cmp-nvim-lsp' + +" Snippet completion source for nvim-cmp +Plug 'hrsh7th/cmp-vsnip' + +" Other usefull completion sources +Plug 'hrsh7th/cmp-path' +Plug 'hrsh7th/cmp-buffer' + +" See hrsh7th's other plugins for more completion sources! + +" To enable more of the features of rust-analyzer, such as inlay hints and more! +Plug 'simrat39/rust-tools.nvim' + +" Snippet engine +Plug 'hrsh7th/vim-vsnip' + + " support for jsonnet Plug 'google/vim-jsonnet' " groovy syntax and indent @@ -45,8 +69,6 @@ Plug 'vim-scripts/groovyindent-unix' Plug 'Chiel92/vim-autoformat' " taskwarrior Plug 'xarthurx/taskwarrior.vim' -" support for lsp in gnvim -Plug 'vhakulinen/gnvim-lsp' " Wiki support Plug 'vimwiki/vimwiki' " Preferred color scheme diff --git a/rust.vim b/rust.vim new file mode 100644 index 0000000..ef1f6be --- /dev/null +++ b/rust.vim @@ -0,0 +1,79 @@ +" from: https://sharksforarms.dev/posts/neovim-rust/ +" Set completeopt to have a better completion experience +" :help completeopt +" menuone: popup even when there's only one match +" noinsert: Do not insert text until a selection is made +" noselect: Do not select, force user to select one from the menu +set completeopt=menuone,noinsert,noselect + +" Avoid showing extra messages when using completion +set shortmess+=c + +" Configure LSP through rust-tools.nvim plugin. +" rust-tools will configure and enable certain LSP features for us. +" See https://github.com/simrat39/rust-tools.nvim#configuration +lua <'] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Add tab support + [''] = 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.Insert, + select = true, + }) + }, + + -- Installed sources + sources = { + { name = 'nvim_lsp' }, + { name = 'vsnip' }, + { name = 'path' }, + { name = 'buffer' }, + }, +}) +EOF + +" Set updatetime for CursorHold +" 300ms of no cursor movement to trigger CursorHold +set updatetime=300 +" Show diagnostic popup on cursor hold +autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics() diff --git a/syntastic.vim b/syntastic.vim index 0650cbe..a1530dd 100644 --- a/syntastic.vim +++ b/syntastic.vim @@ -4,8 +4,8 @@ let g:syntastic_always_populate_loc_list = 1 " open but only when errors are detected; default closes when errors are cleared " but doesn't open the list automatically -let g:syntastic_auto_loc_list = 1 +let g:syntastic_auto_loc_list = 0 " check when first opening a file -let g:syntastic_check_on_open = 1 +let g:syntastic_check_on_open = 0 " don't check on writing and quitting let g:syntastic_check_on_wq = 0