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.

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