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.

563 lines
16 KiB

4 years ago
  1. " How to install me:
  2. "
  3. " git clone http://code.p1k3.com/gitea/brennen/wmf-engprod-offsite-slides.git
  4. " mkdir -p ~/.vim/bundle
  5. " cp wmf-engprod-offsite-slides/vim/vimrc ~/.vim/vimrc
  6. " git clone https://github.com/VundleVim/Vundle.vim ~/.vim/bundle/Vundle.vim
  7. " vim +PluginInstall
  8. " Use comma for the leader key
  9. let mapleader = ","
  10. " 1. Package management {{{
  11. set nocompatible
  12. " Disable modelines for security:
  13. set nomodeline
  14. filetype off
  15. set rtp+=~/.vim/bundle/Vundle.vim/
  16. call vundle#begin()
  17. " Let Vundle manage Vundle - required:
  18. Plugin 'VundleVim/Vundle.vim'
  19. " Really nice file tree - see keybindings section below for some tweaks:
  20. Plugin 'preservim/nerdtree'
  21. Plugin 'Xuyuanp/nerdtree-git-plugin'
  22. " Double click to open nodes:
  23. " (for directory nodes with a single click, set to 2)
  24. " (for all nodes with a single click, set to 3)
  25. let NERDTreeMouseMode = 1
  26. " Fancy start screen with recent files & bookmarks
  27. Plugin 'mhinz/vim-startify'
  28. let g:startify_bookmarks = [ {'v': '~/code/wmf'}, '~/.bashrc', '~/notes/' ]
  29. " Vim Outliner of Markups - see :help voom - no idea yet if this is any good
  30. Plugin 'vim-voom/VOoM'
  31. " Align text vertically on a string:
  32. Plugin 'Align'
  33. " Wrap common version control commands:
  34. Plugin 'vcscommand.vim'
  35. Plugin 'tpope/vim-fugitive'
  36. " Visual marking of changes in working tree:
  37. Plugin 'git://github.com/airblade/vim-gitgutter.git'
  38. " commands for surrounding chars:
  39. Plugin 'tpope/vim-repeat' " used by vim-surround, commentary
  40. Plugin 'tpope/vim-surround'
  41. " Readline-style keybindings in command line / insert:
  42. Plugin 'tpope/vim-rsi'
  43. " Enable gc[motion] to comment, gcc to comment current line:
  44. Plugin 'https://tpope.io/vim/commentary.git'
  45. " A bunch of colorschemes + a gui menu listing them:
  46. Plugin 'flazz/vim-colorschemes'
  47. Plugin 'altercation/vim-colors-solarized'
  48. Plugin 'chriskempson/vim-tomorrow-theme.git'
  49. Plugin 'desert-warm-256'
  50. Plugin 'ColorSchemeMenuMaker'
  51. Plugin 'ScrollColors'
  52. " beyondgrep.com:
  53. Plugin 'mileszs/ack.vim'
  54. " fzf - fuzzy finding
  55. " https://github.com/junegunn/fzf
  56. let g:fzf_launcher = '/usr/bin/xterm'
  57. Plugin 'junegunn/fzf'
  58. " Preview contents of named registers:
  59. Plugin 'junegunn/vim-peekaboo'
  60. " ASCII art - ,di to start, arrow keys to draw lines, ,ds to stop:
  61. Plugin 'DrawIt'
  62. " Most recently used files - my fork allows for a top-level menu:
  63. let g:MRU_Menu_Path = '&Recent\ Files'
  64. let g:MRU_Max_Menu_Entries = 30
  65. let g:MRU_Max_Submenu_Entries = 30
  66. Plugin 'https://code.p1k3.com/gitea/brennen/mru.git'
  67. " Do stuff with tables - used by some vim-markdown features:
  68. Plugin 'godlygeek/tabular'
  69. " Filetypes / modes / language support {{{
  70. let g:go_version_warning = 0
  71. Plugin 'fatih/vim-go' " golang
  72. Plugin 'rust-lang/rust.vim'
  73. Plugin 'chikamichi/mediawiki.vim'
  74. Plugin 'plasticboy/vim-markdown'
  75. Plugin 'nginx.vim'
  76. Plugin 'jceb/vim-orgmode'
  77. " }}}
  78. " Graceful syntax checking for many languages:
  79. " - apt-get install shellcheck for shell linting
  80. Plugin 'vim-syntastic/syntastic'
  81. let g:syntastic_check_on_open = 1
  82. let g:syntastic_php_checkers = ['php']
  83. let g:syntastic_enable_perl_checker = 1
  84. let g:syntastic_perl_lib_path = ['./lib', './lib/auto']
  85. let g:syntastic_perl_checkers = ['perl', 'podchecker']
  86. " Fancy status line; laststatus can be set so it always shows up:
  87. Plugin 'vim-airline/vim-airline'
  88. Plugin 'vim-airline/vim-airline-themes'
  89. let g:airline_theme = 'luna'
  90. if has("gui_running")
  91. let g:airline_theme = 'base16_ashes'
  92. endif
  93. " GUI font size - use <Leader><Leader>+ or - to adjust
  94. Plugin 'drmikehenry/vim-fontsize'
  95. " Ctrl-A increment / Ctrl-X decrement various date formats with this one:
  96. " try, for example: Tue, 26 Jan 2016 23:59:59 +0000
  97. Plugin 'tpope/vim-speeddating'
  98. " Open files at the cursor position where you left off (awesome):
  99. Plugin 'farmergreg/vim-lastplace'
  100. " Handle .editorconfig files:
  101. " https://editorconfig.org/
  102. " https://github.com/editorconfig/editorconfig-vim
  103. Plugin 'editorconfig-vim'
  104. " a calendar - used in conjunction with vimwiki diaries
  105. let g:calendar_keys = {
  106. \ 'goto_next_month': '<C-Right>',
  107. \ 'goto_prev_month': '<C-Left>',
  108. \ 'goto_next_year': '<C-Up>',
  109. \ 'goto_prev_year': '<C-Down>'
  110. \ }
  111. Plugin 'mattn/calendar-vim'
  112. Plugin 'mbbill/undotree'
  113. " Vimwiki - for notes, daily logs, etc. {{{
  114. " Main personal wiki:
  115. let wiki = {}
  116. let wiki.path = '~/vimwiki/'
  117. let wiki.path_html = '~/html/'
  118. let wiki.auto_tags = 1
  119. let wiki.auto_diary_index = 1
  120. let wiki.automatic_nested_syntaxes = 1
  121. " This could be a list containing many vimwikis:
  122. let g:vimwiki_list = [wiki]
  123. " Don't make temporary wikis based on file extensions in the list - this
  124. " is necessary to avoid .md files getting a filetype of vimwiki instead of
  125. " markdown:
  126. let g:vimwiki_global_ext = 0
  127. let g:vimwiki_folding = 'expr'
  128. " let g:vimwiki_folding = 'syntax'
  129. " let g:vimwiki_folding = 'list'
  130. " Link concealing when cursor not on line, etc.:
  131. " let g:vimwiki_conceallevel = 0
  132. " Don't obscure URLs in links:
  133. " let g:vimwiki_url_maxsave = 0
  134. " Make links clickable and such:
  135. let g:vimwiki_use_mouse = 1
  136. " Use colors in header highlighting
  137. let g:vimwiki_hl_headers = 1
  138. Plugin 'vimwiki/vimwiki'
  139. augroup bpb_vimwiki
  140. " clear any existing commands in this group:
  141. autocmd!
  142. " selectively activate foldcolumn:
  143. au FileType vimwiki setlocal foldcolumn=3
  144. " regenerate vimwiki diary on file load:
  145. " (with auto_diary_index, the index is updated every time you use
  146. " ,wi to open - this covers the rest of the cases, i guess)
  147. au BufReadPost,BufNewFile *vimwiki/diary/diary.wiki :VimwikiDiaryGenerateLinks
  148. " set up linewrapping so that long lines more or less work
  149. au BufRead,BufNewFile *.wiki call <SID>LonglineMode()
  150. augroup END
  151. " }}}
  152. call vundle#end()
  153. filetype plugin on
  154. filetype indent on
  155. " }}}
  156. " 2. miscellaneous UI {{{
  157. " Set the window title (usually to filename plus some metadata):
  158. set title
  159. " Pretty colors:
  160. set t_Co=256
  161. syntax on
  162. " Pretty characters:
  163. set encoding=utf-8
  164. " Do not beep or flash at me:
  165. " vb is needed to stop beep
  166. " t_vb sets visual bell action, we're nulling it out here
  167. " note also that this may need to be repeated in .gvimrc
  168. set visualbell
  169. set t_vb=
  170. " Enable mouse for (a)ll, (n)ormal, (v)isual, (i)nsert, or (c)ommand line
  171. " mode - works in most terminals:
  172. set mouse=a
  173. " Let me delete stuff while in insert mode:
  174. set backspace=indent,eol,start
  175. " Display commands as-typed + current position in file:
  176. set showcmd
  177. set ruler
  178. " Set height of command line area - having it greater than one avoids some
  179. " hit-enter prompts:
  180. set cmdheight=2
  181. " Display a visual menu for tab-completion of files:
  182. set wildmenu
  183. " Keep lots of command-line history - 10000 is currently the max value:
  184. set history=10000
  185. " Search:
  186. set incsearch
  187. set ignorecase
  188. set smartcase
  189. set wrapscan
  190. " neovim defaults hlsearch to on, which annoys me personally
  191. set nohlsearch
  192. " use + register (x window clipboard) as unnamed register (copy to system
  193. " clipboard on yy, for example):
  194. if has('nvim')
  195. set clipboard+=unnamedplus
  196. else
  197. set clipboard=unnamedplus,autoselect
  198. endif
  199. " }}}
  200. " 3. File saving/loading/swap/backups {{{
  201. " Read (unchanged) buffers when they're modified on filesystem.
  202. " this saves me a lot of time and agony because I switch git branches
  203. " constantly, but it might not be what you want:
  204. set autoread
  205. " Disable swapfiles (you may not want this (but you probably do)):
  206. set noswapfile
  207. " }}}
  208. " 4. Whitespace handling {{{
  209. " Display tabs and trailing spaces:
  210. set listchars=tab:⇾\ ,trail
  211. set list
  212. " Display tab characters as 8 spaces, indent 2 spaces,
  213. " always use spaces instead of tabs:
  214. set tabstop=8
  215. set shiftwidth=2
  216. set softtabstop=2
  217. set expandtab
  218. set autoindent
  219. " set smarttab
  220. " set smartindent
  221. " For c code, no tab expansion, turn off softtabstop
  222. au FileType c setlocal noexpandtab
  223. au FileType c setlocal shiftwidth=8
  224. au FileType c setlocal softtabstop=0
  225. " Turn off tab expansion for Makefiles and calendar files:
  226. au FileType make setlocal noexpandtab
  227. au FileType calendar setlocal noexpandtab
  228. " Wrap entire words in markdown files
  229. " http://stackoverflow.com/questions/19624105/how-can-i-make-vim-break-lines-only-on-whitespace
  230. au FileType markdown setlocal wrap linebreak breakat&vim
  231. " }}}
  232. " 5. Custom keybindings {{{
  233. " F2 toggles the nerdtree file browser pane
  234. map <F2> :NERDTreeToggle<CR>
  235. imap <F2> <Esc>:NERDTreeToggle<CR>
  236. " F3 finds the current file in nerdtree
  237. map <F3> :NERDTreeFind<CR>
  238. " F4 toggles line numbers
  239. map <F4> :set invnumber<CR>
  240. imap <F4> <Esc>:set invnumber<CR>
  241. " F5 saves everything
  242. map <F5> :wall<CR>
  243. imap <F5> <Esc><F5>
  244. " F6 brings up a recently-used file list using MRU
  245. map <F6> :MRU<CR>
  246. imap <F6> <Esc><F6>
  247. " F7 opens ~/.vim/vimrc (in existing tab if open, new otherwise)
  248. " (7 kind of looks like a rotated v)
  249. " see http://learnvimscriptthehardway.stevelosh.com/chapters/07.html for
  250. " rationale - the idea is to make changing vim configuration trivial
  251. if has('nvim')
  252. map <F7> :call <SID>TabDrop("~/.vim/vimrc")<CR>
  253. else
  254. map <F7> :call <SID>TabDrop($MYVIMRC)<CR>
  255. endif
  256. imap <F7> <Esc><F7>
  257. " F8 inserts an ISO-8601 datestamp (mnemonic: eight rhymes with date)
  258. " (used to open the options window; use :options for that)
  259. map <F8> :r !date -I<CR>kJ
  260. " ,F8 inserts a date with seconds precision
  261. map <Leader><F8> :r !date -Is<CR>kJ
  262. " ,td / ,tD do the same (mnemonic: toDay)
  263. map <Leader>td :r !date -I<CR>kJ
  264. map <Leader>tD :r !date -Is<CR>kJ
  265. imap <F8> <Esc><F8>
  266. " F9 toggles search highlighting and some other noise
  267. map <F9> :call <SID>Crosshairs()<CR>
  268. imap <F9> <Esc><F9>
  269. " F10 starts a git commit for recent changes
  270. map <F10> :Gcommit -av<CR>
  271. " F11 i'm leaving unbound because of fullscreen shortcuts in various
  272. " terminals and window managers
  273. " in normal or insert mode, <F12> copies all in buffer
  274. " in visual/select modes, it just yanks the selected bit
  275. nmap <F12> :%y+<CR>
  276. imap <F12> <Esc><F12>
  277. vmap <F12> y+
  278. " add a menu separator
  279. menu Cheatsheet.-misc- :
  280. " split lines under the cursor (modeled on, maybe, emacs?)
  281. map K i<CR><Esc>g;
  282. " an FZF fragment menu
  283. nmap <Leader>F :call <SID>FragmentMenu()<CR>
  284. " Find files with fzf fuzzy-finder (assumes FZF is installed)
  285. " https://github.com/junegunn/fzf
  286. nmap <Leader>f :FZF<CR>
  287. " Pull up the git log:
  288. nmap <Leader>gl :Glog<CR>:copen<CR>
  289. " Run any Makefile in the current directory:
  290. nmap <leader>m :make<CR>
  291. " Jump to next, previous errors:
  292. nmap <Leader>n :cnext<CR>
  293. nmap <Leader>p :cprev<CR>
  294. " Reformat a paragraph:
  295. nmap <Leader>q gqip
  296. " Q mapping (it usually enters ex mode) based on this mail from bram:
  297. " https://groups.google.com/forum/#!search/vim/vim_use/iXH_Zxj8iBA/H7YDtbACBAAJ
  298. " note this is done by default in neovim
  299. map Q gq
  300. " Delete trailing whitespace, file-wide:
  301. nmap <Leader>s :%s/\s\+$//e<CR>
  302. " New tab:
  303. nmap <Leader>tn :tabnew<CR>
  304. " Split window navigation (ctrl-j/k, alt-arrows):
  305. map <C-J> <C-W>j<C-W>_
  306. map <M-Down> <C-W>j
  307. map <C-K> <C-W>k<C-W>_
  308. map <M-Up> <C-W>k
  309. map <M-Right> <C-W>l
  310. map <M-Left> <C-W>h
  311. " }}}
  312. " 6. Write custom functions {{{
  313. " Run the file through a custom filter, leaving the cursor at its original
  314. " location in the file (or close) - there might be a better way to do this,
  315. " but I don't know what it is.
  316. function! s:RunFilter(filter)
  317. let l:currentline = line('.')
  318. exe ":%!" . a:filter
  319. exe ":" . l:currentline
  320. endfunction
  321. " Do some normal-mode commands and return the cursor to its previous location
  322. function! s:ExecNormalAndReturnCursor(commands)
  323. let l:currentline = line('.')
  324. " see http://learnvimscriptthehardway.stevelosh.com/chapters/30.html
  325. exe "normal! " . a:commands
  326. exe ":" . l:currentline
  327. endfunction
  328. " Spit out a date for today.
  329. function! s:Datestamp()
  330. " . is current line, -1 is 1 line above that, r would otherwise read
  331. " the output onto the line below the cursor
  332. .-1r !date
  333. endfunction
  334. " select a fragment script using fzf and include its output in the
  335. " current buffer
  336. function! s:FragmentMenu()
  337. call fzf#run({
  338. \ 'options': '--reverse',
  339. \ 'sink': '.-1r !',
  340. \ 'source': 'find ~/bin/ -maxdepth 1 -name "fragment-*" -printf "%f\n"'
  341. \ })
  342. endfunction
  343. " Make things more amenable to editing long soft-wrapped lines
  344. " mostly an attempt to make vimwiki a bit more ergonomic, this
  345. " version adapted from:
  346. " http://www.baryudin.com/blog/vim-line-wrapping-and-word-boundary.html
  347. function! s:LonglineMode()
  348. setlocal wrap linebreak
  349. set virtualedit=
  350. setlocal display+=lastline
  351. noremap <buffer> <silent> <Up> gk
  352. noremap <buffer> <silent> k gk
  353. noremap <buffer> <silent> <Down> gj
  354. noremap <buffer> <silent> j gj
  355. noremap <buffer> <silent> <Home> g<Home>
  356. noremap <buffer> <silent> <End> g<End>
  357. inoremap <buffer> <silent> <Up> <C-o>gk
  358. inoremap <buffer> <silent> <Down> <C-o>gj
  359. inoremap <buffer> <silent> <Home> <C-o>g<Home>
  360. inoremap <buffer> <silent> <End> <C-o>g<End>
  361. endfunction
  362. " add some display sugar that helps highlight cursor, searches, and
  363. " textwidth. good for fiddling with alignment, reflowing text, etc.
  364. function! s:Crosshairs()
  365. set invhlsearch
  366. set invcursorcolumn
  367. set invcursorline
  368. " Toggle a colorcolumn - will get weird if it's set outside this function
  369. if &colorcolumn == "+1"
  370. set colorcolumn=0
  371. else
  372. " I think this is relative to textwidth:
  373. set colorcolumn=+1
  374. endif
  375. endfunction
  376. " Tab drop (edit in existing or new tab) a file's real path, in case it is a
  377. " symlink - useful for, frex, symlinked .vimrc. does wildcard expansion on
  378. " the path. as usual, there are probably better ways to do all of this.
  379. function! s:TabDrop(path)
  380. let realpath = system('readlink -fn ' . shellescape(expand(a:path)))
  381. echom realpath
  382. execute 'tab drop ' . realpath
  383. endfunction
  384. " This is ridiculous:
  385. " https://vi.stackexchange.com/questions/21825/how-to-insert-text-from-a-variable-at-current-cursor-position
  386. function! s:AppendAtCursor(string)
  387. execute "normal! a\<C-r>\<C-r>=a:string\<CR>\<Space>\<Esc>"
  388. endfunc
  389. " Get a list of key bindings, along with where they were defined, and
  390. " open it in a tab. This variant of redir and map seen at:
  391. " https://stackoverflow.com/questions/7642746/is-there-any-way-to-view-the-currently-mapped-keys-in-vim#7642762
  392. function! g:ListBindings()
  393. redir! > ~/vim_keys.txt
  394. silent verbose map
  395. redir END
  396. call <SID>TabDrop("~/vim_keys.txt")
  397. endfunction
  398. " }}}
  399. " 7. Pick a colorscheme {{{
  400. " I have used these all at one time or another and liked them for various
  401. " reasons:
  402. " colorscheme brookstream
  403. " colorscheme mustang
  404. " colorscheme dark-ruby
  405. " colorscheme Tomorrow-Night-Bright
  406. " colorscheme pyte
  407. " colorscheme wargrey
  408. " colorscheme hybrid
  409. " colorscheme icansee
  410. " colorscheme candycode
  411. " colorscheme peppers
  412. " colorscheme inkpot
  413. colorscheme iceberg
  414. " }}}
  415. " 8. Make folding suck less {{{
  416. " Turn off folding by default - i constantly open some file and have to
  417. " expand folds to see what's going on; this is easy to get back with zi
  418. set nofoldenable
  419. " Use {{{ and }}} to denote a folded section (these can be adjusted by
  420. " setting foldmarker, but i'm sticking with the vim defaults):
  421. set foldmethod=marker
  422. " For custom foldline colors:
  423. highlight FoldColumn ctermbg=darkgrey ctermfg=white guibg=darkgrey guifg=white
  424. " forked from: http://dhruvasagar.com/2013/03/28/vim-better-foldtext
  425. function! BPB_NeatFoldText()
  426. let line = ' ' . substitute(getline(v:foldstart), '^\s*"\?\s*\|\s*"\?\s*{{' . '{\d*\s*', '', 'g') . ' '
  427. let lines_count = v:foldend - v:foldstart + 1
  428. let lines_count_text = '| ' . printf("%10s", lines_count . ' lines') . ' |'
  429. let foldchar = matchstr(&fillchars, 'fold:\zs.')
  430. let foldtextstart = strpart('+' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3)
  431. let foldtextend = lines_count_text . repeat(foldchar, 8)
  432. let foldtextlength = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g')) + &foldcolumn
  433. return foldtextstart . repeat(foldchar, winwidth(0)-foldtextlength) . foldtextend
  434. endfunction
  435. set foldtext=BPB_NeatFoldText()
  436. " }}}