vim-config/init.vim

150 lines
4.5 KiB
VimL
Raw Permalink Normal View History

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/