From aaf687a22552ce87bd8f779fecca87336d8fce2b Mon Sep 17 00:00:00 2001 From: bretello Date: Sun, 6 Dec 2020 02:29:15 +0100 Subject: [PATCH] vim: split config into multiple files --- vim/functions.vim | 87 ++++++++ vim/plugins_config.vim | 142 +++++++++++++ vim/plugs.vim | 67 ++++++ vim/shortcuts.vim | 108 ++++++++++ vim/vimrc | 57 +++++ vimrc | 459 ----------------------------------------- 6 files changed, 461 insertions(+), 459 deletions(-) create mode 100644 vim/functions.vim create mode 100644 vim/plugins_config.vim create mode 100644 vim/plugs.vim create mode 100644 vim/shortcuts.vim create mode 100644 vim/vimrc delete mode 100644 vimrc diff --git a/vim/functions.vim b/vim/functions.vim new file mode 100644 index 0000000..b1dd7e3 --- /dev/null +++ b/vim/functions.vim @@ -0,0 +1,87 @@ +""" 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()set hlsendif +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(''), '\').'\>' + 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 BufcloseCloseIt() +function! 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 diff --git a/vim/plugins_config.vim b/vim/plugins_config.vim new file mode 100644 index 0000000..6aa0c37 --- /dev/null +++ b/vim/plugins_config.vim @@ -0,0 +1,142 @@ +"""" 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"], + \ 'dockerfile': ["hadolint"], + \ '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 = '' +let g:multi_cursor_select_all_word_key = '' +let g:multi_cursor_start_key = 'g' +let g:multi_cursor_select_all_key = 'g' +let g:multi_cursor_next_key = '' +let g:multi_cursor_prev_key = '' +let g:multi_cursor_skip_key = '' +let g:multi_cursor_quit_key = '' + +" indent-guides, toggle with 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 + + +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'] diff --git a/vim/plugs.vim b/vim/plugs.vim new file mode 100644 index 0000000..9a0d12b --- /dev/null +++ b/vim/plugs.vim @@ -0,0 +1,67 @@ +" 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 'https://github.com/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 '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() diff --git a/vim/shortcuts.vim b/vim/shortcuts.vim new file mode 100644 index 0000000..8746660 --- /dev/null +++ b/vim/shortcuts.vim @@ -0,0 +1,108 @@ +"""" Leader shortcuts + + +let mapleader = "," +" also use space as leader +nmap + +nmap w :w! +command! W execute 'w !sudo tee % > /dev/null' edit! +" nmap W :w! + +"Reload vimrc on config change +map e :e! ~/.vimrc +map ` :ALELint +" FIXME: This results in some weird conflict with lightline +autocmd! bufwritepost ~/.vimrc source ~/.vimrc + +" Quickly open a markdown buffer for scribble +map x :e ~/buffer.md +" Toggle paste mode on and off +nmap pp :setlocal paste! + +" open quickfix +nmap cc :botright cope +" close quickfix (also see C below) +nmap cx :hide +nmap co ggVGy:tabnew:set syntax=qfpgg +" next cope error +map cn :cn +" previous cope error +map cp :cp + +map :noh "disable highlighting for current word +map ss :setlocal spell! + +nnoremap mk :bel copensilent (cargo run) !redraw! +nnoremap wz :call WinZoomToggle() + +nmap \ :Explore +nnoremap C :close +nnoremap B :Bclose +nnoremap k :Ack + +"" Fugitive +nnoremap / :Git +nnoremap g :Git +nnoremap gd :Git diff +nnoremap gp :Git push +nnoremap M :Git commit +nnoremap gpf :Git push --force-with-lease + +"" Gitutter +nnoremap u :GitGutterBufferToggle +nnoremap L :GitGutterLineHighlightsToggle +nmap hn (GitGutterNextHunk) +nmap hp (GitGutterPrevHunk) + +"" Ale +nmap (ale_previous_wrap) +nmap (ale_next_wrap) +nmap sv :ALEGoToDefinition -vsplit +nmap sh :ALEGoToDefinition -split +nmap st :ALEGoToDefinition -tab +nmap A :ALEGoToDefinition +nmap n :ALEFindReferences +nmap h :ALEHover +nmap r :ALERename + +" call ack when pressing gv in visual +vnoremap gv :call VisualSelection('gv', '') + +map nn :NERDTreeToggle +map o :BufExplorer + +"" CtrlP +" Quickly find and open a recently opened file +" let g:ctrlp_map = '' +map :CtrlPBuffer +map j :CtrlP +map b :CtrlPBuffer +map f :CtrlPMRUFiles +map t :CtrlPTag + + +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", @") + nnoremap "+p :let @"=substitute(system("wl-paste --no-newline"), '', '', 'g')p + xnoremap "*y :call system("wl-copy --primary", @") + nnoremap "*p :let @"=substitute(system("wl-paste --no-newline --primary"), '', '', 'g')p +else + "" Unkown platform +endif + +" Add shortcuts to yank/paste to unnamed/unnamedplus clipboards +noremap y "*y +noremap p "*p +noremap Y "+y +noremap P "+p + + +" A friggin python breakpoint. Invoke with @b "FIXME: make this decent +let @b = 'A breakpoint()€ýajkj0' diff --git a/vim/vimrc b/vim/vimrc new file mode 100644 index 0000000..1e55485 --- /dev/null +++ b/vim/vimrc @@ -0,0 +1,57 @@ +" Install all plugins +source $DOTFILES/vim/plugs.vim + +" Sanity +set encoding=utf-8 +scriptencoding utf-8 + +" 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 +cnoremap +cnoremap + +cnoremap +cnoremap + +try + set undodir=~/.vim/temp_dirs/undodir + set undofile +catch +endtry + +source $DOTFILES/vim/plugins_config.vim +source $DOTFILES/vim/shortcuts.vim +source $DOTFILES/vim/functions.vim diff --git a/vimrc b/vimrc deleted file mode 100644 index bbb5909..0000000 --- a/vimrc +++ /dev/null @@ -1,459 +0,0 @@ -" 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 -cnoremap -cnoremap - -cnoremap -cnoremap - -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"], - \ 'dockerfile': ["hadolint"], - \ '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 = '' -let g:multi_cursor_select_all_word_key = '' -let g:multi_cursor_start_key = 'g' -let g:multi_cursor_select_all_key = 'g' -let g:multi_cursor_next_key = '' -let g:multi_cursor_prev_key = '' -let g:multi_cursor_skip_key = '' -let g:multi_cursor_quit_key = '' - -" indent-guides, toggle with 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 - -nmap w :w! -command! W execute 'w !sudo tee % > /dev/null' edit! -" nmap W :w! - -"Reload vimrc on config change -map e :e! ~/.vimrc -map ` :ALELint -" FIXME: This results in some weird conflict with lightline -autocmd! bufwritepost ~/.vimrc source ~/.vimrc - -" Quickly open a markdown buffer for scribble -map x :e ~/buffer.md -" Toggle paste mode on and off -nmap pp :setlocal paste! - -" open quickfix -nmap cc :botright cope -" close quickfix (also see C below) -nmap cx :hide -nmap co ggVGy:tabnew:set syntax=qfpgg -" next cope error -map cn :cn -" previous cope error -map cp :cp - -map :noh "disable highlighting for current word -map ss :setlocal spell! - -nnoremap mk :bel copensilent (cargo run) !redraw! -nnoremap wz :call WinZoomToggle() - -nmap \ :Explore -nnoremap C :close -nnoremap B :Bclose -nnoremap k :Ack - -"" Fugitive -nnoremap / :Git -nnoremap g :Git -nnoremap gd :Git diff -nnoremap gp :Git push -nnoremap M :Git commit -nnoremap gpf :Git push --force-with-lease - -"" Gitutter -nnoremap u :GitGutterBufferToggle -nnoremap L :GitGutterLineHighlightsToggle -nmap hn (GitGutterNextHunk) -nmap hp (GitGutterPrevHunk) - -"" Ale -nmap (ale_previous_wrap) -nmap (ale_next_wrap) -nmap sv :ALEGoToDefinition -vsplit -nmap sh :ALEGoToDefinition -split -nmap st :ALEGoToDefinition -tab -nmap A :ALEGoToDefinition -nmap n :ALEFindReferences -nmap h :ALEHover -nmap r :ALERename - -" call ack when pressing gv in visual -vnoremap gv :call VisualSelection('gv', '') - -map nn :NERDTreeToggle -map o :BufExplorer - -"" CtrlP -" Quickly find and open a recently opened file -" let g:ctrlp_map = '' -map :CtrlPBuffer -map j :CtrlP -map b :CtrlPBuffer -map f :CtrlPMRUFiles -map t :CtrlPTag - - -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", @") - nnoremap "+p :let @"=substitute(system("wl-paste --no-newline"), '', '', 'g')p - xnoremap "*y :call system("wl-copy --primary", @") - nnoremap "*p :let @"=substitute(system("wl-paste --no-newline --primary"), '', '', 'g')p -else - "" Unkown platform -endif - -" Add shortcuts to yank/paste to unnamed/unnamedplus clipboards -noremap y "*y -noremap p "*p -noremap Y "+y -noremap 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()set hlsendif -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(''), '\').'\>' - 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 BufcloseCloseIt() -function! 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