dotfiles/vimrc

344 lines
10 KiB
VimL
Raw Normal View History

2021-01-27 14:24:24 +00:00
set background=dark
2020-06-26 12:19:50 +00:00
syntax on
filetype plugin indent on
2021-02-25 12:49:17 +00:00
let mapleader=','
2020-12-29 07:02:41 +00:00
2021-01-06 13:34:33 +00:00
" netrw
2020-12-29 07:02:41 +00:00
let g:netrw_banner = 0
let g:netrw_liststyle = 1
let g:netrw_list_hide = '^\.'
2021-01-06 13:34:33 +00:00
let g:netrw_winsize=25
map <leader>n <esc>:Lexplore<cr>
2020-06-26 12:19:50 +00:00
2021-01-28 19:23:15 +00:00
" 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
2020-06-26 12:19:50 +00:00
set shiftwidth=2
set shiftround
2021-02-02 11:37:36 +00:00
set tabstop=2
2020-06-26 12:19:50 +00:00
set expandtab
2021-03-17 06:34:50 +00:00
set smarttab
2021-01-12 12:49:38 +00:00
set splitbelow
set splitright
2020-06-26 12:19:50 +00:00
set encoding=utf-8
set hidden
2021-01-06 13:34:33 +00:00
set history=1000
2020-06-26 12:19:50 +00:00
set nowrap
set smartindent
set copyindent
set autoindent
set hlsearch
set showmatch
2020-12-18 12:49:36 +00:00
set wildmenu
2021-01-24 15:46:40 +00:00
set wildmode=list:full,full
2020-06-26 12:19:50 +00:00
set number
2021-02-22 09:45:05 +00:00
set relativenumber
2020-06-26 12:19:50 +00:00
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
2020-12-29 07:02:41 +00:00
set ttymouse=sgr
2020-06-26 12:19:50 +00:00
set mouse=a
2020-12-29 07:02:41 +00:00
set mousemodel=popup_setpos
2021-04-01 07:20:52 +00:00
" https://github.com/tpope/vim-sensible/issues/78:
2020-06-26 12:19:50 +00:00
set lazyredraw
2021-02-22 09:45:05 +00:00
set timeoutlen=1000
2020-12-29 07:02:41 +00:00
set ballooneval
set balloonevalterm
2021-03-17 06:34:50 +00:00
set scrolloff=15
2021-02-22 09:45:05 +00:00
set dictionary=/usr/share/dict/words
2021-01-06 13:34:33 +00:00
set shortmess+=I
2021-03-17 06:34:50 +00:00
set updatetime=250
2021-01-12 12:49:38 +00:00
set pastetoggle=<f2>
2021-01-06 13:34:33 +00:00
" See :help thesaurus
set thesaurus=$HOME/Documents/thesaurus/thesaurus_pkg/thesaurus.txt
2021-01-27 14:24:24 +00:00
set pumheight=200
2021-03-08 08:34:00 +00:00
set completeopt=menu,menuone,popup,noselect
2021-01-27 14:24:24 +00:00
set completepopup=width:300,height:50,align:item,border:off
2021-04-01 07:20:52 +00:00
set complete-=i
set nrformats-=octal
set ttimeout
set ttimeoutlen=100
set formatoptions+=j
set autoread
2020-06-26 12:19:50 +00:00
2021-03-12 09:37:10 +00:00
" 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
2020-06-26 12:19:50 +00:00
" Colour scheme:
2021-03-31 09:53:33 +00:00
packadd! nord-vim " https://github.com/arcticicestudio/nord-vim.git
2021-03-21 15:10:06 +00:00
colorscheme nord
2021-03-19 07:08:57 +00:00
2021-02-25 12:49:17 +00:00
augroup vimrc
2021-01-12 12:49:38 +00:00
autocmd!
2021-02-25 12:49:17 +00:00
" Automatically load/save views on files.
" https://vi.stackexchange.com/posts/13874/revisions
2021-01-12 12:49:38 +00:00
autocmd BufWinLeave,BufLeave,BufWritePost,BufHidden,QuitPre ?* nested silent! mkview!
autocmd BufWinEnter ?* silent! loadview
2021-02-25 12:49:17 +00:00
" set cursor line highlight in insert mode.
autocmd InsertEnter * set cul
autocmd InsertLeavePre * set nocul
2021-03-17 06:34:50 +00:00
" use tabs in .gitconfig
2021-03-18 08:05:37 +00:00
autocmd BufEnter .gitconfig setlocal shiftwidth=2 tabstop=2 noexpandtab
2021-03-18 12:30:30 +00:00
" Quickfix window is always full-width.
" https://github.com/fatih/vim-go/issues/1757#issuecomment-565130503
autocmd FileType qf if (getwininfo(win_getid())[0].loclist != 1) | wincmd J | endif
2021-01-12 12:49:38 +00:00
augroup end
2021-02-25 12:49:17 +00:00
2021-03-24 14:19:54 +00:00
" Don't remember the current directory for a given file:
2021-02-04 07:38:27 +00:00
set viewoptions-=curdir
set viewoptions-=options
2021-04-01 07:20:52 +00:00
set sessionoptions-=options
2020-06-26 12:19:50 +00:00
" Key mappings:
2021-02-17 03:54:06 +00:00
nnoremap j gj
nnoremap k gk
2020-06-26 12:19:50 +00:00
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
2021-01-17 08:30:47 +00:00
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
2021-03-17 06:34:50 +00:00
nmap ]q :cn<cr>
nmap [q :cp<cr>
2021-01-17 08:30:47 +00:00
2021-03-26 08:34:54 +00:00
nnoremap <silent> <leader>/ :nohlsearch<cr>
2021-03-24 14:19:54 +00:00
nnoremap <silent> <leader><space> :nohlsearch<cr>
2020-06-26 12:19:50 +00:00
" Select just-pasted text:
2021-01-28 19:23:15 +00:00
nnoremap <silent> <leader>0 `[v`]
2021-03-26 16:24:46 +00:00
" Select just-pasted text and re-indent:
nnoremap <silent> <leader>) `[v`]=
2021-01-28 19:23:15 +00:00
nnoremap <silent> <leader>1 :set relativenumber!<cr>
2021-03-24 14:19:54 +00:00
nnoremap <leader>m :marks<cr>
nnoremap <leader>v :vsplit<cr>
nnoremap <leader>s :split<cr>
" <leader>a* currently conflicts with LspCodeAction
nnoremap <leader>ab :Gblame<cr>
nnoremap <leader>as :Gstatus<cr>
nnoremap <leader>ac :Commits<cr>
nnoremap <leader>ah :GitGutterLineHighlightsToggle<cr>
2021-03-24 08:16:09 +00:00
" yank filename of current buffer:
nmap <leader>f :let @" = expand("%")<cr>
" and into + register:
nmap <leader>F :let @+ = expand("%")<cr>
2021-01-06 13:34:33 +00:00
function! ToggleQuickFix()
if empty(filter(getwininfo(), 'v:val.quickfix'))
copen
else
cclose
endif
endfunction
2021-02-23 12:42:59 +00:00
nmap <silent> <leader>q :call ToggleQuickFix()<cr>
2021-02-22 18:46:23 +00:00
nmap <silent> <leader>l :lclose<cr>
2020-06-26 12:19:50 +00:00
packadd! async.vim " https://github.com/prabirshrestha/async.vim.git
packadd! asyncomplete.vim " https://github.com/prabirshrestha/asyncomplete.vim.git
packadd! asyncomplete-lsp.vim " https://github.com/prabirshrestha/asyncomplete-lsp.vim.git
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr> pumvisible() ? asyncomplete#close_popup() . "\<cr>" : "\<cr>"
2021-01-17 09:14:53 +00:00
2020-12-30 08:47:55 +00:00
" vim-markdown configuration:
2021-01-17 08:30:47 +00:00
let g:vim_markdown_conceal = 1
2020-06-26 12:19:50 +00:00
2021-03-09 19:40:10 +00:00
" fzf configuration:
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit' }
2021-03-15 15:29:40 +00:00
nmap <leader>t :Files<cr>
nmap <leader>T :GFiles<cr>
2021-03-09 18:34:35 +00:00
nmap <leader>b :Buffers<cr>
2021-03-09 19:40:10 +00:00
nmap <leader>gg :Rg<cr>
2020-06-26 12:19:50 +00:00
" Lightline configuration:
2021-03-31 09:53:33 +00:00
packadd! lightline.vim " https://github.com/itchyny/lightline.vim.git
2021-03-21 20:30:20 +00:00
set laststatus=2
function! LightlineLSPErrorText()
let l:info = lsp#get_buffer_diagnostics_counts()
if info.error == 0
return ''
endif
let sign = get(g:lsp_diagnostics_signs_error, 'text', 'E')
return info.error . sign
endfunction
function! LightlineLSPWarningText()
let l:info = lsp#get_buffer_diagnostics_counts()
if info.warning == 0
return ''
endif
let sign = get(g:lsp_diagnostics_signs_warning, 'text', 'W')
return info.warning . sign
2021-03-19 07:11:11 +00:00
endfunction
2021-03-18 19:57:37 +00:00
let g:lightline = {
\ 'colorscheme': 'seoul256',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ],
\ [ 'gitbranch' ], ['lsperror', 'lspwarn'] ],
2021-03-18 19:57:37 +00:00
\ 'right': [ ['lineinfo'], ['percent'], ['filetype'], ['gobuild'] ],
\ },
\ 'component_function': {
\ 'gobuild': 'go#statusline#Show',
2021-03-21 20:30:20 +00:00
\ 'gitbranch': 'FugitiveStatusline',
2021-03-18 19:57:37 +00:00
\ },
\ 'component_expand': {
\ 'lsperror': 'LightlineLSPErrorText',
\ 'lspwarn': 'LightlineLSPWarningText',
\ },
\ 'component_type': {
\ 'lsperror': 'error',
\ 'lspwarn': 'warning',
\ },
2021-03-19 01:31:37 +00:00
\ 'mode_map': {
\ 'n' : 'N',
\ 'i' : 'I',
\ 'R' : 'R',
\ 'v' : 'V',
\ 'V' : 'V-LINE',
\ "\<C-v>": 'V-BLOCK',
\ 'c' : 'C',
\ 's' : 'S',
\ 'S' : 'S-LINE',
\ "\<C-s>": 'S-BLOCK',
\ 't': 'TERM',
\ },
2021-03-18 19:57:37 +00:00
\ }
2020-06-26 12:19:50 +00:00
2021-01-28 08:21:55 +00:00
" vim-gitgutter configuration
2021-03-31 09:53:33 +00:00
packadd! vim-gitgutter " https://github.com/airblade/vim-gitgutter.git
2021-03-19 01:31:37 +00:00
set signcolumn=yes
2021-01-28 08:21:55 +00:00
nmap ]h <Plug>(GitGutterNextHunk)
nmap [h <Plug>(GitGutterPrevHunk)
2021-03-11 13:35:44 +00:00
omap ih <Plug>(GitGutterTextObjectInnerPending)
omap ah <Plug>(GitGutterTextObjectOuterPending)
xmap ih <Plug>(GitGutterTextObjectInnerVisual)
xmap ah <Plug>(GitGutterTextObjectOuterVisual)
2021-01-28 08:21:55 +00:00
" vim-fugitive
2021-03-31 09:53:33 +00:00
packadd! vim-fugitive " https://github.com/tpope/vim-fugitive.git
" vim-go
2021-03-24 14:19:54 +00:00
" Doesn't work in after/ftplugin/go.vim:
let g:go_def_mapping_enabled = 0
2021-03-31 09:53:33 +00:00
packadd! vim-go " https://github.com/fatih/vim-go.git
" LSP configuration:
2021-03-31 09:53:33 +00:00
packadd! vim-lsp " https://github.com/prabirshrestha/vim-lsp.git
packadd! vim-lsp-settings " https://github.com/mattn/vim-lsp-settings.git
let g:lsp_settings = {
\ 'gopls': {
\ 'initialization_options': {
\ 'ui.diagnostic.analyses': {
\ 'composites': v:false,
\ 'unusedparams': v:true,
\ 'unusedresult': v:true,
\ 'shadow': v:true,
2021-03-22 08:11:12 +00:00
\ 'nilness': v:true,
\ 'unusedwrite': v:true,
\ },
\ 'staticcheck': v:true,
2021-03-29 19:11:17 +00:00
\ 'hoverKind': 'FullDocumentation',
2021-03-22 08:11:12 +00:00
\ 'linksInHover': v:false,
2021-03-23 06:46:31 +00:00
\ 'experimentalWorkspaceModule': v:false,
\ }}}
let g:lsp_diagnostics_float_cursor = 1
2021-03-26 08:34:54 +00:00
let g:lsp_diagnostics_float_delay = 175
let g:lsp_diagnostics_highlight_delay = 175
let g:lsp_diagnostics_signs_delay = 175
let g:lsp_diagnostics_code_action_signs_delay = 175
2021-03-21 20:39:18 +00:00
let g:lsp_document_highlight_delay = 500
2021-03-24 20:00:25 +00:00
let g:lsp_async_completion = 1
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
2021-03-21 20:30:20 +00:00
" number may be clobbered by vim-fugitive?
setlocal number
2021-03-22 08:11:12 +00:00
setlocal signcolumn=yes
" Jump to definitions
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gvd :vertical :LspDefinition<cr>
nmap <buffer> gsd :belowright :LspDefinition<cr>
nmap <buffer> gD <plug>(lsp-type-definition)
nmap <buffer> gvD :vertical :LspTypeDefinition<cr>
nmap <buffer> gsD :belowright :LspTypeDefinition<cr>
" Map to leader keys too, easy typo:
nmap <buffer> <leader>gd <plug>(lsp-definition)
nmap <buffer> <leader>gD <plug>(lsp-type-definition)
" Peek definitions, only on leader keys
nmap <buffer> <leader>pd <plug>(lsp-peek-definition)
nmap <buffer> <leader>pD <plug>(lsp-peek-type-definition)
" Navigation
nmap <buffer> <silent> ]e <plug>(lsp-next-error)
nmap <buffer> <silent> [e <plug>(lsp-previous-error)
nmap <buffer> <silent> ]d <plug>(lsp-next-diagnostic)
nmap <buffer> <silent> [d <plug>(lsp-previous-diagnostic)
nmap <buffer> <silent> ]r <plug>(lsp-next-reference)
nmap <buffer> <silent> [r <plug>(lsp-previous-reference)
" Misc actions
nmap <buffer> <leader>ci <plug>(lsp-call-hierarchy-incoming)
nmap <buffer> <leader>co <plug>(lsp-call-hierarchy-outgoing)
2021-03-26 16:24:46 +00:00
nmap <buffer> <leader>ca <plug>(lsp-code-action)
nmap <buffer> <leader>i <plug>(lsp-implementation)
nmap <buffer> <leader>r <plug>(lsp-references)
nmap <buffer> <leader>d <plug>(lsp-hover)
2021-03-26 16:24:46 +00:00
nmap <buffer> <leader>o :silent LspCodeAction source.organizeImports<cr>
nmap <buffer> <leader>e <plug>(lsp-rename)
endfunction
augroup lsp_install
au!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
autocmd User lsp_diagnostics_updated call lightline#update()
2021-03-24 14:19:54 +00:00
autocmd BufWritePre *.go silent LspDocumentFormatSync
" autocmd CursorHold <buffer> silent LspHover
augroup END
2020-12-29 07:02:41 +00:00
2021-01-19 08:54:13 +00:00
" load internal plugins:
runtime macros/matchit.vim
" load other plugins:
2021-03-31 09:53:33 +00:00
packadd! rust.vim " https://github.com/rust-lang/rust.vim.git
packadd! tmux-complete.vim " https://github.com/wellle/tmux-complete.vim.git
packadd! vim-commentary " https://github.com/tpope/vim-commentary.git
2021-03-09 19:40:10 +00:00
" Requires both fzf.vim plugin to be manually installed:
" https://github.com/junegunn/fzf/blob/master/plugin/fzf.vim
2021-03-09 18:34:35 +00:00
" and also this separate plugin, which is loaded here:
2021-03-31 09:53:33 +00:00
packadd! fzf.vim " https://github.com/junegunn/fzf.vim.git
packadd! vim-surround " https://github.com/tpope/vim-surround.git
packadd! vim-rhubarb " https://github.com/tpope/vim-rhubarb.git
packadd! editorconfig-vim " https://github.com/editorconfig/editorconfig-vim.git