vimrc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. set fileencoding=utf-8 " Set utf-8 encoding on write
  2. scriptencoding utf-8
  3. """"""""""""""""""""""""""""""
  4. " ~ VIMRC ~ for Vim >= 8 && Neovim
  5. " Author: Chris Jones
  6. " Source: http://github.com/ipatch/dotfiles/blob/master/editors/vim/vimrc
  7. " Source: https://git.io/vpEKR
  8. ""
  9. """"""""""""""""""""""""""""""
  10. " Notes / gotchas - some good things to know before hacking `~/.vimrc`
  11. " NOTE: this rc file is being linted with `vint`
  12. " NOTE: https://github.com/Kuniwak/vint
  13. " NOTE: To print the value of a setting, ie. return the set value
  14. " `:set autoindent?`
  15. " SEE: `~/.vim/after/ftplugin/vim.vim` for settings related to `.vim`
  16. ""
  17. " set this first, the default `leader` key is `\`
  18. let g:mapleader = "\<Space>" " bind 'leader' key to spacebar
  19. " Don't allow vi compatibility mode; don't need it 🤽
  20. " NOTE: as of nov 2020, `nocompatible` is default for Vim ≥ 8.2 and Neovim
  21. " set nocompatible "Enable at own risk, can have undesired effects
  22. " SEE: `:help nocompatible` for more info.
  23. ""
  24. """""""""""""""""""""""""""""
  25. " NOTE: Settings - June 23 2018 moved to `~/.vim/plugin/settings.vim`
  26. ""
  27. """""""""""""""""""""""""""""
  28. " Key mappings / bindings
  29. " NOTE: mappings - June 23 2018 moved to `~/.vim/plugin/mappings.vim`
  30. ""
  31. """"""""""""""""""""""""""""""
  32. " check for current OS
  33. " NOTE: `:echo os` to print the variable value in the current buffer
  34. " NOTE: if (n)vim has access to both clipboards it will put copy / paste operations into both clipboards.
  35. ""
  36. function! GetRunningOS()
  37. if has('win32')
  38. return 'win32'
  39. elseif has('win32unix')
  40. return 'win32unix'
  41. elseif has('macunix')
  42. if !empty($TMUX)
  43. " echom 'wtf'
  44. " let g:clipboard+=tmux
  45. set clipboard+=unnamed,unnamedplus
  46. else
  47. set clipboard+=unnamed,unnamedplus
  48. " pbcopy for macOS copy/paste
  49. " vmap <C-x> :!pbcopy<CR>
  50. " vmap <C-c> :w !pbcopy<CR><CR>
  51. endif
  52. set shell=bash
  53. set runtimepath+=/usr/local/opt/fzf
  54. return 'macos'
  55. elseif has ('unix')
  56. if system('uname')=~?'Linux'
  57. if !empty($TMUX)
  58. " TODO: figure out how to set clipboard properly through ssh
  59. " let g:clipboard+=tmux
  60. " set clipboard+=xsel
  61. else
  62. " set clipboard+=xsel
  63. endif
  64. set shell=bash
  65. set runtimepath+=/home/linuxbrew/.linuxbrew/bin/fzf
  66. return 'linux'
  67. endif
  68. else
  69. " catch all 🎣 for everything else
  70. " No love 💔 for the other guys
  71. endif
  72. endfunction
  73. let g:os = GetRunningOS()
  74. function! SetupCommandAlias(from, to)
  75. " NOTE: useful for aliasing `PackUpdate` to `packupdate` etc...
  76. exec 'cnoreabbrev <expr> '.a:from
  77. \ .' ((getcmdtype() is# ":" && getcmdline() is# "'.a:from.'")'
  78. \ .'? ("'.a:to.'") : ("'.a:from.'"))'
  79. endfunction
  80. """"""""""""""""""""""""""""""
  81. " fonts
  82. ""
  83. highlight Comment gui=italic
  84. highlight Comment cterm=italic
  85. let &t_8f="\<Esc>[38;2;%lu;%lu;%lum"
  86. let &t_8b="\<Esc>[48;2;%lu;%lu;%lum"
  87. set termguicolors " use guifg/guibg instead of ctermfg/ctermbg in terminal
  88. """""""""""""""""""""""""""""
  89. " conceal levels
  90. " toggle between different conceal levels
  91. " NOTE: `indentLine` will control conceal levels if installed
  92. ""
  93. function! ToggleConcealLevel()
  94. if &conceallevel == 0
  95. setlocal conceallevel=2
  96. elseif &conceallevel == 1
  97. setlocal conceallevel=0
  98. elseif &conceallevel == 2
  99. setlocal conceallevel=0
  100. endif
  101. endfunction
  102. nnoremap <silent> ` :call ToggleConcealLevel()<CR>
  103. " set default conceal level
  104. set conceallevel=0 " DO NOT conceal any text
  105. let g:indentLine_fileTypeExclude = ['json']
  106. """""""""""""""""""""""""""""
  107. " netrw - file explorer
  108. " CREDIT: https://shapeshed.com/vim-netrw/
  109. ""
  110. let g:netrw_liststyle = 3 " tree style
  111. let g:netrw_banner = 0 " Do not display the banner when using Netrw
  112. let g:netrw_browse_split = 1 " TODO: figure out what this variable does ???
  113. let g:netrw_winsize = 25 " set the default width for netrw
  114. " TODO: document what the below variable does to netrw
  115. let g:netrw_altv = 1
  116. " Set atom style macOS key binding to open the project drawer
  117. " CREDIT: https://stackoverflow.com/a/23069285/708807
  118. " NOTE: toggling netrw sucks!
  119. " TODO: get a sane toggle expierence going ...eventually!
  120. nnoremap <M-\> :Lexplore<cr>
  121. inoremap <M-\> :Lexplore<cr>
  122. " OPTIONAL: keep netrw browsing dir the same as current dir
  123. " `let g:netrw-keepdir = 0`
  124. " https://vi.stackexchange.com/a/13012
  125. " Per default, netrw leaves unmodified buffers open. This autocommand
  126. " deletes netrw's buffer once it's hidden (using `:q`, for example)
  127. augroup netrw_delete_hidden_augroup
  128. autocmd!
  129. autocmd FileType netrw setl bufhidden=delete
  130. augroup END
  131. "----------------------------
  132. " Autocommands relocated to `~/.vim/plugin/autocmds.vim`
  133. ""
  134. "----------------------------
  135. " wildmenu - completion
  136. "-
  137. if has('wildmenu')
  138. set wildmenu " display menu when using `tab` completeion
  139. set wildmode=full " Specifies how the `tab` completion works in wildmenu
  140. set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
  141. set wildignore+=*/.git/* " ignore the below directories with wild menu
  142. set wildignore+=*logs*
  143. set wildignore+=*node_modules/**
  144. set wildignore+=package-lock.json
  145. set wildignore+=yarn.lock
  146. set wildignore+=*DS_Store*
  147. set wildignore+=*.gem
  148. set wildignore+=log/**
  149. set wildignore+=_build/**
  150. set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png,*.pdf,*.psd,session.vim
  151. set wildignore+=tags
  152. endif
  153. " NOTE: clone minpac first before installing plugins.
  154. set packpath^=~/.vim
  155. " Try to load minpac.
  156. silent! packadd minpac
  157. function! BuildStaticVimMarkdownComposer()
  158. " if a:info.status != 'unchanged' || a:info.force
  159. if has('nvim')
  160. !(cd '/opt/code/dotfiles/editors/vim/vim/pack/minpac/start/vim-markdown-composer'; cargo +nightly build --release)
  161. " !cargo build --release
  162. elseif v:version > 8 || v:version == 8 " Check for Vim8 ...sort of
  163. !(cd '/opt/code/dotfiles/editors/vim/vim/pack/minpac/start_vim8/vim-markdown-composer';cargo build --release --no-default-features --features json-rpc)
  164. " Explicity set path for Vim8 build of vim-markdown-composer
  165. set runtimepath+=/opt/code/dotfiles/editors/vim/vim/pack/minpac/start_vim8/vim-markdown-composer
  166. set runtimepath-=/opt/code/dotfiles/editors/vim/vim/pack/minpac/start/vim-markdown-composer
  167. endif
  168. endfunction
  169. " plugin specfic settings
  170. " let g:markdown_composer_autostart = 1
  171. " let g:ale_completion_enabled = 1
  172. function! FixupBase16()
  173. !(sed -i '/Base16hi/\! s/a:\(attr\|guisp\)/l:\1/g' /opt/code/dotfiles/editors/vim/vim/pack/minpac/start/base16-vim/colors/*.vim)
  174. endfunction
  175. " below `if` block/statement stopped working on september 26, 2020
  176. " if !exists('*minpac#init')
  177. " SEE: advanced sample on github readme of minpac
  178. if !exists('g:loaded_minpac')
  179. " minpac is NOT available
  180. echo 'Yo!, you need minpac dawg!'
  181. " Settings for plugin-less, ie. no minpac 😥 environment.
  182. if empty(glob('~/.vim/pack/minpac/opt/minpac/plugin/minpac.vim'))
  183. silent !curl -fLo ~/.vim/pack/minpac/opt/minpac/plugin/minpac.vim
  184. \--create-dirs
  185. \https://raw.githubusercontent.com/k-takata/minpac/master/plugin/minpac.vim
  186. autocmd VimEnter * packadd minpac
  187. call minpac#init()
  188. call minpac#add('k-takata/minpac', {'type': 'opt'})
  189. endif
  190. else
  191. " minpac found
  192. call minpac#init()
  193. call minpac#add('k-takata/minpac', {'type': 'opt'})
  194. "-----------------------------
  195. " Load additional plugins
  196. "-
  197. call minpac#add('machakann/vim-highlightedyank') " name says it all
  198. call minpac#add('chriskempson/base16-vim') " UX goodness
  199. call minpac#add('Yggdroot/indentLine') " vert indent lines
  200. call minpac#add('tpope/vim-commentary') " quickly comment lines
  201. call minpac#add('sheerun/vim-polyglot') " lazy load syntax hl
  202. call minpac#add('christoomey/vim-tmux-navigator') " vim&tmux navi
  203. call minpac#add('tpope/vim-fugitive') " display git branch
  204. call minpac#add('itchyny/lightline.vim') " lightweight status line.
  205. call minpac#add('rust-lang/rust.vim')
  206. " call minpac#add('euclio/vim-markdown-composer')
  207. " call minpac#add('euclio/vim-markdown-composer', {'type': 'opt'})
  208. call minpac#add('majutsushi/tagbar')
  209. "
  210. " call minpac#add('joshdick/onedark.vim') " exp with new colorscheme
  211. " call minpac#add('w0rp/ale') " Asynchronous Linting Engine
  212. " call minpac#add('tpope/vim-obsession') " auto session mgmt
  213. " call minpac#add('MaxMEllon/vim-jsx-pretty') " syntax highlight
  214. "-----------------------------
  215. " minpac - conditional plugins
  216. "---------------------------------------------------------------
  217. " neovim only plugins!!!
  218. "---------------------------------------------------------------
  219. ""
  220. if has('nvim')
  221. call minpac#add('Shougo/denite.nvim')
  222. " call minpac#add('Shougo/denite.nvim', {'rev': '29bfd4c53271c7a150def2388e059746ae4c1713'})
  223. call minpac#add('neoclide/coc.nvim', {'branch': 'release'})
  224. elseif v:version > 8 || v:version == 8 " Check for Vim8 ...sort of
  225. call minpac#add('autozimu/LanguageClient-neovim', {'type': 'opt',
  226. \'branch': 'next', 'do': {-> system('bash install.sh')}})
  227. endif
  228. "----------------------------
  229. " minpac - Custom commands
  230. "-
  231. command! PackUpdate packadd minpac | source $MYVIMRC | call minpac#update('', {'do': 'call minpac#status()'})
  232. command! PackClean packadd minpac | source $MYVIMRC | call minpac#clean()
  233. command! PackList echo join(minpac#getpackages("minpac", "start"), "\n")
  234. command! PackStatus packadd minpac | source $MYVIMRC | call minpac#status()
  235. call SetupCommandAlias("packupdate", "PackUpdate")
  236. call SetupCommandAlias("packclean", "PackClean")
  237. call SetupCommandAlias("packstatus", "PackStatus")
  238. endif
  239. "----------------------------
  240. " DANGER ZONE > experimental settings
  241. "-
  242. " exp with floating window for fuzzy searching for files using fzf
  243. " " floating fzf
  244. " if has('nvim')
  245. " let $FZF_DEFAULT_OPTS .= '--layout=reverse'
  246. " function! FloatingFZF()
  247. " let height = &lines
  248. " let width = float2nr(&columns - (&columns * 2 / 10))
  249. " let col = float2nr((&columns - width) / 2)
  250. " let col_offset = &columns / 10
  251. " let opts = {
  252. " \ 'relative': 'editor',
  253. " \ 'row': 1,
  254. " \ 'col': col + col_offset,
  255. " \ 'width': width * 2/ 1,
  256. " \ 'height': height / 2,
  257. " \ 'style': 'minimal'
  258. " \ }
  259. " let buf = nvim_create_buf(v:false, v:true)
  260. " let win = nvim_open_win(buf, v:true,opts)
  261. " call setwinvar(win, '&winhl', 'NormalFloat:TabLine')
  262. " endfunction
  263. " let g:fzf_layout = { 'window': 'call FloatingFZF()' }
  264. " endif
  265. "----------------------------
  266. " END < DANGER ZONE
  267. "-
  268. " Setting for rust.vim
  269. " TODO: move to language specific setting file, ie. `rust.vim`
  270. let g:autofmt_autosave = 1
  271. "----------------------------
  272. " For Neovim's eyes only
  273. "-
  274. if has('nvim')
  275. let g:loaded_sensible=0
  276. " Keymappings for Neovim
  277. " Neovim defaults to `<C-\><C-n>` to exit a virtual terminal
  278. tnoremap <Esc> <C-\><C-n>
  279. tnoremap <A-[> <Esc>
  280. if has('nvim-0.1.5')
  281. set termguicolors " use guifg/guibg instead of ctermfg/ctermbg in terminal
  282. hi Cursor guifg=green guibg=green
  283. hi Cursor2 guifg=red guibg=red
  284. set guicursor=n-v-c:block-Cursor/lCursor,i-ci-ve:ver25-Cursor2/lCursor2,r-cr:hor20,o:hor50
  285. elseif
  286. let $NVIM_TUI_ENABLE_TRUE_COLOR = 1 " Legacy way to enable 24bit color.
  287. endif
  288. endif " END Neovim only settings
  289. """"""""""""""""""""""""""""""
  290. " colorscheme
  291. ""
  292. " NOTE: make scope explicit, ie. `let g:[mr-fancy-setting]` NOT `let
  293. " [mr-fancy-setting`
  294. "let g:base16colorspace = 256 " Access colors present in 256 colorspace
  295. "onedark.vim override: Set a custom background color in the terminal
  296. " NOTE: set custom gui settings for `ondark.vim` BEFORE init colorscheme
  297. if (has("autocmd") && !has("gui_running"))
  298. augroup colors
  299. autocmd!
  300. let s:background = { "gui": "#101010", "cterm": "235", "cterm16": "0" }
  301. autocmd ColorScheme * call onedark#set_highlight("Normal", { "bg": s:background }) "No `fg` setting
  302. augroup END
  303. endif
  304. if (has("autocmd"))
  305. augroup colorextend
  306. autocmd!
  307. " Make `Function`s bold in GUI mode
  308. autocmd ColorScheme * call onedark#extend_highlight("Function", { "gui": "bold" })
  309. " Override the `Statement` foreground color in 256-color mode
  310. autocmd ColorScheme * call onedark#extend_highlight("Statement", { "fg": { "cterm": 128 } })
  311. " Override the `Identifier` background color in GUI mode
  312. " autocmd ColorScheme * call onedark#extend_highlight("Identifier", { "bg": { "gui": "#333333" } })
  313. autocmd ColorScheme * call onedark#extend_highlight("FoldColumn", { "fg": { "gui": "#4b5263" } })
  314. augroup END
  315. endif
  316. " TODO: add check if colorscheme is not present, and continue loading file
  317. " colorscheme base16-default-dark
  318. colorscheme onedark
  319. """"""""""""""""
  320. " load before plugins - polyglot
  321. ""
  322. " let g:polyglot_disabled = ['json']