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.

346 lines
12 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. " let xterm16fg_Normal = 'none'
  44. " "Set color scheme
  45. " colorscheme xterm16
  46. "endif
  47. " If using a dark background within the editing area and syntax highlighting
  48. " turn on this option as well
  49. set background=dark
  50. " Remove background color from sign column/gutter
  51. highlight clear SignColumn
  52. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. " General options selection
  54. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. set showcmd " Show (partial) command in status line.
  56. set showmatch " Show matching brackets.
  57. set ignorecase " Do case insensitive matching
  58. set smartcase " Do smart case matching
  59. set mouse=a " Enable mouse usage (all modes)
  60. set nohlsearch " Turn off search highlighting
  61. "set hlsearch " Turn on search highlighting
  62. set shiftwidth=4 " Auto-indent amount when using cindent, <<, >>, etc.
  63. set softtabstop=4 " How many spaces represent a tab
  64. set tabstop=4 " Real tab size
  65. set autoindent " Indent level of new line set by previous line
  66. set cindent " Attempt to intelligently guess level of indent for new line
  67. set cinkeys-=0# " Don't un-indent comments
  68. set indentkeys-=0# " Don't un-indent comments
  69. set nf=octal,hex,alpha " additional ctrl-a increments
  70. set spell spelllang=en_us " Set spell check language
  71. set scrolloff=5 " Add visible lines beyond cursor at top or bottom of window
  72. set linebreak " Soft wrap whole words together
  73. set breakindent " Indent linebreaks to match
  74. set showbreak=\ \ \ ⇲ " Visual linebreak indicator
  75. set updatetime=100 " Make some plugins snappier
  76. set backspace=indent,eol,start " Fix OS X backspace behavior
  77. set ruler " Fix OS X missing ruler
  78. "set nowrap
  79. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80. " Filetype-specific options
  81. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. autocmd FileType plaintex,tex,latex syntax spell toplevel
  83. autocmd FileType plaintex,tex,latex set tw=80
  84. autocmd FileType tex,latex let g:tex_flavor = 'latex'
  85. autocmd FileType pug,jade set tw=80
  86. autocmd FileType text,markdown set tw=80 nocindent
  87. autocmd FileType swift set noexpandtab
  88. autocmd BufNewFile,BufRead *.cu set filetype=c
  89. autocmd BufNewFile,BufRead *.tp set filetype=taskpaper
  90. aug python
  91. " to override ftype/python.vim
  92. autocmd FileType python setlocal ts=4 sts=4 sw=4 noexpandtab
  93. aug end
  94. aug python
  95. " to override ftype/python.vim
  96. autocmd FileType scss setlocal ts=4 sts=4 sw=4 noexpandtab
  97. aug end
  98. syntax spell toplevel
  99. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  100. " Key mapping customizations
  101. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  102. " Turn off search highlighting with Enter
  103. nnoremap <silent> <C-@> :nohlsearch<CR>
  104. nnoremap <silent> <C-l> :GitGutter<CR>:nohlsearch<CR><C-l>
  105. nnoremap <silent> <CR> :nohlsearch<CR><CR>
  106. " Yank to global clipboard
  107. noremap Y "+y
  108. " Center page on search (breaks 'search hit bottom...' message)
  109. "noremap n nzz
  110. "noremap N Nzz
  111. "noremap * *zz
  112. "noremap # #zz
  113. "noremap g* g*zz
  114. "noremap g# g#zz
  115. " Better scrolling keys
  116. noremap <C-n> <C-e>
  117. noremap <C-p> <C-y>
  118. inoremap <C-n> <C-o><C-e>
  119. inoremap <C-p> <C-o><C-y>
  120. " Allow saving files with sudo after starting vim
  121. cmap w!! w !sudo tee > /dev/null %
  122. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  123. " Plugin helper functions
  124. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  125. " Build script when installing/updating YouCompleteMe
  126. function! BuildYCM(info)
  127. " info is a dictionary with 3 fields
  128. " - name: name of the plugin
  129. " - status: 'installed', 'updated', or 'unchanged'
  130. " - force: set on PlugInstall! or PlugUpdate!
  131. if a:info.status == 'installed' || a:info.force
  132. " YCM dependencies for --all option:
  133. " gcc, make, cmake, python3, clang, mono, go, node.js, npm, rust, jdk8
  134. !./install.py --all
  135. endif
  136. endfunction
  137. " Pick a more convenient spot for the latency from loading YCM
  138. "let g:YouCompleteMeLazyLoaded = 0
  139. "function! LazyLoadingYMC()
  140. " if g:YouCompleteMeLazyLoaded == 0
  141. " let g:YouCompleteMeLazyLoaded = 1
  142. " call plug#load('YouCompleteMe') | call youcompleteme#Enable()
  143. " endif
  144. "endfunction
  145. "if g:use_pluggin_manager == 1
  146. " autocmd BufRead * call timer_start(1, {id->execute('call LazyLoadingYMC()')} )
  147. " " (also try BufWinEnter, InsertEnter, or CursorHold and CursorHoldI events)
  148. "endif
  149. " Enable vimtex completions for YCM
  150. function! VimtexYCMSetup()
  151. if !exists('g:ycm_semantic_triggers')
  152. let g:ycm_semantic_triggers = {}
  153. endif
  154. if exists('g:vimtex#re#youcompleteme')
  155. let g:ycm_semantic_triggers.tex=g:vimtex#re#youcompleteme
  156. endif
  157. endfunction
  158. if has("autocmd")
  159. autocmd VimEnter * call VimtexYCMSetup()
  160. endif
  161. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  162. " Plugin setup with vim-plug
  163. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  164. " Use with :PlugInstall and :PlugUpdate
  165. "if exists('g:use_pluggin_manager') && g:use_pluggin_manager
  166. if g:use_pluggin_manager == 1
  167. " Set custom plugin directory
  168. call plug#begin('~/.vim/vim-plug')
  169. "Plug 'ycm-core/YouCompleteMe', { 'do': function('BuildYCM'), 'on': [] }
  170. Plug 'ycm-core/YouCompleteMe', { 'do': function('BuildYCM') }
  171. Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
  172. Plug 'dense-analysis/ale'
  173. Plug 'airblade/vim-gitgutter'
  174. Plug 'godlygeek/tabular'
  175. Plug 'tpope/vim-surround'
  176. Plug 'tpope/vim-unimpaired'
  177. Plug 'tpope/vim-speeddating'
  178. Plug 'tpope/vim-repeat'
  179. Plug 'tpope/vim-fugitive'
  180. Plug 'lervag/vimtex'
  181. Plug 'junegunn/goyo.vim'
  182. Plug 'junegunn/limelight.vim'
  183. Plug 'joshdick/onedark.vim', { 'branch': 'main' }
  184. call plug#end()
  185. endif
  186. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  187. " Plugin options
  188. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  189. " Close the YCM preview window automatically
  190. let g:ycm_autoclose_preview_window_after_insertion = 1
  191. let g:ycm_autoclose_preview_window_after_completion = 1
  192. " Suggest language keywords
  193. let g:ycm_seed_identifiers_with_syntax = 1
  194. " Start with ale linting disabled
  195. let g:ale_enabled = 0
  196. " Activate Limelight with Goyo and fix colors
  197. autocmd! User GoyoEnter Limelight
  198. autocmd! User GoyoLeave Limelight!
  199. let g:limelight_conceal_ctermfg = 'gray'
  200. let g:limelight_conceal_guifg = 'DarkGray'
  201. " Set up color scheme for onedark.vim
  202. let s:colors = onedark#GetColors()
  203. let g:onedark_terminal_italics = 0
  204. let g:onedark_color_overrides = {
  205. \ "comment_grey": { "gui": "#8888A2", "cterm": "59", "cterm16": "7" }
  206. \}
  207. "Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
  208. "If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
  209. "(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
  210. if (empty($TMUX))
  211. if (has("nvim"))
  212. "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
  213. let $NVIM_TUI_ENABLE_TRUE_COLOR=1
  214. endif
  215. "For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
  216. "Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
  217. " < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
  218. " if (has("termguicolors")) " disabling this seems to fix colors over Shelly
  219. " set termguicolors
  220. " endif
  221. endif
  222. if (has("autocmd"))
  223. augroup colorextend
  224. autocmd!
  225. " Override the `Identifier` background color in GUI mode
  226. autocmd ColorScheme * call onedark#extend_highlight("String", { "fg": s:colors.cyan })
  227. "autocmd ColorScheme * call onedark#extend_highlight("String", { "fg": { "gui": "#AAFFFF" } })
  228. augroup END
  229. augroup colorset
  230. autocmd!
  231. autocmd ColorScheme * call onedark#set_highlight("SpellBad", { "gui": "underline", "cterm": "underline" })
  232. autocmd ColorScheme * call onedark#set_highlight("SpellCap", { "gui": "italic", "cterm": "italic" })
  233. autocmd ColorScheme * call onedark#set_highlight("SpellRare", { "gui": "italic", "cterm": "italic" })
  234. autocmd ColorScheme * call onedark#set_highlight("SpellLocal", { })
  235. autocmd ColorScheme * call onedark#set_highlight("Keyword", { "fg": s:colors.blue })
  236. autocmd ColorScheme * call onedark#set_highlight("Identifier", { "fg": s:colors.blue })
  237. augroup END
  238. endif
  239. " onedark.vim override: Don't set a background color when running in a terminal;
  240. " `gui` is the hex color code used in GUI mode/nvim true-color mode
  241. " `cterm` is the color code used in 256-color mode
  242. " `cterm16` is the color code used in 16-color mode
  243. if (has("autocmd") && !has("gui_running"))
  244. augroup colorsetdefault
  245. autocmd!
  246. "let s:white = { "gui": "#ABB2BF", "cterm": "145", "cterm16" : "7" }
  247. let s:white = { "gui": "#FFFFFF", "cterm": "255", "cterm16" : "15" }
  248. autocmd ColorScheme * call onedark#set_highlight("Normal", { "fg": s:white }) " `bg` will not be styled since there is no `bg` setting
  249. augroup END
  250. endif
  251. syntax on
  252. colorscheme onedark
  253. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  254. " Plugin key mappings
  255. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  256. " (optionally press / instead of _ for :NERDTreeToggle)
  257. nnoremap <C-_> :NERDTreeToggle<CR>
  258. nnoremap <F2> :ALEToggle<CR>
  259. nmap <silent> [W <Plug>(ale_first)
  260. nmap <silent> ]W <Plug>(ale_last)
  261. nmap <silent> [w <Plug>(ale_previous_wrap)
  262. nmap <silent> ]w <Plug>(ale_next_wrap)
  263. nmap <silent> [e <Plug>(ale_previous_wrap_error)
  264. nmap <silent> ]e <Plug>(ale_next_wrap_error)
  265. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  266. " End
  267. "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~