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.

1270 lines
42 KiB

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