vimrc 6.8 KB

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