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.

1051 lines
34 KiB

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