vimrc (34383B)
1 " vim: foldmethod=marker foldlevel=0 2 let mapleader=" " " Set the mapleader to be space 3 4 " Plugins {{{1 5 " Installation {{{2 6 " Install vim-plug if needed 7 if empty(glob('~/.vim/autoload/plug.vim')) 8 silent execute "!curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" 9 autocmd VimEnter * PlugInstall | source $MYVIMRC 10 endif 11 12 call plug#begin('~/.vim/plugged') 13 Plug 'pearofducks/ansible-vim' 14 " To get documentation on vim-plug 15 Plug 'junegunn/vim-plug' 16 17 " Vim tester 18 Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' } 19 20 " A color table with xterm color codes 21 Plug 'guns/xterm-color-table.vim' 22 23 " Faster HTML 24 Plug 'mattn/emmet-vim', { 'for': ['html', 'css', 'markdown'] } 25 26 " Endwise - smart do-end, if-fi, if-end, case-esac, etc. 27 Plug 'tpope/vim-endwise' 28 29 " Surround - super useful plugin for surrounding stuff with quotes/brackets/tags 30 Plug 'tpope/vim-surround' 31 32 " Eunuch - shell commands but in vim 33 Plug 'tpope/vim-eunuch' 34 35 " Project management 36 Plug 'tpope/vim-projectionist' 37 38 " Git wrapper from tpope 39 Plug 'tpope/vim-fugitive' 40 41 " Repeat everything with '.' 42 Plug 'tpope/vim-repeat' 43 44 " Distraction-free editing 45 Plug 'junegunn/goyo.vim' 46 Plug 'junegunn/limelight.vim' 47 48 " Disable hlsearch after finished searching 49 Plug 'romainl/vim-cool' 50 51 " Vim + latex 52 Plug 'lervag/vimtex' 53 54 " Better abbrevation and substitution 55 Plug 'tpope/vim-abolish' 56 57 " Highlight hex colors 58 Plug 'chrisbra/colorizer', { 'on': 'ColorHighlight' } 59 60 " Bracket bindings for filetypes 61 Plug 'arp242/jumpy.vim' 62 63 " Omnifuncs 64 Plug 'myhere/vim-nodejs-complete', { 'for': 'js' } 65 Plug 'othree/html5.vim', { 'for': 'html' } 66 Plug 'vim-scripts/OmniCppComplete', { 'for': 'cpp' } 67 Plug 'vim-scripts/pythoncomplete', { 'for': 'python' } 68 69 " Peek contents of registers 70 Plug 'junegunn/vim-peekaboo' 71 72 " Latex symbol to unicode 73 Plug 'joom/latex-unicoder.vim' 74 75 " Asynchronous popery 76 Plug 'tpope/vim-dispatch' 77 78 " Vimscript testing 79 Plug 'tpope/vim-scriptease', { 'on': ['Breakadd', 'Runtime'] } 80 81 " Set 'path', 'suffixesadd', 'include', 'includeexpr', 'define' 82 " automatically for selected filetypes. 83 Plug 'tpope/vim-apathy' 84 85 " Schemer - colorscheme creator 86 Plug 'thezeroalpha/vim-schemer' 87 88 " Make ins-completion relative to current file 89 Plug 'thezeroalpha/vim-relatively-complete' 90 91 " Run visually selected lines as Vim commands 92 Plug 'thezeroalpha/vim-visualrun' 93 94 " Select files with LF 95 Plug 'thezeroalpha/vim-lf' 96 97 " Literate programming in Markdown 98 Plug 'thezeroalpha/vim-literate-markdown' 99 100 " Lightweight REPL 101 Plug 'axvr/zepl.vim' 102 103 " Center the window vertically (like Goyo but keeps statusline/whatever) 104 Plug 'jmckiern/vim-venter', { 'on': 'Venter' } 105 106 " Edit files directly in quickfix window 107 Plug 'stefandtw/quickfix-reflector.vim' 108 109 " Minesweeper 110 Plug 'iqxd/vim-mine-sweeping' 111 112 " Rust 113 Plug 'rust-lang/rust.vim', { 'for': 'rust' } 114 115 " Fuzzy finder in vim 116 Plug 'junegunn/fzf', { 'dir': '$DOTFILES/tools/fzf', 'do': './install --all --xdg --no-fish'} 117 Plug 'junegunn/fzf.vim' 118 119 Plug 'mbbill/undotree' 120 121 " Hide long links 122 Plug 'qadzek/link.vim' 123 124 " Vim-only 125 if !has('nvim') 126 " Smooth ^U/^D scrolling 127 Plug 'psliwka/vim-smoothie' 128 129 " Alignment 130 Plug 'junegunn/vim-easy-align' 131 132 " A tag overview on the right side 133 Plug 'majutsushi/tagbar' 134 135 " Substitute preview 136 Plug 'markonm/traces.vim' 137 138 Plug 'dense-analysis/ale' 139 140 " Show git changes in the sign column 141 Plug 'airblade/vim-gitgutter' 142 143 Plug 'Yggdroot/indentLine', { 'for': 'python' } 144 145 " Simple commenting 146 Plug 'tpope/vim-commentary' 147 148 " Display ANSI color codes 149 Plug 'vim-scripts/AnsiEsc.vim', { 'on': 'AnsiEsc' } 150 151 " Additional text objects 152 Plug 'wellle/targets.vim' 153 endif 154 call plug#end() 155 156 " quickfix filtering 157 packadd cfilter 158 159 if !has('nvim') 160 " matchit.vim is default, why not enable it 161 packadd matchit 162 endif 163 164 " }}}2 165 " Config {{{2 166 " Say {{{3 167 let g:say_wpm = 230 168 nmap gs <Plug>Say 169 vmap gs <Plug>Say 170 nmap gsl <Plug>SayLine 171 nmap gss <Plug>SayBuffer 172 " Tagbar {{{3 173 " Maps 174 nnoremap <leader>tt :TagbarToggle<CR> 175 nnoremap <leader>to :TagbarOpen fj<CR> 176 177 " tagbar language definitions 178 let g:tagbar_type_go = { 179 \ 'ctagstype' : 'go', 180 \ 'kinds' : [ 181 \ 'p:package', 182 \ 'i:imports:1', 183 \ 'c:constants', 184 \ 'v:variables', 185 \ 't:types', 186 \ 'n:interfaces', 187 \ 'w:fields', 188 \ 'e:embedded', 189 \ 'm:methods', 190 \ 'r:constructor', 191 \ 'f:functions' 192 \ ], 193 \ 'sro' : '.', 194 \ 'kind2scope' : { 195 \ 't' : 'ctype', 196 \ 'n' : 'ntype' 197 \ }, 198 \ 'scope2kind' : { 199 \ 'ctype' : 't', 200 \ 'ntype' : 'n' 201 \ }, 202 \ 'ctagsbin' : 'gotags', 203 \ 'ctagsargs' : '-sort -silent' 204 \ } 205 let g:tagbar_type_scss = { 206 \ 'ctagstype' : 'scss', 207 \ 'kinds' : [ 208 \ 'm:Mixins', 209 \ 'f:Functions', 210 \ 'v:Variables', 211 \ 'c:Classes', 212 \ 'i:IDs', 213 \ 't:Tags', 214 \ 'd:Media', 215 \ 'p:Placeholders' 216 \ ], 217 \ 'sort': 0 218 \ } 219 let g:tagbar_type_conf = { 220 \ 'ctagstype' : 'lfrc', 221 \ 'kinds' : [ 222 \ 'c:Commands', 223 \ 'm:Maps' 224 \ ], 225 \ 'sort': 0 226 \ } 227 let g:tagbar_type_zsh = { 228 \ 'ctagstype' : 'zsh', 229 \ 'kinds' : [ 230 \ 's:Source scripts', 231 \ 'e:Environment variables', 232 \ 'f:Functions', 233 \ 'm:Mappings' 234 \ ], 235 \ 'sort': 0 236 \ } 237 " Doge {{{3 238 let g:doge_mapping = '<leader>gd' 239 " Goyo {{{3 240 let g:goyo_width = "80%" 241 let g:goyo_height = "85%" 242 " Vimtex {{{3 243 let g:vimtex_view_automatic=0 244 let g:vimtex_quickfix_open_on_warning = 0 245 let g:vimtex_quickfix_ignore_filters = [ '[Ww]arning', '\(Under\|Over\)full', 'Missing ".* in' ] 246 let g:tex_flavor='latex' 247 let g:vimtex_toc_config = { 248 \ 'todo_sorted': 0, 249 \ 'show_help': 0 250 \ } 251 let g:vimtex_view_method='sioyek' 252 let g:vimtex_view_sioyek_exe='/Applications/sioyek.app/Contents/MacOS/sioyek' 253 let g:vimtex_syntax_custom_cmds = [ 254 \ {'name': 'fullref', 'argspell': 0}, 255 \ {'name': 'citea', 'argspell': 0}, 256 \ {'name': 'citen', 'argspell': 0, 'arggreedy': 1}, 257 \ {'name': 'citet', 'argspell': 0, 'arggreedy': 1} 258 \ ] 259 let g:vimtex_complete_ref = { 260 \ 'custom_patterns': ['\\fullref\*\?{[^}]*'] 261 \ } 262 let g:vimtex_complete_bib = { 263 \ 'custom_patterns': ['\\citen\*\?{[^}]*}{[^}]*', 264 \ '\\citea\*\?{[^}]*'] 265 \ } 266 let g:tex_comment_nospell=1 267 let g:vimtex_syntax_nospell_comments=1 268 let g:vimtex_quickfix_mode=0 269 let g:tex_conceal='abdmg' 270 let g:vimtex_compiler_enabled = 1 271 let g:vimtex_compiler_method='latexmk' 272 let g:vimtex_compiler_latexmk = { 273 \ 'callback' : 1, 274 \ 'continuous' : 1, 275 \ 'executable' : 'latexmk', 276 \ 'hooks' : [], 277 \ 'options' : [ 278 \ '-verbose', 279 \ '-file-line-error', 280 \ '-synctex=1', 281 \ '-interaction=nonstopmode', 282 \ ], 283 \} 284 let g:vimtex_compiler_tectonic = { 285 \ 'build_dir' : 'build', 286 \ 'callback' : 1, 287 \ 'options' : [ 288 \ '--keep-logs', 289 \ '--synctex', 290 \ '--keep-intermediates' 291 \ ], 292 \} 293 " Abolish {{{3 294 " Work with variants of words easily 295 let g:abolish_save_file = $HOME.."/.dotfiles/vim/abolish_save_file.vim" 296 " Fzf {{{3 297 set rtp+="$HOME"/.dotfiles/tools/fzf 298 function! s:build_quickfix_list(lines) 299 call setqflist(map(copy(a:lines), '{ "filename": v:val }')) 300 copen 301 cc 302 endfunction 303 let g:fzf_action = { 304 \ 'ctrl-f': function('s:build_quickfix_list'), 305 \ 'ctrl-t': 'tabedit', 306 \ 'ctrl-p': 'split', 307 \ 'ctrl-v': 'vsplit' } 308 let g:fzf_layout = {'window': { 'width': 0.9, 'height': 0.4 } } 309 let g:fzf_preview_window = 'right:60%' 310 " Jump to existing buffer/window if possible 311 let g:fzf_buffers_jump = 1 312 313 nnoremap <leader>F :Files<CR> 314 nnoremap <leader><c-f><c-f> :Files<space> 315 nnoremap <expr> <leader><c-f>. ":Files " .. expand("%:h") .. "<CR>" 316 nnoremap <leader>B :Buffers<CR> 317 nnoremap <leader>G :Lines<CR> 318 nnoremap <leader>W :BLines<CR> 319 nnoremap <expr> <leader>Z ':BLines '..&foldmarker->split(',')[0]..'<CR>' 320 nnoremap <leader>? :Helptags<CR> 321 nnoremap <leader>T :Tags<CR> 322 nnoremap <leader>/ :Ag<CR> 323 nnoremap <leader>M :Marks<CR> 324 nnoremap <leader>; :History:<CR> 325 326 " My extensions 327 nmap <leader>J <Plug>FzfChangesJumpsJumps 328 nmap <leader>C <Plug>FzfChangesJumpsChanges 329 330 " Search for Todos/Fixmes 331 command! Todo Ag ((TO ?DO)|FIXME):?<space> 332 nnoremap <leader>! :Todo<CR> 333 334 " Set a filetype 335 cabbrev setf Filetypes 336 337 command! Scripts call fzf#run(fzf#wrap({'source': 'command find $DOTFILES -type f -or -type l -not -ipath "*/.git/*"', 'options': '--multi --reverse --inline-info --prompt="scripts> "', 'sink': 'sp'})) 338 command! Configs call fzf#run(fzf#wrap({'source': 'command find $DOTFILES -type f ! -ipath "*/.git/*" ! -ipath "*/bin/*" ! -ipath "*/oh-my-zsh/*" ! -name ".DS_Store"', 'options': '--multi --reverse --inline-info --prompt="configs> "', 'sink': 'sp'})) 339 " Haskell {{{3 340 let hs_highlight_delimiters = 1 341 let hs_highlight_boolean = 1 342 let hs_highlight_types = 1 343 let hs_highlight_more_types = 1 344 " EasyAlign {{{3 345 " Start interactive EasyAlign in visual mode (e.g. vipga) 346 xmap ga <Plug>(LiveEasyAlign) 347 348 " Start interactive EasyAlign for a motion/text object (e.g. gaip) 349 nmap ga <Plug>(LiveEasyAlign) 350 351 " Keep :ascii as a map 352 nnoremap <leader>ga :<c-u>ascii<cr> 353 " Peekaboo {{{3 354 let g:peekaboo_compact=1 355 " Undotree {{{3 356 nnoremap <leader>u :UndotreeToggle<CR> 357 " Dispatch {{{3 358 " Disable default maps 359 let g:dispatch_no_maps = 1 360 361 " Only enable those I'll actually use 362 nnoremap `<CR> :Dispatch<CR> 363 nnoremap '<CR> :Start<CR> 364 " netrw {{{3 365 let g:netrw_banner = 0 " hide the banner 366 let g:netrw_fastbrowse = 1 " had set to 2 before, which ended up showing duplicate files... 367 let g:netrw_liststyle = 0 " thin listing 368 let g:netrw_winsize = 25 " open at 25% size 369 let g:netrw_keepdir = 0 " keep the current directory the same as the browsing directory. 370 let g:netrw_retmap = 0 " double-click to return to browsing 371 let g:netrw_list_hide = &wildignore " hide everything in &wildignore 372 let g:netrw_list_hide .= ',\(^\|\s\s\)\zs\.\S\+' " as well as dotfiles 373 let g:netrw_special_syntax = 1 " use special syntax groups for certain files in browser 374 " latex-unicoder {{{3 375 let g:unicoder_no_map = 1 376 inoremap <C-l> <Esc>:call unicoder#start(1)<CR> 377 " colorizer {{{3 378 let g:colorizer_colornames = 0 379 command! CH ColorHighlight 380 command! CC ColorClear 381 " Schemer {{{3 382 " List color group 383 nmap <leader><C-p> <Plug>SchemerSynstack 384 nmap <leader><C-E><C-L> <Plug>SchemerEdit 385 " Relatively complete {{{3 386 " Replace default file completion with 'smart' relative complete 387 imap <C-x><C-f> <Plug>RelativelyCompleteFile 388 " Visualrun {{{3 389 " Run selected commands (silent) 390 vmap <silent> <leader><cr> <Plug>VisualRunCommands 391 " Zepl {{{3 392 runtime! zepl/contrib/control_characters.vim 393 \ zepl/contrib/load_files.vim 394 \ zepl/contrib/python.vim 395 let g:repl_config = { 396 \ 'python': { 397 \ 'cmd': 'python3', 398 \ 'formatter': function('zepl#contrib#python#formatter'), 399 \ 'load_file': 'from %s import *' 400 \ }, 401 \ 'javascript': { 'cmd': 'node' }, 402 \ 'ruby': { 'cmd': 'irb', 'load_file': 'load "%s"' }, 403 \ 'r': { 'cmd': 'R' }, 404 \ 'java': {'cmd': 'jshell' }, 405 \ 'sh': {'cmd': 'sh' } 406 \ } 407 nnoremap gzr :Repl<CR> 408 " Medieval {{{3 409 let g:medieval_langs = ['python=python3', 'ruby', 'sh', 'bash', 'haskell=ghci', 'javascript=node'] 410 " LF {{{3 411 nmap <leader>\ <Plug>LfEdit 412 nmap <leader><c-\> <Plug>LfSplit 413 " Ada {{{3 414 let g:ada_standard_types = 1 415 let g:ada_space_errors = 1 416 let g:ada_begin_preproc = 1 417 let g:ada_omni_with_keywords = 1 418 " gh.vim {{{3 419 let g:gh_token = getenv("GITHUB_AUTH_TOKEN") 420 " ALE {{{3 421 if exists('g:loaded_ale') 422 let g:airline#extensions#ale#enabled = 0 423 let g:ale_enabled = 0 424 let g:ale_c_cc_options = '-std=gnu99 -Wall' 425 let g:ale_c_clangd_options = '-std=gnu99 -Wall' 426 let g:ale_c_clangformat_options = '-std=gnu99 -Wall' 427 let g:ale_c_clangtidy_options = '-std=gnu99 -Wall' 428 let g:ale_c_clangtidy_extra_options = '-std=gnu99 -Wall' 429 let g:ale_perl_perlcritic_options = '--brutal' 430 let g:ale_python_flake8_options = '--max-line-length=130' 431 call ale#Set('tex_textidote_executable', 'textidote') 432 call ale#Set('tex_textidote_options', '--no-color --output singleline') 433 " TODO get language from spell spelllang 434 call ale#Set('tex_textidote_check_lang', '') 435 call ale#linter#Define('tex', { 436 \ 'name': 'textidote', 437 \ 'output_stream': 'stdout', 438 \ 'executable': {b -> ale#Var(b, 'tex_textidote_executable')}, 439 \ 'command': function('ale_linters#tex#textidote#GetExecutable'), 440 \ 'callback': 'ale_linters#tex#textidote#Handle', 441 \}) 442 endif 443 444 " indentLine {{{3 445 if !has('nvim') 446 let g:indentLine_char_list = ['|', '¦', '┆', '┊'] 447 let g:indentLine_enable = 0 " off by default 448 let g:indentLine_fileType = ['python'] " enable for python 449 endif 450 " Emmet {{{3 451 let g:user_emmet_settings = { 452 \ 'markdown': { 453 \ 'indentation': '', 454 \ 'extends': 'html' 455 \ } 456 \ } 457 " Smoothie {{{3 458 let g:smoothie_remapped_commands = ['<C-D>', '<C-U>', '<C-F>', '<C-B>'] 459 " }}}1 460 " General {{{1 461 " Put viminfo in ~/.cache 462 if has('nvim') 463 set viminfofile=~/.cache/nvim/viminfo 464 else 465 set viminfofile=~/.cache/vim/viminfo 466 endif 467 468 " Set the colors 469 " Use true color 470 " Set Vim-specific sequences for RGB colors 471 let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum" 472 let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum" 473 474 if has('termguicolors') 475 set termguicolors 476 endif 477 478 if filereadable($HOME."/.config/dark-theme") 479 colorscheme junipero 480 else 481 colorscheme jokull 482 endif 483 484 " where to find tags files 485 set tags=./tags;~,tags,~/.tags 486 if has("path_extra") 487 " If compiled with path_extra, search for .git/tags upwards in the tree 488 " and stop searching at $HOME 489 let &tags = &tags.',.git/tags;~' 490 else 491 let &tags = &tags.',.git/tags' 492 endif 493 494 " follow the 'ignorecase' option when looking for tags 495 set tagcase=followic 496 497 " dictionary files, in order (custom words should appear at the top) 498 " remember, to generate a wordlist from spellcheck, do :spelldump 499 set dictionary=~/.vim/words/dict/global/custom.txt 500 set dictionary+=~/.vim/words/dict/global/3of6all.txt 501 set dictionary+=/usr/share/dict/words 502 503 " thesaurus file 504 set thesaurus=~/.vim/words/thesaurus/mthesaur.txt 505 506 if !has('nvim') 507 " same with :Man 508 " I'm lazy-loading this because it really affects my startup time. 509 " I'm not the only one: https://www.reddit.com/r/vim/comments/emx856/lazy_loading_man_page_plugin/ 510 silent! command! -bar -nargs=* Man 511 \ delcommand Man | 512 \ runtime ftplugin/man.vim | 513 \ Man <args> 514 endif 515 516 " For editing binaries 517 set binary 518 519 " Save swapfiles to ~/.local/share/vim/swap 520 if has('nvim') 521 if !isdirectory($HOME.'/.local/share/nvim/swap') 522 silent call mkdir($HOME.'/.local/share/nvim/swap', 'p') 523 endif 524 set directory=~/.local/share/nvim/swap// 525 else 526 if !isdirectory($HOME.'/.local/share/vim/swap') 527 silent call mkdir($HOME.'/.local/share/vim/swap', 'p') 528 endif 529 set directory=~/.local/share/vim/swap// 530 endif 531 set swapfile 532 533 " Save backups to ~/.local/share/vim/backup 534 if has('nvim') 535 if !isdirectory($HOME.'/.local/share/nvim/backup') 536 silent call mkdir($HOME.'/.local/share/nvim/backup', 'p') 537 endif 538 set backupdir=~/.local/share/nvim/backup// 539 else 540 if !isdirectory($HOME.'/.local/share/vim/backup') 541 silent call mkdir($HOME.'/.local/share/vim/backup', 'p') 542 endif 543 set backupdir=~/.local/share/vim/backup// 544 endif 545 set nobackup writebackup 546 547 " make regexes consistent with other programs (extended) 548 set magic 549 550 " global setting for directories to search for files (e.g. for gf) 551 " . == directory of current file, ,, == current working directory 552 set path=.,"$HOME"/.dotfiles/vim/**,, 553 554 " global suffixes to add when looking for files (configured otherwise on per-language basis) 555 set suffixesadd=.vim 556 557 " include, includeexpr, define: very language-specific, so no default global value 558 559 " global patterns to ignore in wildmenu 560 set wildignore=*.swp 561 set wildignorecase 562 563 " Persistent undos (useful for plugins too){{{ 564 if has('persistent_undo') 565 if has('nvim') 566 let myUndoDir = $HOME . '/.local/share/nvim/undo' 567 else 568 let myUndoDir = $HOME . '/.local/share/vim/undo' 569 endif 570 silent! call mkdir(myUndoDir, 'p') 571 let &undodir = myUndoDir 572 set undofile 573 endif 574 " }}} 575 576 " Hide buffers instead of closing 577 set hidden 578 579 " Dont redraw while executing macros 580 set lazyredraw 581 582 " Encoding & formats 583 set encoding=utf-8 nobomb 584 set fileformats=unix,dos,mac 585 586 " Number of lines to use for command line 587 " (this fixes the 'press to continue' thing on :help) 588 set cmdheight=1 589 590 " Send more characters at a given time 591 set ttyfast 592 593 " Show partial command on last line 594 set showcmd 595 596 " Don't show current mode (it's in the statusline) 597 set noshowmode 598 " Command completion 599 set wildmenu 600 601 " Allow the mouse, good for e.g. resizing splits 602 set mouse=a 603 " fix issue with not being able to drag resize split windows in tmux 604 if !has('nvim') 605 if &term =~# '^screen' || $TMUX !=# "" 606 set ttymouse=xterm2 607 elseif &term =~# '^st-' || &term =~# '^alacritty' 608 set ttymouse=sgr 609 endif 610 endif 611 612 " How to split new windows 613 set splitbelow splitright 614 615 " Allow per-file settings 616 set modeline 617 set modelines=5 "within the first/last 5 lines 618 619 " Allow italics 620 set t_ZH=[3m 621 set t_ZR=[23m 622 623 " Since belloff isn't always an option 624 if exists("&belloff") 625 set belloff=showmatch,esc,shell,wildmode,backspace " Disable beeping if no match is found 626 endif 627 628 " Command-line autocompletion 629 set wildmode=longest:list,full 630 631 " Add everything to sessions 632 set sessionoptions=buffers,curdir,folds,globals,localoptions,options,resize,tabpages 633 634 " Use ag for grepping 635 set grepprg=ag\ --vimgrep 636 set updatetime=100 637 638 " Make <esc> faster. 639 " Note: this disables arrow keys in insert mode, because arrow keys start with <esc> (e.g. `\eOD` for left arrow). 640 " However, I don't use arrow keys anyway, so that's fine. 641 if !has('nvim') 642 set noesckeys 643 endif 644 645 " }}}1 646 " Editor {{{1 647 " In general, don't conceal anything 648 if has('conceal') 649 set conceallevel=0 650 endif 651 652 " Change cursor shape between insert and normal mode in iTerm2.app and 653 " Alacritty 654 " '\e[n q' with n: 0 blinking block, 1 blinking block, 2 steady block, 3 655 " blinking underline, 4 steady underline, 5 blinking bar, 6 steady bar 656 " If this doesn't work, you might need a different escape sequence: 657 " - t_SI = "\<Esc>]50;CursorShape=1\x7\<Esc>\\" 658 " - t_EI = "\<Esc>]50;CursorShape=0\x7\<Esc>\\" 659 " (test them with e.g. `printf '\e[6 q'`) 660 if exists('$TMUX') 661 " NOTE: For tmux >= version 3.3, you need 'allow-passthrough' set. 662 let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>[6 q\<Esc>\\" " Vertical bar in insert mode 663 let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>[2 q\<Esc>\\" " Block in normal mode 664 let &t_SR = "\<Esc>Ptmux;\<Esc>\<Esc>[4 q\<Esc>\\" " Underline in replace mode 665 else 666 let &t_SI = "\<Esc>[6 q" " Vertical bar in insert mode 667 let &t_SR = "\<Esc>[4 q" " Underline in replace mode 668 let &t_EI = "\<Esc>[2 q" " Block in normal mode 669 endif 670 671 " Highlight current line 672 set cursorline 673 674 " Reduce waiting on keys (like esc) 675 set timeoutlen=1000 ttimeoutlen=5 676 677 " Wrap settings - no wrap by default 678 set nowrap 679 set textwidth=0 680 set wrapmargin=0 681 set linebreak " break at &breakat 682 " Continue wrapped line on same indent as previous 683 if has('breakindent') 684 set breakindent 685 set breakindentopt+=shift:3 686 endif 687 688 " Default formatoptions: 689 " - q: allow gq 690 " - n: recognise numbered lists 691 " - l: don't break long lines in insert mode 692 " - j: remove comment leader when joining 693 set formatoptions=qnlj 694 695 " Numbered lines 696 set number 697 set numberwidth=3 698 set relativenumber 699 700 " with a smart tab 701 set smarttab 702 703 " and 1 tab == 2 spaces 704 set tabstop=8 " visual length of \t in spaces, should be left at 8 705 set expandtab " use spaces instead of tabs 706 set softtabstop=4 " 4 spaces inserted when TAB pressed 707 set shiftwidth=2 " 2 spaces when >> 708 set shiftround " always shift by multiple of shiftwidth 709 710 " Auto indent when starting new line 711 set autoindent 712 set copyindent " copy structure of other indents whn autoindenting 713 714 " Enable indenting based on filetype 715 filetype plugin indent on 716 717 " Syntax highlighting 718 syntax on 719 720 " Enable fenced code highlighting in markdown (tpope's plugin, ships with vim) 721 " NOTE: I'm disabling it because it makes Vim very slow when typing in 722 " markdown... 723 " let g:markdown_fenced_languages = ['html', 'python', 'ruby', 'bash=sh', 'map', 'vim', 'c', 'cpp', 'make'] 724 725 " Enable markdown folding 726 " NOTE: I'm disabling it because it makes Vim very slow when typing in 727 " markdown... 728 " let g:markdown_folding = 1 729 730 " Folding on indentation 731 set foldmethod=indent 732 set foldlevelstart=5 " start with up to 5 levels open 733 set foldnestmax=10 " unless callback-hell JS 734 735 " Show matching brackets 736 set showmatch 737 set matchtime=2 738 739 " Searching 740 set hlsearch " highlight matches 741 set incsearch " search while typing 742 set ignorecase " ignore case generally 743 set smartcase " but not if searching for capital 744 745 " Backspace tweaks 746 set backspace=indent,eol,start 747 set whichwrap+=<,>,h,l 748 749 " Complete from current buffer, other windows, buffers, unloaded buffers, tags, 750 " current and included files, and dictionary if spell is set 751 set complete=.,w,b,u,t,i,kspell 752 " Use popup menu, also when there is only one match, don't insert until the user selects 753 " a match, don't select anything automatically. 754 set completeopt=menu,menuone,preview 755 756 nnoremap <silent><expr> <leader># ":set ".(&relativenumber?'norelativenumber number':'relativenumber number')."<CR>" 757 758 set omnifunc=syntaxcomplete#Complete 759 760 " Keep cursor off top and bottom of screen 761 set scrolloff=5 762 763 " Which formats to use for incrementing/decrementing 764 set nrformats=hex,bin 765 766 " We write posix shell scripts 767 let g:is_posix = 1 768 769 " Show where lines were wrapped 770 set showbreak=≻ 771 " }}} 772 " Commands {{{1 773 command! NoteP vimgrep /NOTE\C/ **/*.* | copen 774 command! Note vimgrep /NOTE\C/ % | copen 775 command! FixP vimgrep /FIXME\C/ **/*.* | copen 776 command! Fix vimgrep /FIXME\C/ % | copen 777 command! ListFileTypes echo glob($VIMRUNTIME . '/syntax/*.vim') 778 command! CD cd %:p:h 779 command! LCD lcd %:p:h 780 command! TCD tcd %:p:h 781 command! RO setlocal nomodifiable readonly 782 command! RW setlocal modifiable noreadonly 783 command! Maketab set noet ts=2 | %retab! 784 command! Diff w !diff % - 785 command! Diffg w !git diff % - 786 command! Fuckwindows %s/ //g 787 command! Hexedit %!xxd 788 command! Unhex %!xxd -r 789 command! JsonSimplifyObject %s/^\(\s\{10}\){\n\s\{12\}\(.*\)\n\s\{10\}}\(,\?\)/\1{ \2 }\3 790 command! UnsmartQuotes silent %s/[“”]/"/ge | %s/[‘’]/'/ge 791 command! BeautifyJson %!python -m json.tool 792 command! Dos2unix %!dos2unix 793 command! -nargs=1 Cheat terminal curl cheat.sh/<args> 794 command! Reveal exe "silent !open ".shellescape(expand("%:p:h")) | redraw! 795 command! Softwrap setlocal wrap formatoptions-=cat 796 command! Hardwrap setlocal nowrap formatoptions+=cat 797 command! Syncwin windo set scrollbind! cursorbind! 798 command! EF exe "split $HOME/.vim/after/ftplugin/".&filetype.".vim" 799 command! FD filetype detect 800 command! D smile 801 command! QuickfixAddCurrent call setqflist([{'bufnr': bufnr(), 'lnum': line('.'), 'text': getline('.')}], 'a') 802 command! LoclistAddCurrent call setloclist(winnr(), [{'bufnr': bufnr(), 'lnum': line('.'), 'text': getline('.')}], 'a') 803 command! QuickfixDelCurrent call setqflist(getqflist()->filter($'v:val["bufnr"] !=# {bufnr()} || v:val["lnum"] !=# {line(".")}'), 'r') 804 command! LoclistDelCurrent call setloclist(winnr(), getloclist(winnr())->filter($'v:val["bufnr"] !=# {bufnr()} || v:val["lnum"] !=# {line(".")}'), 'r') 805 command! QuickfixClear call setqflist([], 'f') 806 command! LoclistClear call setloclist(winnr(), [], 'f') 807 command! -nargs=? Browser exe 'terminal ++close w3m -config '.getenv("XDG_CONFIG_HOME").'/w3m/config -bookmark '.getenv("XDG_CONFIG_HOME").'/w3m/bookmark.html '.<q-args> 808 command! -nargs=1 Img 809 \ exe "r! find ".shellescape(expand("%:p:h"))." -maxdepth ".<args>." -type f -exec file --mime-type '{}' \\+" 810 \ ."| awk -F: '$2 ~ /image\\//{print $1}'" 811 \ ."| sxiv -qto - 2>/dev/null" 812 813 " Fat finger fixes/convenience abbreviations 814 cnoreabbrev E Explore 815 cnoreabbrev Colors XtermColorTable 816 cnoreabbrev lset setl 817 cnoreabbrev sudow w !sudo tee > /dev/null % 818 cnoreabbrev hg helpgrep 819 cnoreabbrev gitr system("git root") 820 821 if has('terminal') 822 " ++close means close when process ends 823 " (so that I don't get a hanging term buffer) 824 cnoreabbrev wt terminal ++close 825 cnoreabbrev tt tab terminal ++close 826 cnoreabbrev tm terminal ++close man 827 cnoreabbrev tf terminal ++close lf 828 cnoreabbrev tn terminal ++close joplin 829 command! Reddit tab terminal ttrv 830 endif 831 832 " Convenient command to see the difference between the current buffer and the 833 " file it was loaded from, thus the changes you made. 834 command! DiffOrig vert new | set bt=nofile | r# | 0d_ | diffthis 835 \ | wincmd p | diffthis 836 " }}} 837 " Digraphs {{{1 838 let digraphs = { 839 \ 'o+': 0x2295, 'O+': 0x2a01, 840 \ 'e$': 0x20ac, 841 \ '\|>': 0x21a6, 842 \ '[[': 0x27e6, ']]': 0x27e7, 843 \ 'aS': 0x1D43, 'bS': 0x1D47, 'cS': 0x1D9C, 'dS': 0x1D48, 'eS': 0x1D49, 'fS': 0x1DA0, 'gS': 0x1D4D, 'hS': 0x02B0, 'iS': 0x2071, 'jS': 0x02B2, 'kS': 0x1D4F, 'lS': 0x02E1, 'mS': 0x1D50, 'nS': 0x207F, 'oS': 0x1D52, 'pS': 0x1D56, 'rS': 0x02B3, 'sS': 0x02E2, 'tS': 0x1D57, 'uS': 0x1D58, 'vS': 0x1D5B, 'wS': 0x02B7, 'xS': 0x02E3, 'yS': 0x02B8, 'zS': 0x1DBB, 'AS': 0x1D2C, 'BS': 0x1D2D, 'DS': 0x1D30, 'ES': 0x1D31, 'GS': 0x1D33, 'HS': 0x1D34, 'IS': 0x1D35, 'JS': 0x1D36, 'KS': 0x1D37, 'LS': 0x1D38, 'MS': 0x1D39, 'NS': 0x1D3A, 'OS': 0x1D3C, 'PS': 0x1D3E, 'RS': 0x1D3F, 'TS': 0x1D40, 'US': 0x1D41, 'VS': 0x2C7D, 'WS': 0x1D42, 844 \ 'as': 0x2090, 'es': 0x2091, 'is': 0x1D62, 'os': 0x2092, 'rs': 0x1D63, 'us': 0x1D64, 'vs': 0x1D65, 'xs': 0x2093, 'ys': 0x1D67, 845 \ '0S': 0x2070, '1S': 0x00B9, '2S': 0x00B2, '3S': 0x00B3, '4S': 0x2074, '5S': 0x2075, '6S': 0x2076, '7S': 0x2077, '8S': 0x2078, '9S': 0x2079, '+S': 0x207A, '-S': 0x207B, '=S': 0x207C, '(S': 0x207D, ')S': 0x207E, 846 \ '0s': 0x2080, '1s': 0x2081, '2s': 0x2082, '3s': 0x2083, '4s': 0x2084, '5s': 0x2085, '6s': 0x2086, '7s': 0x2087, '8s': 0x2088, '9s': 0x2089, '+s': 0x208A, '-s': 0x208B, '=s': 0x208C, '(s': 0x208D, ')s': 0x208E, 847 \ '-<': 0x227a, '>-': 0x227b, 848 \ '\|=': 0x22a8, '\|-': 0x22a2, '!m': 0x22ad, 849 \ '[]': 0x25a1, '()': 0x25c7, '<(': 0x3008, '>)': 0x3009, 850 \ 'n#': 0x2115, 'r#': 0x211d, 'z#': 0x2124 } 851 852 for [dg, code] in items(digraphs) 853 exe 'digraphs ' .. dg .. ' ' .. code 854 endfor 855 " Mappings {{{1 856 " So I don't have to mash shift all the time 857 nnoremap ; : 858 vnoremap ; : 859 860 if has('terminal') 861 tnoremap <C-w>; <C-w>: 862 endif 863 864 " To keep the old functionality of ; 865 nnoremap : ; 866 vnoremap : ; 867 868 " Disable q: cuz I hate it 869 " (also C-F does the same) 870 nnoremap q: <Nop> 871 872 " Normal mode shortcuts 873 nnoremap <leader>b :ls<CR>:b<Space> 874 875 " Retain visual mode after > and < 876 vnoremap < <gv 877 vnoremap > >gv 878 879 " visual j/k 880 nnoremap j gj 881 nnoremap k gk 882 nnoremap gj j 883 nnoremap gk k 884 vnoremap j gj 885 vnoremap k gk 886 vnoremap gj j 887 vnoremap gk k 888 889 " Move visual block 890 xnoremap D :m '>+1<CR>gv=gv 891 xnoremap U :m '<-2<CR>gv=gv 892 893 " and don't break my colours (U for 'unfuck my screen please') 894 nnoremap <leader><c-l> :syntax sync fromstart<CR>:redraw!<CR>:diffupdate<CR><c-l> 895 896 " urlview 897 nnoremap <silent> U :w !urlview<CR> 898 nnoremap <leader>U U 899 900 " 'zoom to head level' 901 nnoremap zh mzzt10<c-u>`z 902 903 " Reindent the file 904 nnoremap <leader>= mlgg=G`lzz 905 906 " Tab mappings 907 nnoremap <leader>tn :tabnew<CR> 908 nnoremap <leader>tc :tabclose<CR> 909 nnoremap <leader>th :tabmove -1<CR> 910 nnoremap <leader>tl :tabmove +1<CR> 911 912 " Window resizing mappings 913 nnoremap <C-k> <C-w>+ 914 nnoremap <C-j> <C-w>- 915 nnoremap <C-h> <C-W>< 916 nnoremap <C-l> <C-W>> 917 918 " Delete hidden buffers 919 nmap <leader>dh <Plug>DeleteHiddenBuffers 920 921 " Show hidden symbols 922 nnoremap <leader>hs :set list!<CR> 923 924 " List marks 925 nnoremap <leader>mm :<C-u>marks<CR>:normal! ` 926 nnoremap <leader>ml :<C-u>marks a-z<CR>:normal! ` 927 928 929 " Map '0' to act as '^' on first press and '0' on second 930 nnoremap <expr> <silent> 0 col('.') == match(getline('.'),'\S')+1 ? '0' : '^' 931 932 " Highlight last inserted text 933 nnoremap gV `[v`] 934 935 " Save in insert mode 936 inoremap <C-Z> <C-o>:w<CR> 937 938 " Allow undo/redo on C-w and C-u in insert mode 939 inoremap <c-u> <c-g>u<c-u> 940 inoremap <c-w> <c-g>u<c-w> 941 942 if !has('nvim') 943 " Config edit mappings 944 " Why :drop? It uses the file if it's already open. 945 " Also have to map c-c to no-op first, otherwise doesn't work 946 nnoremap <C-c> <nop> 947 nnoremap <leader><C-E><C-V> :DropToFoldedVimrc<CR>zXgg 948 nnoremap <leader><C-E><C-A> :DropToFoldedVimrc<CR>zXgg/^" Autocommands {{<CR>:noh<CR>za 949 nnoremap <leader><C-E><C-C> :DropToFoldedVimrc<CR>zXgg/Commands {{<CR>:noh<CR>za 950 nnoremap <leader><C-E><C-E> :DropToFoldedVimrc<CR>zXgg/Editor {{<CR>:noh<CR>za 951 nnoremap <leader><C-E><C-G> :DropToFoldedVimrc<CR>zXgg/General {{<CR>:noh<CR>za 952 nnoremap <leader><C-E><C-M> :DropToFoldedVimrc<CR>zXgg/Mappings {{<CR>:noh<CR>za 953 nnoremap <leader><C-E><C-P><C-I> :DropToFoldedVimrc<CR>zXgg/Plugins {{<CR>:noh<CR>za/Installation {{<CR>:noh<CR>za 954 nnoremap <leader><C-E><C-P><C-C> :DropToFoldedVimrc<CR>zXgg/Plugins {{<CR>:noh<CR>za/Config {{<CR>:noh<CR>za 955 nnoremap <leader><C-E><C-U> :UltiSnipsEdit<CR> 956 endif 957 958 " Yank to clipboard 959 nnoremap <leader>d "+d 960 vnoremap <leader>d "+d 961 nnoremap <leader>D "+D 962 nnoremap <leader>y "+y 963 vnoremap <leader>y "+y 964 nnoremap <leader><leader>p "+p 965 nnoremap <leader><leader>P "+P 966 vnoremap <leader><leader>p "+p 967 vnoremap <leader><leader>P "+P 968 nnoremap <leader>n "_ 969 vnoremap <leader>n "_ 970 nnoremap <leader>yy "+yg_ 971 nnoremap <leader>y<leader> :<c-u>let @*=@0<CR> 972 nnoremap Y y$ 973 974 " Insert lines without moving cursor and going into insert mode 975 nnoremap <leader>o m`o<esc>`` 976 nnoremap <leader>O m`O<esc>`` 977 978 " native file browsing 979 nnoremap <leader>f :Lexplore<CR> 980 981 " Strip trailing whitespace (silent makes it so nothing is echoed) 982 nmap <silent> <leader>$ <Plug>StripTrailingWhitespace 983 984 " Buffer switching 985 nnoremap H :bprevious<CR> 986 nnoremap L :bnext<CR> 987 988 " Arg switching 989 nnoremap <leader>H :previous<CR> 990 nnoremap <leader>L :next<CR> 991 992 993 " Correct the last spelling error 994 inoremap <expr> <C-x>s &spell ? "<c-g>u<Esc>[s1z=`]a<c-g>u" : "" 995 996 " Make-ing (use Dispatch if enabled) 997 nnoremap <leader>m? :set makeprg<CR> 998 nnoremap <leader>mm :Make<CR> 999 nnoremap <leader>mc :Make clean<CR> 1000 1001 " If Dispatch not used 1002 " :silent make<CR>\|:redraw!<CR>\|:cwindow<CR> 1003 " :silent make clean<CR>\|:redraw!<CR> 1004 1005 " Vmap for searching in selection 1006 vnoremap <leader>/ <esc>/\%V 1007 1008 " Allow scrolling popup menus with the mouse 1009 if has('mouse') 1010 inoremap <expr> <ScrollWheelUp> pumvisible() ? "<C-p>" : "<Esc><ScrollWheelUp>" 1011 inoremap <expr> <ScrollWheelDown> pumvisible() ? "<C-n>" : "<Esc><ScrollWheelDown>" 1012 endif 1013 1014 " 'Zoom' the current buffer in a new tab 1015 nnoremap <C-w>Z :tab split<CR> 1016 1017 " Go to line:column 1018 nnoremap <leader>gg :call input("go line:col> ")->split(":")->cursor()<CR> 1019 1020 " Which commit introduced this line? 1021 nnoremap <silent><Leader>gw :call setbufvar(winbufnr(popup_atcursor(systemlist("cd " . shellescape(fnamemodify(resolve(expand('%:p')), ":h")) . " && git log --no-merges -n 1 -L " . shellescape(line("v") . "," . line(".") . ":" . resolve(expand("%:p")))), { "padding": [1,1,1,1], "pos": "botleft", "wrap": 0, "highlight": "StatusLine"})), "&filetype", "git")<CR> 1022 1023 " Avoid paste hijacking in insert mode 1024 inoremap <c-r> <c-r><c-o> 1025 1026 " Up/down arrows on the command line search for commands starting with current 1027 " string. I want <c-n/p> to do the same. 1028 cnoremap <expr> <c-n> wildmenumode() ? "\<c-n>" : "\<down>" 1029 cnoremap <expr> <c-p> wildmenumode() ? "\<c-p>" : "\<up>" 1030 1031 " Use <Tab> and <S-Tab> to jump to next search result, 1032 " while keeping <Tab>'s wildmenu function. 1033 set wildcharm=<c-z> 1034 cnoremap <expr> <Tab> getcmdtype() =~ '[?/]' ? "<c-g>" : "<c-z>" 1035 cnoremap <expr> <S-Tab> getcmdtype() =~ '[?/]' ? "<c-t>" : "<S-Tab>" 1036 1037 " Easier pasting 1038 nnoremap <leader>p "0p 1039 vnoremap <leader>p "0p 1040 nnoremap <leader>P "0P 1041 vnoremap <leader>P "0P 1042 1043 " Highlight one or more lines 1044 highlight LineHighlight ctermbg=darkgray guibg=darkgray cterm=bold 1045 nnoremap <silent> <leader>hl :call matchadd('LineHighlight', '\%'.line('.').'l')<CR> 1046 vnoremap <silent> <leader>hl :call matchadd('LineHighlight', '\%'.line('.').'l')<CR> 1047 nnoremap <silent> <leader>hc :call clearmatches()<CR> 1048 vnoremap <silent> <leader>hc :call clearmatches()<CR> 1049 1050 " have n always search forward 1051 noremap <expr> <SID>(search-forward) 'Nn'[v:searchforward] 1052 " and N always search backward 1053 noremap <expr> <SID>(search-backward) 'nN'[v:searchforward] 1054 1055 " backspace to switch to alternate buffer 1056 nnoremap <backspace> <c-^> 1057 1058 " Switch to tab/space indentation 1059 nnoremap <leader>i<tab> :set noexpandtab shiftwidth=4 softtabstop=4 tabstop=4<CR> 1060 nnoremap <leader>i<space> :set expandtab shiftwidth=4 softtabstop=4 tabstop=8<CR> 1061 1062 " Switch fold methods 1063 nnoremap <leader>zm :setlocal foldmethod=manual<CR> 1064 nnoremap <leader>zi :setlocal foldmethod=indent<CR> 1065 nnoremap <leader>z{ :setlocal foldmethod=marker<CR> 1066 nnoremap <leader>zs :setlocal foldmethod=syntax<CR> 1067 nnoremap <leader>ze :setlocal foldmethod=expr<CR> 1068 nnoremap <leader>zd :setlocal foldmethod=diff<CR> 1069 nmap z/ <Plug>SearchFold 1070 1071 " Set the foldlevel 1072 nnoremap <leader>zn :set foldlevel= 1073 nnoremap <leader>z. :exe "set foldlevel=".foldlevel(line('.'))<CR> 1074 1075 " quickfix 1076 nnoremap <leader>qf :cwindow<CR> 1077 nnoremap <leader>qn :cnext<CR> 1078 nnoremap <leader>qp :cprevious<CR> 1079 nnoremap <leader>qc :cclose<CR> 1080 nnoremap <leader>qz :<c-u>QuickfixClear<CR> 1081 nnoremap <leader>q. :<c-u>QuickfixAddCurrent<CR> 1082 nnoremap <leader>q- :<c-u>QuickfixDelCurrent<CR> 1083 nnoremap <leader>qr :<c-u>crewind<CR> 1084 1085 " location 1086 nnoremap <leader>ll :lwindow<CR> 1087 nnoremap <leader>ln :lnext<CR> 1088 nnoremap <leader>lp :lprevious<CR> 1089 nnoremap <leader>lb :lbefore<CR> 1090 nnoremap <leader>la :lafter<CR> 1091 nnoremap <leader>lf :lfirst<CR> 1092 nnoremap <leader>lz :<c-u>LoclistClear<CR> 1093 nnoremap <leader>l. :<c-u>LoclistAddCurrent<CR> 1094 nnoremap <leader>l- :<c-u>LoclistDelCurrent<CR> 1095 " Autocommands {{{1 1096 if has('autocmd') 1097 augroup vimrc_sets 1098 autocmd! 1099 autocmd InsertEnter * setlocal nocursorline 1100 autocmd InsertLeave * setlocal cursorline 1101 autocmd ColorScheme * highlight ColorColumn ctermbg=233 1102 augroup END 1103 augroup vimrc_commands 1104 autocmd! 1105 autocmd BufWritePre * silent StripTrailingWhitespace 1106 1107 augroup END 1108 endif 1109 " }}}