mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-12-22 23:31:32 +01:00
7f053fcb8e
- abandon amix's vimrc (thanks for all the fish) - use vim-plug (https://github.com/junegunn/vim-plug) to manage plugins - move config from `my_configs.vim` to `vimrc` - update install script accordingly
459 lines
14 KiB
VimL
459 lines
14 KiB
VimL
" Sanity
|
||
set encoding=utf-8
|
||
scriptencoding utf-8
|
||
|
||
" Install vim-plug if not installed already (requires curl)
|
||
if empty(glob('~/.vim/autoload/plug.vim'))
|
||
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
|
||
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
|
||
autocmd VimEnter * PlugInstall --sync | source ~/.vimrc
|
||
endif
|
||
|
||
" Plugins
|
||
call plug#begin('~/.vim/vim-plug')
|
||
" Basic vim config
|
||
Plug 'tpope/vim-sensible'
|
||
" Colorscheme
|
||
Plug 'https://github.com/morhetz/gruvbox'
|
||
" Asynchronous Linting Engine
|
||
Plug 'https://github.com/dense-analysis/ale'
|
||
" Open files/recent files/tags quickly
|
||
Plug 'https://github.com/ctrlpvim/ctrlp.vim'
|
||
" Git
|
||
Plug 'https://github.com/tpope/vim-fugitive'
|
||
" Comment shit easily
|
||
Plug 'https://github.com/tpope/vim-commentary'
|
||
" Browse file system
|
||
Plug 'https://github.com/scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
|
||
" Minimal status line
|
||
Plug 'https://github.com/itchyny/lightline.vim'
|
||
" Lightline status for ALE
|
||
Plug 'maximbaz/lightline-ale'
|
||
" Insert parentheses in pairs
|
||
Plug 'https://github.com/jiangmiao/auto-pairs'
|
||
Plug 'https://github.com/amix/open_file_under_cursor.vim'
|
||
" Multi cursor
|
||
Plug 'https://github.com/mg979/vim-visual-multi'
|
||
" Easily explore open buffers
|
||
Plug 'https://github.com/vim-scripts/bufexplorer.zip'
|
||
" Search
|
||
Plug 'https://github.com/mileszs/ack.vim'
|
||
" Yank history
|
||
Plug 'https://github.com/maxbrunsfeld/vim-yankstack'
|
||
" Mark indentation level
|
||
Plug 'nathanaelkane/vim-indent-guides'
|
||
|
||
" snipmate
|
||
Plug 'https://github.com/MarcWeber/vim-addon-mw-utils'
|
||
Plug 'https://github.com/tomtom/tlib_vim'
|
||
Plug 'https://github.com/garbas/vim-snipmate'
|
||
|
||
" Git gutter line
|
||
Plug 'https://github.com/airblade/vim-gitgutter'
|
||
" Zero distractions
|
||
Plug 'https://github.com/junegunn/goyo.vim'
|
||
|
||
" Highlight lines not covered by tests
|
||
Plug 'https://github.com/mgedmin/coverage-highlight.vim'
|
||
|
||
"Languages
|
||
Plug 'https://github.com/rust-lang/rust.vim'
|
||
Plug 'https://github.com/vim-scripts/nginx.vim'
|
||
Plug 'https://github.com/plasticboy/vim-markdown'
|
||
Plug 'https://github.com/altercation/vim-colors-solarized'
|
||
|
||
Plug 'epheien/termdbg'
|
||
|
||
" No RGB, no party
|
||
let vim_razer = expand('~/projects_razer/vim-razer')
|
||
if isdirectory(vim_razer)
|
||
Plug vim_razer
|
||
endif
|
||
call plug#end()
|
||
|
||
" Style
|
||
set background=dark
|
||
colorscheme gruvbox
|
||
|
||
" General stuff
|
||
set nowrap
|
||
set mouse=a
|
||
set relativenumber number
|
||
set foldlevelstart=3 foldmethod=syntax nofoldenable "without nofoldenable all folds are closed at startup"
|
||
set ttymouse=xterm2 " fix mouse when used in tmux/byobu https://unix.stackexchange.com/q/50733
|
||
|
||
set nobackup nowb noswapfile " no need for backups of every file
|
||
set history=10000
|
||
|
||
set list listchars=tab:›\ ,trail:•,extends:#,nbsp:.
|
||
|
||
set splitbelow splitright
|
||
set autoread
|
||
" Don't redraw while executing macros (good performance config)
|
||
set lazyredraw
|
||
|
||
set ignorecase smartcase " ignore case on search but be smart about it
|
||
set hlsearch "highlight search results (using *)
|
||
|
||
set shiftwidth=4 tabstop=4
|
||
autocmd FileType yaml,yml setlocal shiftwidth=2 softtabstop=2 expandtab
|
||
|
||
" Return to last edit position when opening files (from amix's vimrc)
|
||
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
|
||
|
||
" Remap VIM 0 to first non-blank character
|
||
" map 0 ^
|
||
|
||
" Bash like keys for the command line
|
||
cnoremap <C-A> <Home>
|
||
cnoremap <C-E> <End>
|
||
cnoremap <C-K> <C-U>
|
||
|
||
cnoremap <C-P> <Up>
|
||
cnoremap <C-N> <Down>
|
||
|
||
try
|
||
set undodir=~/.vim/temp_dirs/undodir
|
||
set undofile
|
||
catch
|
||
endtry
|
||
|
||
|
||
"""" PLUGINS CONFIGURATION
|
||
let g:ack_default_options = " --cc --cpp --shell --python --html --js --vue"
|
||
|
||
" ALE configuration
|
||
let g:ale_set_balloons = 1 " enable tooltips
|
||
let g:ale_fixers = {
|
||
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
|
||
\ 'bash': ['shfmt'],
|
||
\ 'json': ['prettier'],
|
||
\ 'cpp': ['clang-format'],
|
||
\ 'css': ['prettier'],
|
||
\ 'html': ['prettier'],
|
||
\ 'markdown': ['prettier'],
|
||
\ 'java': ['eclipselsp'],
|
||
\ 'yaml': ['prettier'],
|
||
\ 'python': ['black', 'isort'],
|
||
\ 'go': ['gofmt', "goimports"],
|
||
\ 'rust': ['rustfmt'],
|
||
\ "javascript": ["prettier", "eslint"],
|
||
\ "vue": ["prettier", "eslint"]
|
||
\}
|
||
let g:ale_fixers_aliases = {'vue': ['vue', 'javascript']}
|
||
|
||
let g:ale_python_bandit_options = "-c banditrc"
|
||
" let g:ale_python_pylint_options = "--rcfile pylintrc --disable=W0511" " if the rcfile does not exist, pylint will exit without linting
|
||
let g:ale_python_pylint_options = "--disable=W0511"
|
||
let g:ale_cpp_clang_options = '-std=c++17 -Wall -Wpedantic'
|
||
let g:ale_cpp_gcc_options = '-std=c++17 -Wall -Wpedantic'
|
||
|
||
let g:ale_linters = {
|
||
\ 'bash': ['bashlint', "shellcheck"],
|
||
\ 'zsh': ['bashlint', "shellcheck"],
|
||
\ 'python': ['pyls', 'pylint', 'bandit'],
|
||
\ 'go': ['gopls', 'gobuild'],
|
||
\ 'rust': ['analyzer', 'rustc'],
|
||
\ 'yaml': ['yamllint'],
|
||
\ 'javascript': ["yarn lint", "eslint", "vls"]
|
||
\}
|
||
let g:ale_linter_aliases = {'vue': ['vue', 'javascript']}
|
||
|
||
let g:ale_set_quickfix=1
|
||
let g:ale_set_loclist=0
|
||
let g:ale_open_list = 0
|
||
let g:ale_keep_list_window_open = 1
|
||
|
||
let g:ale_lint_on_save = 1
|
||
" let g:ale_lint_on_enter = 0 " uncomment if you do not want to lint files on open
|
||
let g:ale_lint_on_insert_leave = 1
|
||
" let g:ale_lint_on_text_changed = 1
|
||
let g:ale_lint_delay = 2500 " lint 2.5 seconds after text has changed
|
||
let g:ale_fix_on_save = 1
|
||
let g:ale_completion_enabled = 1
|
||
" let g:ale_completion_autoimport = 1
|
||
|
||
let g:ale_sign_priority = 99
|
||
let g:ale_sign_error = "xx"
|
||
let g:ale_sign_warning = ">>"
|
||
let g:ale_sign_info = "--"
|
||
"let g:ale_sign_style_error =
|
||
"let g:ale_sign_style_warning =
|
||
|
||
packadd termdebug "useless shit
|
||
|
||
" Fix some gitgutter stuff
|
||
let g:gitgutter_enabled = 1
|
||
let g:gitgutter_sign_allow_clobber = 0 " do not allow gitgutter to overwrite signs
|
||
let g:gitgutter_sign_priority = 50
|
||
" let g:gitgutter_set_sign_backgrounds = 1
|
||
" let g:gitgutter_override_sign_column_highlight = 0
|
||
|
||
" highlight clear GitGutterAdd GitGutterChange GitGutterModified GitGutterDelete SignColumn
|
||
highlight SignColumn ctermbg=none
|
||
|
||
highlight GitGutterAdd ctermbg=none ctermfg=2
|
||
highlight GitGutterChange ctermbg=none ctermfg=3
|
||
highlight GitGutterDelete ctermbg=none ctermfg=1
|
||
highlight GitGutterChangeDelete ctermbg=none ctermfg=1
|
||
|
||
let g:gitgutter_sign_added = '+'
|
||
let g:gitgutter_sign_modified = '~'
|
||
let g:gitgutter_sign_modified_removed = 'x'
|
||
|
||
" Improve vimdiff colors (deprecated, this was useful for the twilight256 colorscheme)
|
||
" highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
|
||
" highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
|
||
" highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
|
||
" highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red
|
||
|
||
" Lightline config from amix's vimrc " TODO: this could be improved
|
||
let g:lightline = {
|
||
\ 'colorscheme': 'wombat',
|
||
\ 'active': {
|
||
\ 'left': [ ['mode', 'paste'],
|
||
\ ['fugitive', 'readonly', 'filename', 'modified'] ],
|
||
\ 'right': [ [ 'lineinfo' ], ['percent'] ]
|
||
\ },
|
||
\ 'component': {
|
||
\ 'readonly': '%{&filetype=="help"?"":&readonly?"¿":""}',
|
||
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}',
|
||
\ 'fugitive': '%{exists("*FugitiveHead")?FugitiveHead():""}'
|
||
\ },
|
||
\ 'component_visible_condition': {
|
||
\ 'readonly': '(&filetype!="help"&& &readonly)',
|
||
\ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))',
|
||
\ 'fugitive': '(exists("*FugitiveHead") && ""!=FugitiveHead())'
|
||
\ },
|
||
\ 'separator': { 'left': ' ', 'right': ' ' },
|
||
\ 'subseparator': { 'left': ' ', 'right': ' ' }
|
||
\ }
|
||
|
||
let g:lightline.component_expand = {
|
||
\ 'linter_checking': 'lightline#ale#checking',
|
||
\ 'linter_infos': 'lightline#ale#infos',
|
||
\ 'linter_warnings': 'lightline#ale#warnings',
|
||
\ 'linter_errors': 'lightline#ale#errors',
|
||
\ 'linter_ok': 'lightline#ale#ok',
|
||
\ }
|
||
|
||
" These are the default mappings for vim-multi-cursor
|
||
let g:multi_cursor_start_word_key = '<C-n>'
|
||
let g:multi_cursor_select_all_word_key = '<A-n>'
|
||
let g:multi_cursor_start_key = 'g<C-n>'
|
||
let g:multi_cursor_select_all_key = 'g<A-n>'
|
||
let g:multi_cursor_next_key = '<C-n>'
|
||
let g:multi_cursor_prev_key = '<C-p>'
|
||
let g:multi_cursor_skip_key = '<C-x>'
|
||
let g:multi_cursor_quit_key = '<Esc>'
|
||
|
||
" indent-guides, toggle with <leader>ig
|
||
let g:indent_guides_enable_on_vim_startup = 0
|
||
let g:indent_guides_exclude_filetypes = ['help', 'terminal', 'nerdtree']
|
||
let g:indent_guides_start_level = 2
|
||
let g:indent_guides_guide_size = 1
|
||
|
||
|
||
"""" Leader shortcuts
|
||
let mapleader = ","
|
||
" also use space as leader
|
||
nmap <Space> <leader>
|
||
|
||
nmap <leader>w :w!<CR>
|
||
command! W execute 'w !sudo tee % > /dev/null' <bar> edit!
|
||
" nmap <leader>W :w!<CR>
|
||
|
||
"Reload vimrc on config change
|
||
map <leader>e :e! ~/.vimrc<CR>
|
||
map <leader>` :ALELint<CR>
|
||
" FIXME: This results in some weird conflict with lightline
|
||
autocmd! bufwritepost ~/.vimrc source ~/.vimrc
|
||
|
||
" Quickly open a markdown buffer for scribble
|
||
map <leader>x :e ~/buffer.md<CR>
|
||
" Toggle paste mode on and off
|
||
nmap <leader>pp :setlocal paste!<CR>
|
||
|
||
" open quickfix
|
||
nmap <leader>cc :botright cope<CR>
|
||
" close quickfix (also see <leader>C below)
|
||
nmap <leader>cx :hide<CR>
|
||
nmap <leader>co ggVGy:tabnew<CR>:set syntax=qf<CR>pgg
|
||
" next cope error
|
||
map <leader>cn :cn<CR>
|
||
" previous cope error
|
||
map <leader>cp :cp<CR>
|
||
|
||
map <silent> <leader><CR> :noh<CR> "disable highlighting for current word
|
||
map <leader>ss :setlocal spell!<CR>
|
||
|
||
nnoremap <leader>mk :bel copen<bar>silent (cargo run) !<bar>redraw!<CR>
|
||
nnoremap <leader>wz :call WinZoomToggle()<CR>
|
||
|
||
nmap \ :Explore<CR>
|
||
nnoremap <leader>C :close<CR>
|
||
nnoremap <leader>B :Bclose<CR>
|
||
nnoremap <leader>k :Ack<Space>
|
||
|
||
"" Fugitive
|
||
nnoremap <leader>/ :Git<CR>
|
||
nnoremap <leader>g :Git<CR>
|
||
nnoremap <leader>gd :Git diff<CR>
|
||
nnoremap <leader>gp :Git push<CR>
|
||
nnoremap <leader>M :Git commit<CR>
|
||
nnoremap <leader>gpf :Git push --force-with-lease<CR>
|
||
|
||
"" Gitutter
|
||
nnoremap <leader>u :GitGutterBufferToggle<CR>
|
||
nnoremap <leader>L :GitGutterLineHighlightsToggle<CR>
|
||
nmap <leader>hn <Plug>(GitGutterNextHunk)
|
||
nmap <leader>hp <Plug>(GitGutterPrevHunk)
|
||
|
||
"" Ale
|
||
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
|
||
nmap <silent> <C-j> <Plug>(ale_next_wrap)
|
||
nmap <leader>sv :ALEGoToDefinition -vsplit<CR>
|
||
nmap <leader>sh :ALEGoToDefinition -split<CR>
|
||
nmap <leader>st :ALEGoToDefinition -tab<CR>
|
||
nmap <leader>A :ALEGoToDefinition<CR>
|
||
nmap <leader>n :ALEFindReferences<CR>
|
||
nmap <leader>h :ALEHover<CR>
|
||
nmap <leader>r :ALERename<CR>
|
||
|
||
" call ack when pressing gv in visual
|
||
vnoremap <silent> gv :call VisualSelection('gv', '')<CR>
|
||
|
||
map <leader>nn :NERDTreeToggle<CR>
|
||
map <leader>o :BufExplorer<CR>
|
||
|
||
"" CtrlP
|
||
" Quickly find and open a recently opened file
|
||
" let g:ctrlp_map = '<C-f>'
|
||
map <C-b> :CtrlPBuffer<CR>
|
||
map <leader>j :CtrlP<CR>
|
||
map <leader>b :CtrlPBuffer<CR>
|
||
map <leader>f :CtrlPMRUFiles<CR>
|
||
map <leader>t :CtrlPTag<CR>
|
||
|
||
|
||
let s:uname=''
|
||
let s:uname = system('uname | tr -d "\n"') " Get platform name (stripping the trailing newline)
|
||
if s:uname == "Darwin"
|
||
"" Mac specific stuff
|
||
elseif s:uname == "linux"
|
||
"" Linux specific stuff
|
||
" Wayland clipboard fix https://github.com/vim/vim/issues/5157
|
||
xnoremap "+y :call system("wl-copy", @")<CR>
|
||
nnoremap "+p :let @"=substitute(system("wl-paste --no-newline"), '<C-v><C-m>', '', 'g')<cr>p
|
||
xnoremap "*y :call system("wl-copy --primary", @")<CR>
|
||
nnoremap "*p :let @"=substitute(system("wl-paste --no-newline --primary"), '<C-v><C-m>', '', 'g')<cr>p
|
||
else
|
||
"" Unkown platform
|
||
endif
|
||
|
||
" Add shortcuts to yank/paste to unnamed/unnamedplus clipboards
|
||
noremap <Leader>y "*y
|
||
noremap <Leader>p "*p
|
||
noremap <Leader>Y "+y
|
||
noremap <Leader>P "+p
|
||
|
||
|
||
let g:ctrlp_custom_ignore = {
|
||
\ 'dir': '\v(target|build|dist|.venv)$',
|
||
\ 'file': '\v\.(exe|so|dll)$',
|
||
\ 'link': 'some_bad_symbolic_links',
|
||
\ }
|
||
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
|
||
|
||
" A friggin python breakpoint. Invoke with @b "FIXME: make this decent
|
||
let @b = 'A
|
||
breakpoint()ýajkj0'
|
||
|
||
|
||
""" Helper Functions
|
||
function! WinZoomToggle() abort
|
||
if ! exists('w:WinZoomIsZoomed')
|
||
let w:WinZoomIsZoomed = 0
|
||
endif
|
||
if w:WinZoomIsZoomed == 0
|
||
let w:WinZoomOldWidth = winwidth(0)
|
||
let w:WinZoomOldHeight = winheight(0)
|
||
wincmd _
|
||
wincmd |
|
||
let w:WinZoomIsZoomed = 1
|
||
elseif w:WinZoomIsZoomed == 1
|
||
execute "resize " . w:WinZoomOldHeight
|
||
execute "vertical resize " . w:WinZoomOldWidth
|
||
let w:WinZoomIsZoomed = 0
|
||
endif
|
||
endfunction
|
||
|
||
|
||
" Highlight all instances of word under cursor, when idle.
|
||
" Type z/ to toggle highlighting on/off.
|
||
nnoremap z/ :if AutoHighlightToggle()<Bar>set hls<Bar>endif<CR>
|
||
function! AutoHighlightToggle()
|
||
let @/ = ''
|
||
if exists('#auto_highlight')
|
||
au! auto_highlight
|
||
augroup! auto_highlight
|
||
setl updatetime=4000
|
||
echo 'Highlight current word: off'
|
||
return 0
|
||
else
|
||
augroup auto_highlight
|
||
au!
|
||
au CursorHold * let @/ = '\V\<'.escape(expand('<cword>'), '\').'\>'
|
||
augroup end
|
||
setl updatetime=500
|
||
echo 'Highlight current word: ON'
|
||
return 1
|
||
endif
|
||
endfunction
|
||
|
||
" Don't close window, when deleting a buffer
|
||
command! Bclose call <SID>BufcloseCloseIt()
|
||
function! <SID>BufcloseCloseIt()
|
||
let l:currentBufNum = bufnr("%")
|
||
let l:alternateBufNum = bufnr("#")
|
||
|
||
if buflisted(l:alternateBufNum)
|
||
buffer #
|
||
else
|
||
bnext
|
||
endif
|
||
|
||
if bufnr("%") == l:currentBufNum
|
||
new
|
||
endif
|
||
|
||
if buflisted(l:currentBufNum)
|
||
execute("bdelete! ".l:currentBufNum)
|
||
endif
|
||
endfunction
|
||
|
||
function! CmdLine(str)
|
||
call feedkeys(":" . a:str)
|
||
endfunction
|
||
|
||
function! VisualSelection(direction, extra_filter) range
|
||
let l:saved_reg = @"
|
||
execute "normal! vgvy"
|
||
|
||
let l:pattern = escape(@", "\\/.*'$^~[]")
|
||
let l:pattern = substitute(l:pattern, "\n$", "", "")
|
||
|
||
if a:direction == 'gv'
|
||
call CmdLine("Ack '" . l:pattern . "' " )
|
||
elseif a:direction == 'replace'
|
||
call CmdLine("%s" . '/'. l:pattern . '/')
|
||
endif
|
||
|
||
let @/ = l:pattern
|
||
let @" = l:saved_reg
|
||
endfunction
|
||
|
||
function! GitStatus()
|
||
let [a,m,r] = GitGutterGetHunkSummary()
|
||
return printf('+%d ~%d -%d', a, m, r)
|
||
endfunction
|