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

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