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.

.vimrc 29KB

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