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.

257 lines
8.1 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> <CR> :nohlsearch<CR><CR>
  94. " Center page on search
  95. noremap n nzz
  96. noremap N Nzz
  97. noremap * *zz
  98. noremap # #zz
  99. noremap g* g*zz
  100. noremap g# g#zz
  101. " Better scrolling keys
  102. noremap <C-n> <C-e>
  103. noremap <C-p> <C-y>
  104. inoremap <C-n> <C-o><C-e>
  105. inoremap <C-p> <C-o><C-y>
  106. " Allow saving files with sudo after starting vim
  107. cmap w!! w !sudo tee > /dev/null %
  108. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  109. " Plugin helper functions
  110. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. " Build script when installing/updating YouCompleteMe
  112. function! BuildYCM(info)
  113. " info is a dictionary with 3 fields
  114. " - name: name of the plugin
  115. " - status: 'installed', 'updated', or 'unchanged'
  116. " - force: set on PlugInstall! or PlugUpdate!
  117. if a:info.status == 'installed' || a:info.force
  118. " YCM dependencies for --all option:
  119. " gcc, make, cmake, python3, clang, mono, go, node.js, npm, rust, jdk8
  120. !./install.py --all
  121. endif
  122. endfunction
  123. " Pick a more convenient spot for the latency from loading YCM
  124. let g:YouCompleteMeLazyLoaded = 0
  125. function! LazyLoadingYMC()
  126. if g:YouCompleteMeLazyLoaded == 0
  127. let g:YouCompleteMeLazyLoaded = 1
  128. call plug#load('YouCompleteMe') | call youcompleteme#Enable()
  129. endif
  130. endfunction
  131. if g:use_pluggin_manager == 1
  132. autocmd BufRead * call timer_start(1, {id->execute('call LazyLoadingYMC()')} )
  133. " (also try BufWinEnter, InsertEnter, or CursorHold and CursorHoldI events)
  134. endif
  135. " Enable vimtex completions for YCM
  136. function! VimtexYCMSetup()
  137. if !exists('g:ycm_semantic_triggers')
  138. let g:ycm_semantic_triggers = {}
  139. endif
  140. if exists('g:vimtex#re#youcompleteme')
  141. let g:ycm_semantic_triggers.tex=g:vimtex#re#youcompleteme
  142. endif
  143. endfunction
  144. if has("autocmd")
  145. autocmd VimEnter * call VimtexYCMSetup()
  146. endif
  147. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  148. " Plugin setup with vim-plug
  149. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. " Use with :PlugInstall and :PlugUpdate
  151. "if exists('g:use_pluggin_manager') && g:use_pluggin_manager
  152. if g:use_pluggin_manager == 1
  153. " Set custom plugin directory
  154. call plug#begin('~/.vim/vim-plug')
  155. Plug 'ycm-core/YouCompleteMe', { 'do': function('BuildYCM'), 'on': [] }
  156. Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
  157. Plug 'dense-analysis/ale'
  158. Plug 'airblade/vim-gitgutter'
  159. Plug 'godlygeek/tabular'
  160. Plug 'tpope/vim-surround'
  161. Plug 'tpope/vim-unimpaired'
  162. Plug 'tpope/vim-speeddating'
  163. Plug 'tpope/vim-repeat'
  164. Plug 'lervag/vimtex'
  165. call plug#end()
  166. endif
  167. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168. " Plugin options
  169. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170. " Close the YCM preview window automatically
  171. let g:ycm_autoclose_preview_window_after_insertion = 1
  172. let g:ycm_autoclose_preview_window_after_completion = 1
  173. " Start with ale linting disabled
  174. let g:ale_enabled = 0
  175. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  176. " Plugin key mappings
  177. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  178. " (optionally press / instead of _ for :NERDTreeToggle)
  179. nnoremap <C-_> :NERDTreeToggle<CR>
  180. nnoremap <F2> :ALEToggle<CR>
  181. nmap <silent> [W <Plug>(ale_first)
  182. nmap <silent> ]W <Plug>(ale_last)
  183. nmap <silent> [w <Plug>(ale_previous_wrap)
  184. nmap <silent> ]w <Plug>(ale_next_wrap)
  185. nmap <silent> [e <Plug>(ale_previous_wrap_error)
  186. nmap <silent> ]e <Plug>(ale_next_wrap_error)
  187. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188. " End
  189. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~