dotfiles/vimrc

273 lines
7.2 KiB
VimL

set background=dark
syntax on
filetype plugin indent on
let mapleader=','
" netrw
let g:netrw_banner = 0
let g:netrw_liststyle = 1
let g:netrw_list_hide = '^\.'
let g:netrw_winsize=25
map <leader>n <esc>:Lexplore<cr>
" fix helptags for opt/ plugins
" https://vi.stackexchange.com/questions/17210/generating-help-tags-for-packages-that-are-loaded-by-vim-8s-package-management
command! -nargs=0 -bar Helptags
\ for p in glob('~/.vim/pack/git-plugins/opt/*', 1, 1)
\| exe 'packadd ' . fnamemodify(p, ':t')
\| endfor
\| helptags ALL
set shiftwidth=2
set shiftround
set tabstop=2
set expandtab
" set smarttab
set splitbelow
set splitright
set encoding=utf-8
set hidden
set history=1000
set nowrap
set smartindent
set copyindent
set autoindent
set hlsearch
set showmatch
set wildmenu
set wildmode=list:full,full
set number
set relativenumber
set ruler
set backspace=indent,eol,start
set ignorecase
set smartcase
set incsearch
set history=1000
set undolevels=1000
set title
set novisualbell
set noerrorbells
set nobackup
set noswapfile
set ttymouse=sgr
set mouse=a
set mousemodel=popup_setpos
set lazyredraw
set timeoutlen=1000
set ballooneval
set balloonevalterm
set scrolloff=5
set dictionary=/usr/share/dict/words
set shortmess+=I
set updatetime=100
set pastetoggle=<f2>
" See :help thesaurus
set thesaurus=$HOME/Documents/thesaurus/thesaurus_pkg/thesaurus.txt
set pumheight=200
set completeopt=menu,menuone,popup,noselect
set completepopup=width:300,height:50,align:item,border:off
" Enable 24-bit colours.
" https://github.com/alacritty/alacritty/issues/109#issuecomment-440353106
if exists('+termguicolors')
let &t_8f="\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b="\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" Colour scheme:
colorscheme nord
augroup vimrc
autocmd!
" Automatically load/save views on files.
" https://vi.stackexchange.com/posts/13874/revisions
autocmd BufWinLeave,BufLeave,BufWritePost,BufHidden,QuitPre ?* nested silent! mkview!
autocmd BufWinEnter ?* silent! loadview
" set cursor line highlight in insert mode.
autocmd InsertEnter * set cul
autocmd InsertLeavePre * set nocul
augroup end
" But, don't remember the current directory for a given file:
set viewoptions-=curdir
" Key mappings:
nmap <silent> ,/ :nohlsearch<CR>
nnoremap j gj
nnoremap k gk
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
nnoremap <silent> ,/ :nohlsearch<cr>
map <c-t> <esc>:tabnew<cr>
" Select just-pasted text:
nnoremap <silent> <leader>0 `[v`]
nnoremap <silent> <leader>1 :set relativenumber!<cr>
map <leader>m :marks<cr>
map <leader>R :ALERename<cr>
map <leader>v :vsplit<cr>
map <leader>s :split<cr>
map <leader>! <esc>:only<cr>
" ctrl-c to unload a buffer
nnoremap <silent> <c-q> :bp\|bd #<cr>
function! ToggleQuickFix()
if empty(filter(getwininfo(), 'v:val.quickfix'))
copen
else
cclose
endif
endfunction
nmap <silent> <leader>q :call ToggleQuickFix()<cr>
nmap <silent> <leader>l :lclose<cr>
" deoplete configuration
packadd! deoplete.nvim
let g:deoplete#enable_at_startup = 1
call deoplete#custom#option('num_processes', 6)
call deoplete#custom#option('max_list', 50)
call deoplete#custom#option('auto_complete_delay', 10)
call deoplete#custom#option('auto_refresh_delay', 10)
" https://github.com/Shougo/deoplete.nvim/issues/965#issuecomment-482925193
" Seems to be causing autocomplete issues so removing for now.
call deoplete#custom#option('omni_patterns', {
\ 'go': '[^. *\t]\.\w*',
\})
" <TAB>: completion.
inoremap <expr><S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr><Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr><C-]> pumvisible() ? "\<C-]>" : "\<Enter>"
" vim-markdown configuration:
let g:vim_markdown_conceal = 1
" fzf configuration:
nmap <leader>t :GFiles<cr>
nmap <leader>b :Buffers<cr>
nmap <leader>gg :Rg<cr>
" Lightline configuration:
set laststatus=2
" vim-gitgutter configuration
nnoremap hg :GitGutterLineHighlightsToggle<cr>
nmap ]h <Plug>(GitGutterNextHunk)
nmap [h <Plug>(GitGutterPrevHunk)
omap ih <Plug>(GitGutterTextObjectInnerPending)
omap ah <Plug>(GitGutterTextObjectOuterPending)
xmap ih <Plug>(GitGutterTextObjectInnerVisual)
xmap ah <Plug>(GitGutterTextObjectOuterVisual)
" Vim-Rust configuration:
let g:rustfmt_autosave = 1
" echodoc configuration:
set cmdheight=2
let g:echodoc#enable_at_startup = 1
" ALE configuration:
function SymbolSearch()
call inputsave()
let s:pattern = trim(input('symbol search: '))
call inputrestore()
if len(s:pattern) > 0
execute 'ALESymbolSearch' s:pattern
endif
endfunction
map <Leader>ss :call SymbolSearch()<CR>
nmap [L <Plug>(ale_first)
nmap ]L <Plug(ale_last)
nmap [e <Plug>(ale_previous_wrap_error)
nmap ]e <Plug>(ale_next_wrap_error)
nmap [w <Plug>(ale_previous_wrap)
nmap ]w <Plug>(ale_next_wrap)
nmap <leader>ad :ALEDetail<cr>
map <Leader>g :ALEGoToDefinition<CR>
map <Leader>f :ALEFindReferences<CR>
map <Leader>fv :ALEFindReferences -vsplit<CR>
map <Leader>fh :ALEFindReferences -split<CR>
map <Leader>ft :ALEFindReferences -tab<CR>
nnoremap gD :ALEGoToTypeDefinition<cr>
nnoremap gd :ALEGoToDefinition<cr>
command GoToDefinition ALEGoToDefinition
command GoToTypeDefinition ALEGoToTypeDefinition
command FindReferences ALEFindReferences
command Rename ALERename
let g:ale_sign_column_always = 1
let g:ale_fix_on_save = 1
let g:ale_lint_on_text_changed = 1
let g:ale_lint_on_enter = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_echo_cursor = 1
let g:ale_lint_delay = 100
let g:ale_set_balloons = 1
" NOTE: Needs https://github.com/dense-analysis/ale/issues/3350
let g:ale_rust_analyzer_config = {
\ 'diagnostics': { 'disabled': ['unresolved-import'] },
\ 'cargo': { 'loadOutDirsFromCheck': v:true },
\ 'procMacro': { 'enable': v:true },
\ 'checkOnSave': { 'command': 'clippy', 'enable': v:true },
\ }
let g:ale_go_goimports_options = '-local github.com/sensiblecodeio/cantabular'
let g:ale_go_gopls_init_options = {'ui.diagnostic.analyses': {
\ 'composites': v:false,
\ 'unusedparams': v:true,
\ 'unusedresult': v:true,
\ 'shadow': v:true,
\ }}
" let g:ale_command_wrapper = 'nice -n5'
let g:ale_completion_enabled = 0
let g:ale_close_preview_on_insert = 1
let g:ale_hover_to_preview = 1
let g:ale_sign_column_always = 1
let g:ale_history_log_output = 1
let g:ale_linters = {
\ 'javascript': ['eslint'],
\ 'go': ['gopls'],
\ 'rust': ['analyzer'],
\ 'css': ['stylelint'],
\ 'python': ['pyls'],
\ 'ruby': ['rubocop'],
\ }
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'javascript': ['prettier'],
\ 'rust': [],
\ 'go': [],
\ 'css': ['stylelint'],
\ 'python': ['autopep8'],
\ 'ruby': ['rubocop'],
\ }
" load internal plugins:
runtime macros/matchit.vim
" load ALE only after configured:
packadd! ale
" load other plugins:
packadd! echodoc.vim
packadd! lightline.vim
packadd! tmux-complete.vim
packadd! vim-commentary
packadd! vim-gitgutter
" Requires both fzf.vim plugin to be manually installed:
" https://github.com/junegunn/fzf/blob/master/plugin/fzf.vim
" and also this separate plugin, which is loaded here:
packadd! fzf.vim
packadd! vim-go
packadd! vim-surround
packadd! vim-yaml-folds