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