CLI config/dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
8.2 KiB

  1. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. " .vimrc
  3. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. " User-specified ~/.vimrc, compatible with vim on GNU/Linux and Apple OS X
  5. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. " Functionality setup
  8. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. " Source a global configuration file if available
  10. if filereadable("/etc/vim/vimrc.local")
  11. source /etc/vim/vimrc.local
  12. endif
  13. " Uncomment the following to have Vim jump to the last position when reopening
  14. " a file
  15. if has("autocmd")
  16. au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
  17. endif
  18. " Uncomment the following to have Vim load indentation rules and plugins
  19. " according to the detected filetype.
  20. if has("autocmd")
  21. filetype plugin indent on
  22. endif
  23. " Use plugin manager if available
  24. if (filereadable($HOME."/.vim/autoload/plug.vim")) || (filereadable("/usr/share/vim/vimfiles/autoload/plug.vim"))
  25. let g:use_pluggin_manager = 1
  26. else
  27. let g:use_pluggin_manager = 0
  28. endif
  29. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  30. " Syntax highlighting
  31. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. if has("syntax")
  33. set t_Co=256
  34. syntax on
  35. " Uncomment the following 'let' lines if using xter16 color scheme
  36. " Select colormap: 'soft', 'softlight', 'standard', or 'allblue'
  37. let xterm16_colormap = 'allblue'
  38. " Select brightness: 'low', 'med', 'high', 'default', or custom levels
  39. let xterm16_brightness = 'high'
  40. "Other override options:
  41. let xterm16fg_Cursor = '555'
  42. let xterm16bg_Normal = 'none'
  43. "Set color scheme
  44. colorscheme xterm16
  45. endif
  46. " If using a dark background within the editing area and syntax highlighting
  47. " turn on this option as well
  48. set background=dark
  49. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. " General options selection
  51. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  52. set showcmd " Show (partial) command in status line.
  53. set showmatch " Show matching brackets.
  54. set ignorecase " Do case insensitive matching
  55. set smartcase " Do smart case matching
  56. set mouse=a " Enable mouse usage (all modes)
  57. set hlsearch " Turn on search highlighting
  58. set shiftwidth=4 " Auto-indent amount when using cindent, <<, >>, etc.
  59. set softtabstop=4 " How many spaces represent a tab
  60. set tabstop=4 " Real tab size
  61. set autoindent " Indent level of new line set by previous line
  62. set cindent " Attempt to intelligently guess level of indent for new line
  63. set cinkeys-=0# " Don't un-indent comments
  64. set indentkeys-=0# " Don't un-indent comments
  65. set nf=octal,hex,alpha " additional ctrl-a increments
  66. set spell spelllang=en_us " Set spell check language
  67. set scrolloff=5 " Add visible lines beyond cursor at top or bottom of window
  68. set linebreak " Soft wrap whole words together
  69. set breakindent " Indent linebreaks to match
  70. set showbreak=\ \ \ ⇲ " Visual linebreak indicator
  71. set updatetime=100 " Make some plugins snappier
  72. set backspace=indent,eol,start " Fix OS X backspace behavior
  73. set ruler " Fix OS X missing ruler
  74. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. " Filetype-specific options
  76. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. autocmd FileType plaintex,tex,latex syntax spell toplevel
  78. autocmd FileType plaintex,tex,latex set tw=80
  79. autocmd FileType tex,latex let g:tex_flavor = 'latex'
  80. autocmd FileType pug,jade set tw=80
  81. autocmd FileType text set tw=80 nocindent
  82. autocmd BufNewFile,BufRead *.cu set filetype=c
  83. autocmd BufNewFile,BufRead *.tp set filetype=taskpaper
  84. aug python
  85. " to override ftype/python.vim
  86. autocmd FileType python setlocal ts=4 sts=4 sw=4 noexpandtab
  87. aug end
  88. syntax spell toplevel
  89. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. " Key mapping customizations
  91. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92. " Turn off search highlighting with Enter
  93. nnoremap <silent> <C-@> :nohlsearch<CR>
  94. nnoremap <silent> <C-l> :GitGutter<CR>:nohlsearch<CR><C-l>
  95. nnoremap <silent> <CR> :nohlsearch<CR><CR>
  96. " Center page on search
  97. noremap n nzz
  98. noremap N Nzz
  99. noremap * *zz
  100. noremap # #zz
  101. noremap g* g*zz
  102. noremap g# g#zz
  103. " Better scrolling keys
  104. noremap <C-n> <C-e>
  105. noremap <C-p> <C-y>
  106. inoremap <C-n> <C-o><C-e>
  107. inoremap <C-p> <C-o><C-y>
  108. " Allow saving files with sudo after starting vim
  109. cmap w!! w !sudo tee > /dev/null %
  110. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. " Plugin helper functions
  112. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  113. " Build script when installing/updating YouCompleteMe
  114. function! BuildYCM(info)
  115. " info is a dictionary with 3 fields
  116. " - name: name of the plugin
  117. " - status: 'installed', 'updated', or 'unchanged'
  118. " - force: set on PlugInstall! or PlugUpdate!
  119. if a:info.status == 'installed' || a:info.force
  120. " YCM dependencies for --all option:
  121. " gcc, make, cmake, python3, clang, mono, go, node.js, npm, rust, jdk8
  122. !./install.py --all
  123. endif
  124. endfunction
  125. " Pick a more convenient spot for the latency from loading YCM
  126. let g:YouCompleteMeLazyLoaded = 0
  127. function! LazyLoadingYMC()
  128. if g:YouCompleteMeLazyLoaded == 0
  129. let g:YouCompleteMeLazyLoaded = 1
  130. call plug#load('YouCompleteMe') | call youcompleteme#Enable()
  131. endif
  132. endfunction
  133. if g:use_pluggin_manager == 1
  134. autocmd BufRead * call timer_start(1, {id->execute('call LazyLoadingYMC()')} )
  135. " (also try BufWinEnter, InsertEnter, or CursorHold and CursorHoldI events)
  136. endif
  137. " Enable vimtex completions for YCM
  138. function! VimtexYCMSetup()
  139. if !exists('g:ycm_semantic_triggers')
  140. let g:ycm_semantic_triggers = {}
  141. endif
  142. if exists('g:vimtex#re#youcompleteme')
  143. let g:ycm_semantic_triggers.tex=g:vimtex#re#youcompleteme
  144. endif
  145. endfunction
  146. if has("autocmd")
  147. autocmd VimEnter * call VimtexYCMSetup()
  148. endif
  149. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. " Plugin setup with vim-plug
  151. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  152. " Use with :PlugInstall and :PlugUpdate
  153. "if exists('g:use_pluggin_manager') && g:use_pluggin_manager
  154. if g:use_pluggin_manager == 1
  155. " Set custom plugin directory
  156. call plug#begin('~/.vim/vim-plug')
  157. Plug 'ycm-core/YouCompleteMe', { 'do': function('BuildYCM'), 'on': [] }
  158. Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
  159. Plug 'dense-analysis/ale'
  160. Plug 'airblade/vim-gitgutter'
  161. Plug 'godlygeek/tabular'
  162. Plug 'tpope/vim-surround'
  163. Plug 'tpope/vim-unimpaired'
  164. Plug 'tpope/vim-speeddating'
  165. Plug 'tpope/vim-repeat'
  166. Plug 'lervag/vimtex'
  167. call plug#end()
  168. endif
  169. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170. " Plugin options
  171. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  172. " Close the YCM preview window automatically
  173. let g:ycm_autoclose_preview_window_after_insertion = 1
  174. let g:ycm_autoclose_preview_window_after_completion = 1
  175. " Suggest language keywords
  176. let g:ycm_seed_identifiers_with_syntax = 1
  177. " Start with ale linting disabled
  178. let g:ale_enabled = 0
  179. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  180. " Plugin key mappings
  181. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  182. " (optionally press / instead of _ for :NERDTreeToggle)
  183. nnoremap <C-_> :NERDTreeToggle<CR>
  184. nnoremap <F2> :ALEToggle<CR>
  185. nmap <silent> [W <Plug>(ale_first)
  186. nmap <silent> ]W <Plug>(ale_last)
  187. nmap <silent> [w <Plug>(ale_previous_wrap)
  188. nmap <silent> ]w <Plug>(ale_next_wrap)
  189. nmap <silent> [e <Plug>(ale_previous_wrap_error)
  190. nmap <silent> ]e <Plug>(ale_next_wrap_error)
  191. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  192. " End
  193. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~