vimrc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. "
  2. " noah's ~/.config/vim/vimrc
  3. "
  4. " basic setup
  5. set nocompatible
  6. " set vim paths
  7. set undodir="~/.config/vim/undo"
  8. set viminfo="~/.config/vim/viminfo"
  9. set runtimepath+="~/.config/vim"
  10. " make :find recursive
  11. set path+=**
  12. " display all files for tab completion
  13. set wildmenu
  14. " making me comfortable
  15. set nu
  16. set tabstop=4 softtabstop=4
  17. set shiftwidth=4
  18. set expandtab
  19. set smartindent
  20. set smartcase
  21. set noswapfile
  22. set nobackup
  23. set incsearch
  24. set spelllang=de_ch,en
  25. " Run PlugInstall if there are missing plugins
  26. autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
  27. \| PlugInstall --sync | source $XDG_CONFIG_HOME/vim/vimrc
  28. \| endif
  29. " getting plugins
  30. call plug#begin('~/.cache/vim/plugged')
  31. " colorshemes
  32. Plug 'morhetz/gruvbox'
  33. "Plug 'itchyny/landscape.vim'
  34. " nice statusline for vim
  35. Plug 'vim-airline/vim-airline'
  36. " some git integration
  37. Plug 'tpope/vim-fugitive'
  38. " preview colours
  39. Plug 'ap/vim-css-color'
  40. " autocompletion plugins
  41. Plug 'neoclide/coc.nvim', {'branch': 'release'}
  42. "Plug 'lervag/vimtex'
  43. call plug#end()
  44. colorscheme gruvbox
  45. set background=dark
  46. let loaded_matchparen = 1
  47. let mapleader = " "
  48. let g:netrw_browse_split = 2
  49. let g:vrfr_rg = 'true'
  50. let g:netrw_banner = 0
  51. let g:netrw_winsize = 25
  52. vnoremap J :m '>+1<CR>gv=gv
  53. vnoremap K :m '<-2<CR>gv=gv
  54. nnoremap <leader>h :wincmd h<CR>
  55. nnoremap <leader>j wincmd j<CR>
  56. nnoremap <leader>k wincmd k<CR>
  57. nnoremap <leader>l wincmd l<CR>
  58. nnoremap <leader>u :UndotreeShow<CR>
  59. nnoremap <leader>pv :wincmd v<bar> :Ex <bar> :vertical resize 30<CR>
  60. nnoremap <leader>ps :Rg<CR>
  61. nnoremap <silent> <leader>+ :vertical resize +5<CR>
  62. nnoremap <silent> <leader>- :vertical resize -5<CR>
  63. " general custom commands
  64. command D filetype detect
  65. """ active to autocompile docs on saving
  66. "autocmd BufWritePost *.ms !compile % | fold -w200
  67. "autocmd BufWritePost *.tex !compile % | fold -w200
  68. "" commands for opening and compiling various document types
  69. command S silent !vshow '%:p'
  70. command C !compile "%"
  71. " general compile button
  72. map <F3> :w<CR>:!compile "%"; pkill -HUP mupdf<CR>
  73. " bibtex extra compiler
  74. map <F2> :w<CR>:!latexmk -pdf "%"; pkill -HUP mupdf<CR>
  75. map <F4> :noh<CR>
  76. map <F5> :set spell!<CR>
  77. map <F6> :w<CR>:!glosscompile "%"; pkill -HUP mupdf<CR>
  78. " set encoding
  79. set encoding=utf-8
  80. " automatic python syntax highlighting for .tibasic files
  81. autocmd BufNewFile,BufRead *.tibasic set filetype=python
  82. autocmd BufNewFile,BufRead *.tib set filetype=python
  83. " jumper
  84. vnoremap <Space><Space> <Esc>/<++><Enter>"_c4l
  85. map <Space><Space> <Esc>/<++><Enter>"_c4l
  86. """ START latex macros
  87. " standard macros
  88. autocmd FileType tex inoremap ;beg <Esc>yypkI\begin{<Esc>A}<Esc>o<Esc>0i<Esc>jI\end{<Esc>A}<CR><Esc>0i<CR><Esc>0i<++><Esc>3ki
  89. autocmd FileType tex inoremap ;ig \includegraphics[]{<++>}<Esc>6hi
  90. autocmd FileType tex inoremap ;tw width=\textwidth<Esc>9hi
  91. autocmd FileType tex inoremap ;th height=\textheight<Esc>10hi
  92. autocmd FileType tex inoremap ;ni \setlength{\parindent}{0em}<Esc>
  93. " packages
  94. autocmd FileType tex inoremap ;ger \usepackage[ngerman]{babel}<Esc>
  95. " text formatting macros
  96. autocmd FileType tex inoremap ;bf \textbf{}<++><Esc>T{i
  97. autocmd FileType tex inoremap ;it \textit{}<++><Esc>T{i
  98. " beamer macros
  99. autocmd FileType tex inoremap ;fr \begin{frame}<CR>\frametitle{}<CR><++><CR>\end{frame}<Esc>kklli
  100. " book macros
  101. autocmd FileType tex inoremap ;sw \switchcolumn[]<++><Esc>4hi
  102. " preambule macros
  103. autocmd FileType tex inoremap ;up \usepackage{}<Esc>i
  104. autocmd FileType tex inoremap ;hy \hyphenation{}<Esc>i
  105. " apacite style
  106. autocmd FileType tex inoremap ;ap \bibliographystyle{apacite}<CR>\bibliography{}<Esc>i
  107. """ END latex macros
  108. " make background transparent
  109. "hi Normal ctermbg=none
  110. "hi NonText ctermbg=none
  111. " disalbe automatic identation
  112. filetype indent off
  113. " disable automatic comment
  114. autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
  115. " clear a TeX build after exiting vim
  116. autocmd VimLeavePre *.tex !texclear "%"
  117. autocmd VimLeavePre *.md !texclear "%"
  118. autocmd VimLeavePre *.c !rm -rf .ccls-cache
  119. autocmd VimLeavePre *.cc !rm -rf .ccls-cache
  120. autocmd VimLeavePre *.cpp !rm -rf .ccls-cache
  121. autocmd VimLeavePre *.h !rm -rf .ccls-cache
  122. autocmd VimLeavePre *.hh !rm -rf .ccls-cache
  123. Plug 'kien/rainbow_parentheses.vim'
  124. Plug 'vim-python/python-syntax'
  125. let g:python_highlight_all = 1
  126. " copy from / to clipboard
  127. vnoremap <C-c> "+y
  128. map <C-p> "+P
  129. " use TAB to autocomplete w/ coc
  130. inoremap <silent><expr> <TAB>
  131. \ pumvisible() ? "\<C-n>" :
  132. \ <SID>check_back_space() ? "\<TAB>" :
  133. \ coc#refresh()
  134. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  135. function! s:check_back_space() abort
  136. let col = col('.') - 1
  137. return !col || getline('.')[col - 1] =~# '\s'
  138. endfunction
  139. " Use `:Format` to format current buffer
  140. command! -nargs=0 Format :call CocAction('format')
  141. " Add status line support, for integration with other plugin, checkout `:h coc-status`
  142. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  143. " if hidden is not set, TextEdit might fail.
  144. set hidden
  145. " Better display for messages
  146. set cmdheight=2
  147. " You will have bad experience for diagnostic messages when it's default 4000.
  148. set updatetime=300
  149. " always show signcolumns
  150. set signcolumn=yes
  151. " Use <c-space> to trigger completion.
  152. inoremap <silent><expr> <c-space> coc#refresh()
  153. " Use `[g` and `]g` to navigate diagnostics
  154. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  155. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  156. " Remap keys for gotos
  157. nmap <silent> gd <Plug>(coc-definition)
  158. nmap <silent> gy <Plug>(coc-type-definition)
  159. nmap <silent> gi <Plug>(coc-implementation)
  160. nmap <silent> gr <Plug>(coc-references)
  161. set colorcolumn=80
  162. autocmd FileType plaintex,tex,latex syntax spell toplevel
  163. " Automatically wrap at 80 characters for Markdown
  164. " autocmd BufRead,BufNewFile *.md setlocal textwidth=80
  165. nmap <leader>rn <Plug>(coc-rename)
  166. vmap <leader>f <Plug>(coc-format-selected)
  167. nmap <leader>f <Plug>(coc-format-selected)
  168. function! MathAndLiquid()
  169. "" Define certain regions
  170. " Block math. Look for "$$[anything]$$"
  171. syn region math start=/\$\$/ end=/\$\$/
  172. " inline math. Look for "$[not $][anything]$"
  173. syn match math_block '\$[^$].\{-}\$'
  174. " Liquid single line. Look for "{%[anything]%}"
  175. syn match liquid '{%.*%}'
  176. " Liquid multiline. Look for "{%[anything]%}[anything]{%[anything]%}"
  177. syn region highlight_block start='{% highlight .*%}' end='{%.*%}'
  178. " Fenced code blocks, used in GitHub Flavored Markdown (GFM)
  179. syn region highlight_block start='```' end='```'
  180. "" Actually highlight those regions.
  181. hi link math Statement
  182. hi link liquid Statement
  183. hi link highlight_block Function
  184. hi link math_block Function
  185. endfunction
  186. " Call everytime we open a Markdown file
  187. autocmd BufRead,BufNewFile,BufEnter *.md,*.markdown call MathAndLiquid()
  188. Plug 'vim-pandoc/vim-pandoc-syntax'
  189. let g:vim_markdown_math = 1
  190. " Go to tab by number
  191. noremap <leader>1 1gt
  192. noremap <leader>2 2gt
  193. noremap <leader>3 3gt
  194. noremap <leader>4 4gt
  195. noremap <leader>5 5gt
  196. noremap <leader>6 6gt
  197. noremap <leader>7 7gt
  198. noremap <leader>8 8gt
  199. noremap <leader>9 9gt
  200. noremap <leader>0 :tablast<cr>
  201. set noshowmode