diff --git a/nvim.configlink/coc-settings.json b/nvim.configlink/coc-settings.json new file mode 100644 index 0000000..bb3cf94 --- /dev/null +++ b/nvim.configlink/coc-settings.json @@ -0,0 +1,4 @@ +{ + "rust-analyzer.serverPath": "/usr/local/bin/rust-analyzer", + "rust-analyzer.checkOnSave.enable": true +} diff --git a/nvim.configlink/init.vim b/nvim.configlink/init.vim index 8e68507..cd796c7 100644 --- a/nvim.configlink/init.vim +++ b/nvim.configlink/init.vim @@ -17,7 +17,6 @@ Plug 'morhetz/gruvbox' " Colorscheme Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " Required for fuzzyfinder Plug 'junegunn/fzf.vim' " Actual fuzzyfinder Plug 'tpope/vim-surround' " Enables paren editing -Plug 'tmsvg/pear-tree' " Auto- and smart-parentheses Plug 'tpope/vim-commentary' " Use gc or gcc to comment Plug 'sheerun/vim-polyglot' " Syntax for every language Plug 'vimwiki/vimwiki' " Wiki Markdown System @@ -40,6 +39,7 @@ set termguicolors " Set to truecolor colorscheme gruvbox " Installed in autoload/ and colors/ " Options +set hidden " Don't unload buffers when leaving them set number " Show line numbers set relativenumber " Relative numbers instead of absolute set list " Reveal whitespace with --- @@ -54,6 +54,7 @@ set scrolljump=1 " Scroll more than one line (or 1 line) set scrolloff=3 " Margin of lines when scrolling set pastetoggle= " Use F3 to enter paste mode set clipboard+=unnamedplus " Uses system clipboard for yanking +set updatetime=300 " Faster diagnostics " Neovim only set inccommand=split " Live preview search and replace @@ -97,32 +98,96 @@ nnoremap :noh nnoremap / :Rg " Open file in this directory -nnoremap f :Files +nnoremap ff :Files " Open a recent file -nnoremap r :History +nnoremap fr :History " Switch between multiple open files -nnoremap b :Buffers +nnoremap bb :Buffers " Jump to text in this file nnoremap s :BLines " Start Magit buffer -nnoremap g :Magit +nnoremap gs :Magit " Toggle Git gutter (by line numbers) nnoremap ` :GitGutterToggle " Git push -nnoremap p :Git push +nnoremap gp :Git push " Close all other splits -nnoremap m :only +nnoremap wm :only " Open file tree noremap t :Fern . -drawer -width=35 -toggle= +" CoC Settings +"------------- + +let g:coc_global_extensions = ['coc-rust-analyzer', 'coc-pairs'] + +" Set tab to completion +inoremap + \ pumvisible() ? "\" : + \ check_back_space() ? "\" : + \ coc#refresh() +inoremap pumvisible() ? "\" : "\" + +function! s:check_back_space() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' +endfunction + +inoremap pumvisible() ? coc#_select_confirm() + \: "\u\\=coc#on_enter()\" + +" 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 show_documentation() + +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('') + else + call CocAction('doHover') + endif +endfunction + +" Highlight the symbol and its references when holding the cursor. +" Uses updatetime for delay before showing info. +autocmd CursorHold * silent call CocActionAsync('highlight') + +" Symbol renaming. +nmap rn (coc-rename) + +" Applying codeAction to the selected region. +" Example: `aap` for current paragraph +xmap a (coc-codeaction-selected) +nmap a (coc-codeaction-selected) + +" Remap keys for applying codeAction to the current buffer. +nmap ac (coc-codeaction) +" Apply AutoFix to problem on the current line. +nmap qf (coc-fix-current) + +" Use CTRL-S for selections ranges. +" Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver +nmap (coc-range-select) +xmap (coc-range-select) + " Plugin Settings "---------------- @@ -133,17 +198,12 @@ let g:netrw_winsize = 15 " Explore window takes % of page let g:netrw_browse_split = 4 " Open in previous window let g:netrw_altv = 1 " Always split left -" Pear Tree parentheses plugin -let g:pear_tree_repeatable_expand = 0 " Don't hide paren until escape -let g:pear_tree_smart_openers = 1 " Smart paren mode, which checks outer or inners -let g:pear_tree_smart_closers = 1 -let g:pear_tree_smart_backspace = 1 - " Gitgutter plugin -let g:gitgutter_enabled = 0 " Disable on start +let g:gitgutter_enabled = 1 " Enabled on start " Polyglot syntax plugin let g:terraform_fmt_on_save=1 " Formats with terraform plugin +let g:rustfmt_autosave = 1 " Formats with rust plugin " VimWiki plugin let g:vimwiki_list = [ @@ -160,9 +220,13 @@ let g:lightline = { \ 'active': { \ 'right': [[ 'lineinfo' ]], \ 'left': [[ 'mode', 'paste' ], - \ [ 'readonly', 'relativepath', 'gitbranch', 'modified' ]] + \ [ 'cocstatus', 'readonly', 'relativepath', 'gitbranch', 'modified' ]] \ }, \ 'component_function': { - \ 'gitbranch': 'fugitive#head' - \ } + \ 'gitbranch': 'fugitive#head', + \ 'cocstatus': 'coc#status' + \ }, \ } + +" Use autocmd to force lightline update. +autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()