vimrc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. " set shell system() runs commands in
  2. " required by many plugins if $SHELL is not bash-compliant
  3. " (e.g., vim-fugitive)
  4. set shell=bash
  5. " http://peterodding.com/code/vim/profile/autoload/xolox/escape.vim
  6. function! EscapeString(string)
  7. let string=a:string
  8. let string = escape(string, '^$.*\/~[]')
  9. let string = substitute(string, '\n', '\\n', 'g')
  10. return string
  11. endfunction
  12. function! GetVisualSelection()
  13. let [lnum1, col1] = getpos("'<")[1:2]
  14. let [lnum2, col2] = getpos("'>")[1:2]
  15. let lines = getline(lnum1, lnum2)
  16. let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
  17. let lines[0] = lines[0][col1 - 1:]
  18. return join(lines, "\n")
  19. endfunction
  20. command! -range GetVisualSelection echo GetVisualSelection()
  21. " create missing parent dirs on write
  22. " source: http://stackoverflow.com/questions/4292733/vim-creating-parent-directories-on-save
  23. function! s:MkNonExDir(file, buf)
  24. if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
  25. let dir=fnamemodify(a:file, ':h')
  26. if !isdirectory(dir)
  27. call mkdir(dir, 'p')
  28. endif
  29. endif
  30. endfunction
  31. augroup BWCCreateDir
  32. autocmd!
  33. autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
  34. augroup END
  35. set showcmd
  36. set number
  37. syntax on
  38. set hlsearch
  39. set term=builtin_ansi
  40. set encoding=utf8
  41. " fix colors in vimdiff
  42. set background=dark
  43. " indention
  44. set autoindent
  45. set tabstop=4
  46. set shiftwidth=4
  47. set expandtab
  48. " sync vim with system clipboard
  49. " http://stackoverflow.com/questions/11489428/how-to-make-vim-paste-from-and-copy-to-systems-clipboard
  50. set clipboard=unnamedplus
  51. set splitbelow
  52. set splitright
  53. set wildmode=longest,list,full
  54. set wildmenu
  55. set wildignore+=*.42m
  56. set wildignore+=__pycache__
  57. " load rtp/(ftplugin|indent)(.vim|\/.*)
  58. filetype plugin indent on
  59. set completeopt=longest,menuone
  60. autocmd FileType gitcommit,tex setlocal spell
  61. autocmd FileType mail setlocal spell spelllang=de_at
  62. " https://github.com/numirias/security/blob/master/doc/2019-06-04_ace-vim-neovim.md#patches
  63. set modelines=0
  64. set nomodeline
  65. " airline
  66. set noshowmode
  67. " http://vim.wikia.com/wiki/256_colors_in_vim
  68. set t_Co=256
  69. let g:airline_theme='dark'
  70. let g:airline#extensions#tabline#enabled = 1
  71. let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
  72. let g:deoplete#enable_at_startup = 1
  73. " fugitive
  74. let g:fugitive_gitlab_domains = [
  75. \ 'https://code.grasp-open.com',
  76. \ 'https://git.internal.catalysts.cc',
  77. \ 'https://gitlab.com',
  78. \ ]
  79. " vimtex
  80. let g:vimtex_view_method = 'zathura'
  81. if empty(v:servername) && exists('*remote_startserver')
  82. call remote_startserver('VIM')
  83. endif
  84. nnoremap <localleader>lt :call vimtex#fzf#run()<cr>
  85. " templates
  86. let g:templates_directory = ['~/.vim/templates']
  87. vmap / <Esc>/<C-R>=EscapeString(GetVisualSelection())<CR>
  88. nmap gx :!urlscan %:p<CR>
  89. let mapleader=','
  90. nmap <leader>+x :w<CR>:!chmod +x "%"<CR>:e<CR>
  91. nmap <leader>b :TagbarOpenAutoClose<CR>
  92. nmap <leader>cd :cd %:p:h<CR>:pwd<CR>
  93. nmap <leader>cp :cd ..<CR>:pwd<CR>
  94. nmap <leader>f :FZF<CR>
  95. nmap <leader>gc :Gcommit -v<CR>
  96. nmap <leader>gd :Git diff --word-diff=color %<CR>
  97. nmap <leader>gD :Git diff --word-diff=color <CR>
  98. nmap <leader>gf :Gfetch --prune<CR>
  99. nmap <leader>gl :Gpull<CR>
  100. nmap <leader>go :Git branch --all<CR>:Git checkout
  101. nmap <leader>gp :Gpush<CR>
  102. nmap <leader>gs :Gstatus<CR>
  103. nmap <leader>gT :Git tree<CR>
  104. nmap <leader>gm :MerginalToggle<CR>
  105. nmap <leader>gt :Git tree %<CR>
  106. nmap <leader>gw :Git diff --cached %<CR>
  107. nmap <leader>gW :Git diff --cached<CR>
  108. nmap <leader>m :make<CR>
  109. nmap <leader>R :!ranger %:p:h<CR>
  110. nmap <leader>su :%s///gc<Left><Left><Left><Left>
  111. vmap <leader>su <Esc>:%s
  112. \/<C-R>=EscapeString(GetVisualSelection())<CR>
  113. \/<C-R>=EscapeString(GetVisualSelection())<CR>
  114. \/gc<left><left><left>
  115. nmap <leader>strip :%s/\s\+$//e<CR>
  116. vmap <leader>strip :s/\s\+$//e<CR>
  117. nmap <leader>T :!$TERMINAL &<CR>
  118. " https://github.com/alepez/vim-gtest
  119. augroup GTest
  120. autocmd FileType cpp nnoremap <silent> <leader>tt :GTestRun<CR>
  121. autocmd FileType cpp nnoremap <silent> <leader>tu :GTestRunUnderCursor<CR>
  122. augroup END