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