Dotfiles, utilities, and other apparatus.
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.

634 lines
19 KiB

11 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. " this is my .vimrc; part of https://github.com/brennen/bpb-kit
  2. "
  3. " to use:
  4. "
  5. " cp [this file] ~/.vimrc
  6. " mkdir -p ~/.vim/bundle
  7. " git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/Vundle.vim
  8. " vim +PluginInstall
  9. "
  10. " if there are funny-looking folded sections below and you're confused,
  11. " hitting zR will unfold them all, while zr will unfold the one your
  12. " cursor is on. this note is as much for my benefit as yours.
  13. "
  14. " some of this config is very specific to my preferences. there are
  15. " keybindings for filters i use regularly, things that automatically happen
  16. " when i open certain files, and shortcuts bound to the F-keys. you might
  17. " find good examples here, but you may not want the behavior. don't say you
  18. " weren't warned.
  19. "
  20. " items particularly likely to be personal preference are marked with the
  21. " string CUSTOMIZE and a note.
  22. "
  23. " -- bpb | https://p1k3.com/ | https://github.com/brennen
  24. set nocompatible
  25. " vundle setup & vundle-managed plugins {{{
  26. filetype off
  27. set rtp+=~/.vim/bundle/Vundle.vim/
  28. call vundle#rc()
  29. " let Vundle manage Vundle - required:
  30. Plugin 'VundleVim/Vundle.vim'
  31. " really nice file tree - see keybindings section below for some tweaks:
  32. Plugin 'scrooloose/nerdtree'
  33. Plugin 'Xuyuanp/nerdtree-git-plugin'
  34. " fancy start screen with recent files & bookmarks
  35. " CUSTOMIZE: you'll probably want different bookmarks
  36. " Plugin 'mhinz/vim-startify'
  37. " let g:startify_bookmarks = [ {'v': '~/.vimrc'}, '~/.zshrc', '~/notes/', '~/p1k3' ]
  38. " Vim Outliner of Markups - see :help voom - no idea yet if this is any good
  39. Plugin 'VOoM'
  40. " align text vertically on a string:
  41. Plugin 'Align'
  42. " wrap common version control commands:
  43. Plugin 'vcscommand.vim'
  44. Plugin 'tpope/vim-fugitive'
  45. " visual marking of changes in working tree:
  46. "Plugin 'git://github.com/airblade/vim-gitgutter.git'
  47. " match lots of things:
  48. Plugin 'edsono/vim-matchit'
  49. " commands for surrounding chars:
  50. Plugin 'tpope/vim-repeat' " used by vim-surround
  51. Plugin 'tpope/vim-surround'
  52. " readline-style keybindings in command line / insert:
  53. Plugin 'tpope/vim-rsi'
  54. " a yank/paste ring - hit ctrl-p after pasting:
  55. " let g:yankring_history_dir = '$HOME/.vim'
  56. " Plugin 'vim-scripts/YankRing.vim'
  57. " a bunch of colorschemes + a gui menu listing them:
  58. Plugin 'flazz/vim-colorschemes'
  59. Plugin 'altercation/vim-colors-solarized'
  60. Plugin 'chriskempson/vim-tomorrow-theme.git'
  61. Plugin 'desert-warm-256'
  62. Plugin 'ColorSchemeMenuMaker'
  63. " beyondgrep.com:
  64. Plugin 'mileszs/ack.vim'
  65. " navigate & control tmux windows + vim buffers - see also .tmux.conf
  66. " Plugin 'christoomey/vim-tmux-navigator'
  67. " Plugin 'benmills/vimux'
  68. " find files / buffers / etc.:
  69. " Plugin 'L9' " - required by FuzzyFinder
  70. " Plugin 'FuzzyFinder'
  71. Plugin 'Shougo/unite.vim'
  72. map <Leader>u :Unite<CR>
  73. " fzf - fuzzy finding
  74. Plugin 'junegunn/fzf'
  75. " ASCII art
  76. Plugin 'DrawIt'
  77. " most recently used files - my fork allows for a top-level menu
  78. let g:MRU_Menu_Path = '&Recent\ Files'
  79. let g:MRU_Max_Menu_Entries = 30
  80. let g:MRU_Max_Submenu_Entries = 30
  81. Plugin 'brennen/mru'
  82. " database stuffs
  83. " Plugin 'dbext.vim'
  84. " do stuff with tables - used by some vim-markdown features
  85. Plugin 'godlygeek/tabular'
  86. " filetypes / modes / language support:
  87. Plugin 'fatih/vim-go' " golang
  88. " Plugin 'brennen/vim-markdown'
  89. " the above a fork of plasticboy's version w/tweaks for variants i use
  90. " you probably want:
  91. Plugin 'plasticboy/vim-markdown'
  92. " graceful syntax checking for many languages:
  93. Plugin 'scrooloose/syntastic'
  94. let g:syntastic_check_on_open = 1
  95. let g:syntastic_php_checkers = ['php']
  96. let g:syntastic_perl_lib_path = [ './lib', './lib/auto' ]
  97. " add option to show a diff when there's a swapfile on disk:
  98. Plugin 'chrisbra/Recover.vim'
  99. " CUSTOMIZE: fancy status line; laststatus can be set so it always shows up
  100. Plugin 'vim-airline/vim-airline'
  101. Plugin 'vim-airline/vim-airline-themes'
  102. " set laststatus=2
  103. " let g:airline#extensions#tabline#enabled = 1
  104. " let g:airline_theme = 'base16_solarized'
  105. if has("gui_running")
  106. let g:airline_theme = 'base16_ashes'
  107. endif
  108. " nginx config file highlighting
  109. Plugin 'nginx.vim'
  110. " GUI font size - use <Leader><Leader>+ or - to adjust:
  111. Plugin 'drmikehenry/vim-fontsize'
  112. Plugin 'jceb/vim-orgmode'
  113. Plugin 'tpope/vim-speeddating'
  114. " a calendar - used in conjunction with vimwiki diaries
  115. Plugin 'mattn/calendar-vim'
  116. " CUSTOMIZE: vimwiki - for notes, daily logs, etc. {{{
  117. let wiki = {}
  118. let wiki.path = '~/notes/vimwiki'
  119. let wiki.path_html = '~/notes/html'
  120. let wiki.auto_tags = 1
  121. let wiki.nested_syntaxes = {'python': 'python', 'ruby': 'ruby', 'perl': 'perl'}
  122. " there can be many of these:
  123. let g:vimwiki_list = [wiki]
  124. let g:vimwiki_folding = 'expr'
  125. " let g:vimwiki_folding = 'syntax'
  126. " let g:vimwiki_folding = 'list'
  127. " selectively activate foldcolumn:
  128. au FileType vimwiki setlocal foldcolumn=3
  129. Plugin 'vimwiki/vimwiki'
  130. " }}}
  131. " snippets
  132. " Plugin 'SirVer/ultisnips'
  133. " Plugin 'honza/vim-snippets'
  134. " " trigger configuration
  135. " " don't use <tab> if you use https://github.com/Valloric/YouCompleteMe
  136. " let g:UltiSnipsExpandTrigger="<tab>"
  137. " let g:UltiSnipsJumpForwardTrigger="<c-b>"
  138. " let g:UltiSnipsJumpBackwardTrigger="<c-z>"
  139. " " if you want :UltiSnipsEdit to split your window.
  140. " let g:UltiSnipsEditSplit="vertical"
  141. filetype plugin on
  142. filetype indent on
  143. " }}}
  144. " misc UI {{{
  145. set title
  146. " pretty colors
  147. set t_Co=256
  148. syntax on
  149. " pretty characters
  150. set encoding=utf-8
  151. " do not beep or flash at me
  152. " vb is needed to stop beep
  153. " t_vb sets visual bell action, we're nulling it out here
  154. " note also that this may need to be repeated in .gvimrc
  155. set visualbell
  156. set t_vb=
  157. " enable mouse for (a)ll, (n)ormal, (v)isual, (i)nsert, or (c)ommand line
  158. " mode - seems to work in most terminals
  159. set mouse=a
  160. " render a useful popup menu for right-click instead of extending
  161. " selection (good for spellchecking, etc.):
  162. set mousemodel=popup_setpos
  163. " let me delete stuff like crazy in insert mode
  164. set backspace=indent,eol,start
  165. " see :help virtualedit - you probably don't want this
  166. " set virtualedit=onemore
  167. " display commands as-typed + current position in file
  168. set showcmd
  169. set ruler
  170. " display a visual menu for tab-completion of files:
  171. set wildmenu
  172. " add git status to statusline; otherwise emulate standard line with ruler
  173. " -- mostly supplanted for the moment by vim-airline
  174. set statusline=%<%{fugitive#statusline()}\ %f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
  175. " keep lots of command-line history
  176. set history=10000
  177. " search:
  178. set incsearch
  179. set ignorecase
  180. set smartcase
  181. set wrapscan
  182. " for gvim. no toolbar, otherwise these are the defaults:
  183. set guioptions=aegimrLt
  184. " use + register (x window clipboard) as unnamed register (copy to system
  185. " clipboard on yy, for example):
  186. set clipboard=unnamedplus,autoselect
  187. " include '-' in words. counts for both movement commands and autcomplete.
  188. " to test, try moving across and autocompleting for some-words-bunched-together
  189. " this is an experiment - mainly i want to use inline dashes in identifiers
  190. " in markdown documents, and so forth
  191. set iskeyword+=-
  192. " }}}
  193. " file saving/loading/swap/backups {{{
  194. " read (unchanged) buffers when they're modified on filesystem.
  195. " this saves me a lot of time and agony because i switch git branches
  196. " constantly, but it might not be what you want.
  197. set autoread
  198. " uncomment to disable swapfiles:
  199. " set noswapfile
  200. " }}}
  201. " whitespace {{{
  202. " display tabs and trailing spaces:
  203. set listchars=tab:⇾\ ,trail
  204. set list
  205. " display tab characters as 8 spaces, indent 2 spaces,
  206. " always use spaces instead of tabs:
  207. set tabstop=8
  208. set shiftwidth=2
  209. set softtabstop=2
  210. set expandtab
  211. set autoindent
  212. " set smarttab
  213. " set smartindent
  214. " for c code, no tab expansion, turn off softtabstop
  215. au FileType c setlocal noexpandtab
  216. au FileType c setlocal shiftwidth=8
  217. au FileType c setlocal softtabstop=0
  218. " turn off tab expansion for Makefiles
  219. au FileType make setlocal noexpandtab
  220. " wrap entire words in markdown files
  221. " http://stackoverflow.com/questions/19624105/how-can-i-make-vim-break-lines-only-on-whitespace
  222. au FileType markdown setlocal wrap linebreak breakat&vim
  223. " }}}
  224. " misc. autocommands {{{
  225. " to get a list of current autocommands:
  226. " http://vim.wikia.com/wiki/Capture_ex_command_output
  227. " :redir @a
  228. " :autocmd
  229. " :redir END
  230. " "ap
  231. " assume *.t files are PHP - i was doing this to override the assumption
  232. " that they're perl
  233. " au BufRead,BufNewFile *.t set filetype=php
  234. " retain view/folds on a specific file:
  235. " au BufWinLeave notes.txt mkview
  236. " au BufWinEnter notes.txt silent loadview
  237. au BufReadPost,BufNewFile *.md set filetype=markdown
  238. " CUSTOMIZE: this invokes a function for doing some custom filetype
  239. " overrides, like treating blog entries as markdown. it is mostly
  240. " for places where i couldn't figure out an autocmd, or needed something
  241. " more complex than the pattern matching offered by au
  242. "
  243. " at present, this fails for files named `index`, probably because of
  244. " a fugitive bug: https://github.com/tpope/vim-fugitive/issues/834
  245. au BufReadPost,BufNewFile * call BPB_FiletypeOverrides()
  246. au BufNewFile * call BPB_NewFileOverrides()
  247. " TODO: make a colorscheme logger here - it'd be nice to know all the
  248. " schemes i ever use for later reference:
  249. " au ColorScheme * call BPB_ColorSchemeOverrides()
  250. " }}}
  251. " keybindings {{{
  252. " CUSTOMIZE: my keybinding habits may be idiosyncratic
  253. " aside from function keys, i try not to stomp on the main keybinding
  254. " 'namespace' too much, with the exception of replacing K with something
  255. " useful.
  256. " a handful of functions are called here, all with a prefix of BPB_ -
  257. " they can be found in the "functions" section below
  258. " use comma for the leader key - this is used as a prefix for
  259. " a bunch of bindings further down
  260. let mapleader = ","
  261. " i use the F-keys a _lot_. this is what makes NERDTree usable.
  262. " F2 toggles the nerdtree file browser pane
  263. map <F2> :NERDTreeToggle<CR>
  264. imap <F2> <Esc>:NERDTreeToggle<CR>
  265. " F3 finds the current file in nerdtree
  266. map <F3> :NERDTreeFind<CR>
  267. " F4 toggles line numbers
  268. map <F4> :set invnumber<CR>
  269. imap <F4> <Esc>:set invnumber<CR>
  270. " i just am not that big a fan of relative numbers, so this version of
  271. " the above is unused for the moment:
  272. " map <F4> :call BPB_CycleLineNumbers()<CR>
  273. " imap <F4> <Esc>:call BPB_CycleLineNumbers()<CR>
  274. " F5 saves everything
  275. map <F5> :wall<CR>
  276. imap <F5> <Esc><F5>
  277. " F6 brings up a recently-used file list using MRU
  278. map <F6> :MRU<CR>
  279. imap <F6> <Esc><F6>
  280. " F7 opens ~/.vimrc (in existing tab if open, new otherwise)
  281. " see http://learnvimscriptthehardway.stevelosh.com/chapters/07.html
  282. map <F7> :call BPB_TabDrop($MYVIMRC)<CR>
  283. imap <F7> <Esc><F7>
  284. " F8 inserts a iso-8601 datestamp (eight rhymes with date)
  285. " (used to open the options window; use :options for that)
  286. map <F8> :r! date -Is<CR>
  287. imap <F8> <Esc><F8>
  288. " F9 toggles search highlighting and some other noise
  289. map <F9> :call BPB_Crosshairs()<CR>
  290. imap <F9> <Esc><F9>
  291. map <F10> :Gcommit -av<CR>
  292. " in normal or insert mode, <F12> copies all in buffer
  293. " in visual/select modes, it just yanks the selected bit
  294. nmap <F12> :%y+<CR>
  295. imap <F12> <Esc><F12>
  296. vmap <F12> y+
  297. " split lines under the cursor (modeled on, maybe, emacs?)
  298. map K i<CR><Esc>g;
  299. " get a datestamp for a p1k3 entry
  300. nmap <Leader>tD :call BPB_Datestamp()<CR>
  301. " lowercased date for a p1k3 entry (ridiculous)
  302. nmap <Leader>td :call BPB_Datestamp()<CR>0v$gu
  303. " CUSTOMIZE: randomize certain text decorations - silly
  304. nmap <Leader>D :call BPB_RunFilter("filter-decorate")<CR>
  305. nmap <Leader>d i<p class="centerpiece"> <Esc>:r !fragment-bullet<CR>kJA </p><Esc>
  306. " i didn't wind up using this much, and it potentially messes
  307. " with vimwiki mappings:
  308. " nmap <Leader>w :call BPB_CommandOutputInNewWindow("dict <cword>"))<CR>
  309. " CUSTOMIZE: these are simple filter scripts to preprocess some
  310. " shell commands in HTML or Markdown files - see scripts for details
  311. nmap <Leader>r :call BPB_RunFilter("filter-exec-raw")<CR>:call BPB_RunFilter("filter-exec")<CR>
  312. " pull up the last hundred git commits in a scratch buffer
  313. " nmap <Leader>l :vnew<CR>:set buftype=nofile<CR>:set bufhidden=hide<CR>:setlocal noswapfile<CR>:r !git log -100<CR>:set ft=git<CR>gg<C-w>r<C-w>l
  314. nmap <Leader>l :Glog<CR>:copen<CR>
  315. nmap <leader>m :make<CR>
  316. " jump to next, previous errors
  317. nmap <Leader>n :cnext<CR>
  318. nmap <Leader>p :cprev<CR>
  319. " reformat a paragraph
  320. nmap <Leader>q gqip
  321. " Q mapping (it usually enters ex mode) based on this mail from bram:
  322. " https://groups.google.com/forum/#!search/vim/vim_use/iXH_Zxj8iBA/H7YDtbACBAAJ
  323. map Q gq
  324. " generate a password-like string with apg
  325. nmap <Leader>pw :r !apg -a 0 -m 20 -n 1<CR>
  326. " tab navigation somewhat like firefox
  327. " http://vim.wikia.com/wiki/Alternative_tab_navigation
  328. nmap <C-S-Tab> :tabprevious<CR>
  329. nmap <C-Tab> :tabnext<CR>
  330. map <C-S-Tab> :tabprevious<CR>
  331. map <C-Tab> :tabnext<CR>
  332. imap <C-S-Tab> <Esc>:tabprevious<CR>i
  333. imap <C-Tab> <Esc>:tabnext<CR>i
  334. " new tab:
  335. nmap <Leader>tn :tabnew<CR>
  336. " split window navigation (ctrl-j/k, alt-h/l)
  337. map <C-J> <C-W>j<C-W>_
  338. map <C-K> <C-W>k<C-W>_
  339. map <M-Right> <C-W>l
  340. map <M-Left> <C-W>h
  341. " check php syntax - replaced by using Syntastic
  342. " noremap <Leader>c :echom system('php -l ' . bufname('%'))<CR>
  343. " }}}
  344. " functions {{{
  345. " run the file through a custom filter, leaving the cursor at its original
  346. " location in the file (or close) - there might be a better way to do this,
  347. " but i don't know what it is
  348. function! BPB_RunFilter(filter)
  349. let l:currentline = line('.')
  350. exe ":%!" . a:filter
  351. exe ":" . l:currentline
  352. endfunction
  353. " do some normal-mode commands and return the cursor to its previous location
  354. function! BPB_ExecNormalAndReturnCursor(commands)
  355. let l:currentline = line('.')
  356. " see http://learnvimscriptthehardway.stevelosh.com/chapters/30.html
  357. exe "normal! " . a:commands
  358. exe ":" . l:currentline
  359. endfunction
  360. " set custom filetypes for some things - invoked by an autocommand above
  361. function! BPB_FiletypeOverrides()
  362. " make sure NERDTree windows don't get messed up
  363. if bufname("%") =~ "NERD_tree"
  364. return
  365. endif
  366. " echom 'testing for p1k3 match'
  367. " using expand('%:p') instead of bufname("%") for full path, per:
  368. " http://vim.wikia.com/wiki/Get_the_name_of_the_current_file
  369. " the initial slash in the regex seems to be necessary to make \v work
  370. if expand('%:p') =~ "\\vp1k3\/archives.*([0-9]|[a-z])+$"
  371. " echom 'p1k3 match - setting filetype to markdown'
  372. set filetype=markdown
  373. endif
  374. endfunction
  375. function! BPB_NewFileOverrides()
  376. if expand('%:p') =~ "\\vp1k3\/archives.*([0-9]|[a-z])+$"
  377. call BPB_Datestamp()
  378. endif
  379. endfunction
  380. " spit out a date for today, using ~/bin/today
  381. function! BPB_Datestamp()
  382. put='<h1>'
  383. r !today
  384. put='</h1>'
  385. -2
  386. join 3
  387. endfunction
  388. " spit out a current timestamp
  389. function! BPB_Timestamp()
  390. r !rightnow
  391. endfunction
  392. function! BPB_ColorSchemeOverrides()
  393. endfunction
  394. " add some display sugar that helps highlight cursor, searches, and
  395. " textwidth. good for fiddling with alignment, reflowing text, etc.
  396. function! BPB_Crosshairs()
  397. set invhlsearch
  398. set invcursorcolumn
  399. set invcursorline
  400. " toggle a colorcolumn - will get weird if it's set outside this function
  401. if &colorcolumn == "+1"
  402. set colorcolumn=0
  403. else
  404. " i think this is relative to textwidth
  405. set colorcolumn=+1
  406. endif
  407. endfunction
  408. " cycle between no, absolute, and relative line numbers
  409. function! BPB_CycleLineNumbers()
  410. if (&number)
  411. set nonumber
  412. return
  413. endif
  414. if (&relativenumber)
  415. set number norelativenumber
  416. else
  417. set number relativenumber
  418. endif
  419. endfunction
  420. " this is pretty much horked from:
  421. " http://vim.wikia.com/wiki/Display_output_of_shell_commands_in_new_window
  422. function! BPB_CommandOutputInNewWindow(cmdline)
  423. echo a:cmdline
  424. let expanded_cmdline = a:cmdline
  425. for part in split(a:cmdline, ' ')
  426. if part[0] =~ '\v[%#<]'
  427. let expanded_part = fnameescape(expand(part))
  428. let expanded_cmdline = substitute(expanded_cmdline, part, expanded_part, '')
  429. endif
  430. endfor
  431. botright new
  432. setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
  433. call setline(1, 'You entered: ' . a:cmdline)
  434. call setline(2, 'Expanded Form: ' . expanded_cmdline)
  435. call setline(3, substitute(getline(2), '.', '=', 'g'))
  436. execute '$read !' . expanded_cmdline
  437. setlocal nomodifiable
  438. 1
  439. endfunction
  440. " tab drop (edit in existing or new tab) a file's real path, in case it is a
  441. " symlink - useful for, frex, symlinked .vimrc. does wildcard expansion on
  442. " the path. as usual, there are probably better ways to do all of this.
  443. function! BPB_TabDrop(path)
  444. let realpath = system('readlink -f ' . shellescape(expand(a:path)))
  445. echom realpath
  446. execute 'tab drop ' . realpath
  447. endfunction
  448. " get a list of key bindings, along with where they were defined, and
  449. " open it in a tab. this variant of redir and map seen at:
  450. " https://stackoverflow.com/questions/7642746/is-there-any-way-to-view-the-currently-mapped-keys-in-vim#7642762
  451. function! BPB_ListBindings()
  452. redir! > ~/vim_keys.txt
  453. silent verbose map
  454. redir END
  455. call BPB_TabDrop("~/vim_keys.txt")
  456. endfunction
  457. " }}}
  458. " colors {{{
  459. " CUSTOMIZE: you are gonna want some other colors i bet - i have used
  460. " these all at one time or another and liked them for various reasons
  461. " colorscheme brookstream
  462. " colorscheme mustang
  463. " colorscheme dark-ruby
  464. " colorscheme Tomorrow-Night-Bright
  465. " colorscheme pyte
  466. " colorscheme wargrey
  467. " colorscheme hybrid
  468. " colorscheme icansee
  469. " colorscheme candycode
  470. colorscheme peppers
  471. " }}}
  472. " folding {{{
  473. " turn off folding by default - i constantly open some file and have to
  474. " expand folds to see what's going on; this is easy to get back with zi
  475. set nofoldenable
  476. " use {{{ and }}} to denote a folded section (these can be adjusted by
  477. " setting foldmarker, but i'm sticking with the vim defaults):
  478. set foldmethod=marker
  479. " for custom foldline colors:
  480. " highlight Folded guibg=grey guifg=blue
  481. highlight FoldColumn ctermbg=darkgrey ctermfg=white guibg=darkgrey guifg=white
  482. " forked from: http://dhruvasagar.com/2013/03/28/vim-better-foldtext
  483. function! BPB_NeatFoldText()
  484. let line = ' ' . substitute(getline(v:foldstart), '^\s*"\?\s*\|\s*"\?\s*{{' . '{\d*\s*', '', 'g') . ' '
  485. let lines_count = v:foldend - v:foldstart + 1
  486. let lines_count_text = '| ' . printf("%10s", lines_count . ' lines') . ' |'
  487. let foldchar = matchstr(&fillchars, 'fold:\zs.')
  488. let foldtextstart = strpart('+' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3)
  489. let foldtextend = lines_count_text . repeat(foldchar, 8)
  490. let foldtextlength = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g')) + &foldcolumn
  491. return foldtextstart . repeat(foldchar, winwidth(0)-foldtextlength) . foldtextend
  492. endfunction
  493. set foldtext=BPB_NeatFoldText()
  494. " }}}
  495. " vim:foldmethod=marker:foldlevel=0