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.

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