From e66a0080a14a28b7bc4170e41273b0bee3450b66 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Wed, 19 Apr 2023 12:41:24 -0400 Subject: [PATCH] Update neovim config --- home/.config/nvim/coc-settings.json | 23 +++ home/.config/nvim/init.vim | 190 ++++++++++++++++++++++++- home/.config/nvim/setup-coc.vim | 160 +++++++++++++++++++++ home/.config/nvim/setup-rust-tools.lua | 10 ++ 4 files changed, 381 insertions(+), 2 deletions(-) create mode 100644 home/.config/nvim/coc-settings.json create mode 100644 home/.config/nvim/setup-coc.vim create mode 100644 home/.config/nvim/setup-rust-tools.lua diff --git a/home/.config/nvim/coc-settings.json b/home/.config/nvim/coc-settings.json new file mode 100644 index 0000000..aa32c89 --- /dev/null +++ b/home/.config/nvim/coc-settings.json @@ -0,0 +1,23 @@ +{ + "languageserver": { + "rust": { + "command": "rust-analyzer", + "filetypes": ["rust"], + "rootPatterns": ["Cargo.toml"] + }, + "erlang": { + "command": "erlang_ls", + "filetypes": ["erlang"] + }, + "ocaml-lsp": { + "command": "opam", + "args": ["config", "exec", "--", "ocamllsp"], + "filetypes": ["ocaml", "reason"] + } + }, + "bash": { + "command": "bash-language-server", + "args": ["start"], + "filetypes": ["sh"] + } +} diff --git a/home/.config/nvim/init.vim b/home/.config/nvim/init.vim index 39affba..7399d15 100644 --- a/home/.config/nvim/init.vim +++ b/home/.config/nvim/init.vim @@ -1,8 +1,194 @@ -set nu +"============================================================================== +" Plugins +"============================================================================== + +" BEGIN Vim-Plug (https://github.com/junegunn/vim-plug) +" Run :PlugInstall after adding a new plugin +call plug#begin() + +Plug 'dense-analysis/ale' " Syntastic's spiritual succesor +Plug 'preservim/nerdtree' +"Plug 'nvim-tree/nvim-web-devicons' " Needs patched fonts: https://www.nerdfonts.com/ +Plug 'phha/zenburn.nvim' +Plug 'itchyny/lightline.vim' +Plug 'numToStr/Comment.nvim' +Plug 'rust-lang/rust.vim' +Plug 'neoclide/coc.nvim', {'branch': 'release'} +" Plug 'neovim/nvim-lspconfig' + +" Plug 'hrsh7th/cmp-nvim-lsp', {'branch': 'main'} +" Plug 'hrsh7th/cmp-buffer', {'branch': 'main'} +" Plug 'hrsh7th/cmp-path', {'branch': 'main'} +" Plug 'hrsh7th/nvim-cmp', {'branch': 'main'} +" +" " Only because nvim-cmp _requires_ snippets +" Plug 'hrsh7th/cmp-vsnip', {'branch': 'main'} +" Plug 'hrsh7th/vim-vsnip' + +" Plug 'simrat39/rust-tools.nvim' + +call plug#end() +" END Vim-Plug + +lua require('Comment').setup() +" luafile ~/.config/nvim/setup-rust-tools.lua +"luafile ~/.config/nvim/setup-lsp-rust-jonhoo.lua +source ~/.config/nvim/setup-coc.vim + +" NERDTree +let NERDTreeShowLineNumbers=1 + +"============================================================================== +" Defaults +"============================================================================== + +"------------------------------------------------------------------------------ +" General +"------------------------------------------------------------------------------ +set nocompatible " Because plain vi is a bit annoying +set nu " Line numbers in gutter +"set rnu " Relative number. relativenumber rnu norelativenumber nornu +set ruler " Line and column numbers in status +set splitright splitbelow " Split window order +set bs=2 " Enable backspace key +set history=1000 " Bump history from default of 20 +set modeline +set modelines=3 +set ttimeoutlen=100 " Reduce delay when addinng libe above ("O") +"set fileformats=unix +filetype on +filetype plugin on +set mouse=a " To scroll Coc tooltips. https://github.com/neoclide/coc.nvim/issues/1405 +set spellfile=~/.vim/spell/en.utf-8.add +set spelllang=en,ru + +" lightline +set laststatus=2 +set noshowmode +let g:lightline = {'colorscheme': 'seoul256'} + +"------------------------------------------------------------------------------ +" Color +"------------------------------------------------------------------------------ set t_Co=256 syntax enable set background=dark colorscheme zenburn + +au TextYankPost * lua vim.highlight.on_yank {higroup="IncSearch", timeout=250, on_visual=true, on_macro=true} + +"hi Normal guibg=NONE " Transparency +"hi Normal ctermbg=NONE " Transparency + +"------------------------------------------------------------------------------ +" Search +"------------------------------------------------------------------------------ +set hlsearch +set incsearch +set noignorecase +set smartcase + +"------------------------------------------------------------------------------ +" Text format / indentation +"------------------------------------------------------------------------------ +filetype indent on +set autoindent +set smartindent +set expandtab +set tabstop=8 +set softtabstop=4 +set shiftwidth=4 +set textwidth=0 " What is the point of this again? Prevent auto-wrapping? + +"------------------------------------------------------------------------------ +" Code folding +"------------------------------------------------------------------------------ +set foldmethod=indent +set nofoldenable + +"------------------------------------------------------------------------------ +" Style enforcement +"------------------------------------------------------------------------------ +" Lines too-long let &colorcolumn=join(range(80,80),",") +"match ErrorMsg '\%>79v.\+' + match ErrorMsg '\s\+$' " Trailing whitespace -set termguicolors +"2match ErrorMsg '\t' " Tabs + +" TODO: How to match more than 2 things? 3match is reserved for brackets. + +"============================================================================== +" Per FileType overrides +"============================================================================== + +" C +autocmd FileType c set noexpandtab | set shiftwidth=8 | set tabstop=8 | set softtabstop=8 + +" TypeScript +autocmd FileType typescript set noexpandtab | set shiftwidth=8 | set tabstop=8 | set softtabstop=8 + +" R +autocmd FileType r set tabstop=2 | set softtabstop=2 | set shiftwidth=2 + +" Python +autocmd FileType python set omnifunc=pythoncomplete#Complete + +" Git commit +autocmd FileType gitcommit set spell + +" Markdown +"autocmd FileType markdown set spell +autocmd FileType markdown set expandtab | set tabstop=2 | set softtabstop=2 | set shiftwidth=2 + +" HTML +autocmd FileType html set spell + +" MediaWiki +autocmd FileType mediawiki set spell +autocmd FileType mediawiki set tabstop=2 | set softtabstop=2 | set shiftwidth=2 + +" Tiger +autocmd BufNewFile,BufRead *.tig set filetype=tiger + +" SML +autocmd BufNewFile,BufRead *.sig set filetype=sml + +" Mathematica +autocmd BufNewFile,BufRead *.m set filetype=mma +autocmd BufNewFile,BufRead *.mt set filetype=mma +autocmd FileType mma set tabstop=2 | set softtabstop=2 | set shiftwidth=2 + +" F# +autocmd FileType fsharp set tabstop=4 | set softtabstop=4 | set shiftwidth=4 + +" twtxt.txt +autocmd BufNewFile,BufRead twtxt.txt set filetype=conf | set noexpandtab + +" Scheme +autocmd FileType scheme set tabstop=2 | set softtabstop=2 | set shiftwidth=2 + +" Racket +autocmd FileType racket setlocal equalprg=scmindent.rkt +"autocmd FileType racket setlocal equalprg=raco\ fmt + +" Erlang +"autocmd FileType erlang setlocal equalprg=erlfmt +autocmd FileType erlang set tabstop=4 | set softtabstop=4 | set shiftwidth=4 + +" ----------------------------------------------------------------------------- +" TypeScript +" ----------------------------------------------------------------------------- +"let g:tsuquyomi_completion_detail = 1 +"let g:tsuquyomi_use_local_typescript = 0 +"let g:syntastic_typescript_checkers = ['tsuquyomi'] + +" ----------------------------------------------------------------------------- +" Racket +" ----------------------------------------------------------------------------- +let g:syntastic_enable_racket_racket_checker = 0 + +" ----------------------------------------------------------------------------- +" OCaml +" ----------------------------------------------------------------------------- +autocmd FileType ocaml set tabstop=2 | set softtabstop=2 | set shiftwidth=2 diff --git a/home/.config/nvim/setup-coc.vim b/home/.config/nvim/setup-coc.vim new file mode 100644 index 0000000..c93a57d --- /dev/null +++ b/home/.config/nvim/setup-coc.vim @@ -0,0 +1,160 @@ +" May need for Vim (not Neovim) since coc.nvim calculates byte offset by count +" utf-8 byte sequence +" set encoding=utf-8 +" Some servers have issues with backup files, see #649 +set nobackup +set nowritebackup + +" Having longer updatetime (default is 4000 ms = 4s) leads to noticeable +" delays and poor user experience +set updatetime=300 + +" Always show the signcolumn, otherwise it would shift the text each time +" diagnostics appear/become resolved +set signcolumn=yes + +" Use tab for trigger completion with characters ahead and navigate +" NOTE: There's always complete item selected by default, you may want to enable +" no select by `"suggest.noselect": true` in your configuration file +" NOTE: Use command ':verbose imap ' to make sure tab is not mapped by +" other plugin before putting this into your config +inoremap + \ coc#pum#visible() ? coc#pum#next(1) : + \ CheckBackspace() ? "\" : + \ coc#refresh() +inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" + +" Make to accept selected completion item or notify coc.nvim to format +" u breaks current undo, please make your own choice +inoremap coc#pum#visible() ? coc#pum#confirm() + \: "\u\\=coc#on_enter()\" + +function! CheckBackspace() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' +endfunction + +" Use to trigger completion +if has('nvim') + inoremap coc#refresh() +else + inoremap coc#refresh() +endif + +" Use `[g` and `]g` to navigate diagnostics +" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list +nmap [g (coc-diagnostic-prev) +nmap ]g (coc-diagnostic-next) + +" GoTo code navigation +nmap gd (coc-definition) +nmap gy (coc-type-definition) +nmap gi (coc-implementation) +nmap gr (coc-references) + +" Use K to show documentation in preview window +nnoremap K :call ShowDocumentation() + +function! ShowDocumentation() + if CocAction('hasProvider', 'hover') + call CocActionAsync('doHover') + else + call feedkeys('K', 'in') + endif +endfunction + +" Highlight the symbol and its references when holding the cursor +autocmd CursorHold * silent call CocActionAsync('highlight') + +" Symbol renaming +nmap rn (coc-rename) + +" Formatting selected code +xmap f (coc-format-selected) +nmap f (coc-format-selected) + +augroup mygroup + autocmd! + " Setup formatexpr specified filetype(s) + autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') + " Update signature help on jump placeholder + autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') +augroup end + +" Applying code actions to the selected code block +" Example: `aap` for current paragraph +xmap a (coc-codeaction-selected) +nmap a (coc-codeaction-selected) + +" Remap keys for applying code actions at the cursor position +nmap ac (coc-codeaction-cursor) +" Remap keys for apply code actions affect whole buffer +nmap as (coc-codeaction-source) +" Apply the most preferred quickfix action to fix diagnostic on the current line +nmap qf (coc-fix-current) + +" Remap keys for applying refactor code actions +nmap re (coc-codeaction-refactor) +xmap r (coc-codeaction-refactor-selected) +nmap r (coc-codeaction-refactor-selected) + +" Run the Code Lens action on the current line +nmap cl (coc-codelens-action) + +" Map function and class text objects +" NOTE: Requires 'textDocument.documentSymbol' support from the language server +xmap if (coc-funcobj-i) +omap if (coc-funcobj-i) +xmap af (coc-funcobj-a) +omap af (coc-funcobj-a) +xmap ic (coc-classobj-i) +omap ic (coc-classobj-i) +xmap ac (coc-classobj-a) +omap ac (coc-classobj-a) + +" Remap and to scroll float windows/popups +if has('nvim-0.4.0') || has('patch-8.2.0750') + nnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" + nnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" + inoremap coc#float#has_scroll() ? "\=coc#float#scroll(1)\" : "\" + inoremap coc#float#has_scroll() ? "\=coc#float#scroll(0)\" : "\" + vnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" + vnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" +endif + +" Use CTRL-S for selections ranges +" Requires 'textDocument/selectionRange' support of language server +nmap (coc-range-select) +xmap (coc-range-select) + +" Add `:Format` command to format current buffer +command! -nargs=0 Format :call CocActionAsync('format') + +" Add `:Fold` command to fold current buffer +command! -nargs=? Fold :call CocAction('fold', ) + +" Add `:OR` command for organize imports of the current buffer +command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport') + +" Add (Neo)Vim's native statusline support +" NOTE: Please see `:h coc-status` for integrations with external plugins that +" provide custom statusline: lightline.vim, vim-airline +set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} + +" Mappings for CoCList +" Show all diagnostics +nnoremap a :CocList diagnostics +" Manage extensions +nnoremap e :CocList extensions +" Show commands +nnoremap c :CocList commands +" Find symbol of current document +nnoremap o :CocList outline +" Search workspace symbols +nnoremap s :CocList -I symbols +" Do default action for next item +nnoremap j :CocNext +" Do default action for previous item +nnoremap k :CocPrev +" Resume latest coc list +nnoremap p :CocListResume diff --git a/home/.config/nvim/setup-rust-tools.lua b/home/.config/nvim/setup-rust-tools.lua new file mode 100644 index 0000000..54d3b05 --- /dev/null +++ b/home/.config/nvim/setup-rust-tools.lua @@ -0,0 +1,10 @@ +require("rust-tools").setup({ + server = { + on_attach = function(_, bufnr) + -- Hover actions + -- vim.keymap.set("n", "", rt.hover_actions.hover_actions, { buffer = bufnr }) + -- Code action groups + -- vim.keymap.set("n", "a", rt.code_action_group.code_action_group, { buffer = bufnr }) + end, + }, +}) -- 2.20.1