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 28KB

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