vimrc 9.3 KB

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