Update with NeoVim 'init.vim', and news of my move to GNU/Emacs

This commit is contained in:
Anthony J. Martinez 2020-10-23 17:28:12 +02:00
parent 79c9269129
commit 200c3a2739
3 changed files with 163 additions and 3 deletions

3
.vimrc
View File

@ -16,8 +16,6 @@ Plugin 'rust-lang/rust.vim'
Plugin 'vim-scripts/indentpython.vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'vim-syntastic/syntastic'
Plugin 'nvie/vim-flake8'
@ -54,7 +52,6 @@ let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline_theme='jellybeans'
let g:syntastic_python_checkers = ['flake8']
let g:ycm_autoclose_preview_window_after_insertion = 1
" Configuration for splits and split navigation
set splitbelow

View File

@ -8,3 +8,17 @@ integration.
There are not a plethora of keybindings assigned, because I'm rather comfortable with
typing, or just using tab-completion. As time goes on, I'm sure I'll add some more
custom mappings to take care of frequently tab-completed tasks.
### Update:
The .vimrc here had an unexpected consequence. Using vim as much more than an editor
revealed more than a few pitfalls. The most notable among them is vim's poor handling
of long-running tasks. Most apparent while serving as an environment for developing Rust,
this led me, initially, to NeoVim. For the most part NeoVim resolved my issues and offered
reprise from vim's own performance troubles. My resulting NeoVim init.vim is also in this
repository.
The _ultimate_ result of all of this is that I now use [GNU/Emacs](https://www.gnu.org/software/emacs/).
When run with [EVIL](https://github.com/emacs-evil/evil), I will go as far as stating that GNU/Emacs is actually the best version of vim...
Even without EVIL mode enabled, GNU/Emacs is still just a better environment for my work.

149
init.vim Normal file
View File

@ -0,0 +1,149 @@
call plug#begin('~/.vim/plugged')
" Collection of common configurations for the Nvim LSP client
Plug 'neovim/nvim-lspconfig'
" Extensions to built-in LSP, for example, providing type inlay hints
Plug 'tjdevries/lsp_extensions.nvim'
" Autocompletion framework for built-in LSP
Plug 'nvim-lua/completion-nvim'
" Diagnostic navigation and settings for built-in LSP
Plug 'nvim-lua/diagnostic-nvim'
Plug 'dense-analysis/ale'
Plug 'preservim/nerdtree'
Plug 'rust-lang/rust.vim'
Plug 'mattn/webapi-vim'
Plug 'vim-scripts/indentpython.vim'
Plug 'nvie/vim-flake8'
Plug 'tpope/vim-fugitive'
Plug 'vim-airline/vim-airline'
Plug 'itspriddle/vim-shellcheck'
Plug 'vim-airline/vim-airline-themes'
call plug#end()
syntax enable
filetype plugin indent on
" 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
set background=dark encoding=utf-8 number nomodeline hidden wrap linebreak
:colorscheme desert
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline_theme='jellybeans'
" let g:syntastic_python_checkers = ['flake8']
" Configuration for splits and split navigation
set splitbelow
set splitright
" Uppercase the current word in insert mode and move to the
" word end
inoremap <C-U> <esc>viwUei
" Uppercase the current word in normal mode and move to the
" word end
nnoremap <C-U> viwUe<esc>
" General indent rules for files
augroup indentrules
autocmd BufNewFile,BufRead *.js,*.html,*.md,*.css,*.yaml,*.uml setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab fileformat=unix
autocmd Filetype text setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab
autocmd Filetype sql setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
autocmd Filetype c setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
autocmd Filetype cpp setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
augroup END
" Group for nerdtree
augroup nerdtree
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
augroup END
" Configure LSP
" https://github.com/neovim/nvim-lspconfig#rust_analyzer
lua <<EOF
-- nvim_lsp object
local nvim_lsp = require'nvim_lsp'
-- function to attach completion and diagnostics
-- when setting up lsp
local on_attach = function(client)
require'completion'.on_attach(client)
require'diagnostic'.on_attach(client)
end
-- Enable rust_analyzer
nvim_lsp.rust_analyzer.setup({ on_attach=on_attach })
EOF
" Trigger completion with <Tab>
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ completion#trigger_completion()
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
" Code navigation shortcuts
nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gD <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> 1gD <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> gd <cmd>lua vim.lsp.buf.declaration()<CR>
" Visualize diagnostics
let g:diagnostic_enable_virtual_text = 1
let g:diagnostic_trimmed_virtual_text = '40'
" Don't show diagnostics while in insert mode
let g:diagnostic_insert_delay = 1
" 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.util.show_line_diagnostics()
" Goto previous/next diagnostic warning/error
nnoremap <silent> g[ <cmd>PrevDiagnosticCycle<cr>
nnoremap <silent> g] <cmd>NextDiagnosticCycle<cr>
" have a fixed column for the diagnostics to appear in
" this removes the jitter when warnings/errors flow in
set signcolumn=yes
" Enable type inlay hints
autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost *
\ lua require'lsp_extensions'.inlay_hints{ prefix = '', highlight = "Comment" }
" This all came from https://sharksforarms.dev/posts/neovim-rust/