|
|
- " this is my .vimrc; part of https://code.p1k3.com/gitea/brennen/bpb-kit
- "
- " to use:
- "
- " cp [this file] ~/.vimrc
- " mkdir -p ~/.vim/bundle
- " git clone https://github.com/VundleVim/Vundle.git ~/.vim/bundle/Vundle.vim
- " vim +PluginInstall
- "
- " if there are funny-looking folded sections below and you're confused,
- " hitting zR will unfold them all, while zr will unfold the one your
- " cursor is on. this note is as much for my benefit as yours.
- "
- " some of this config is very specific to my preferences. there are
- " keybindings for filters i use regularly, things that automatically happen
- " when i open certain files, and shortcuts bound to the F-keys. you might
- " find good examples here, but you may not want the behavior. don't say you
- " weren't warned.
- "
- " items particularly likely to be personal preference are marked with the
- " string CUSTOMIZE and a note.
- "
- " -- bpb | https://p1k3.com | https://code.p1k3.com
-
- set nocompatible
-
- " use comma for the leader key - this is used as a prefix for
- " a bunch of bindings, mostly in the keybindings section. it's up
- " here for things that might require it before plugins are invoked,
- " such as vimwiki mappings.
- let mapleader = ","
-
- " vundle setup & vundle-managed plugins {{{
-
- filetype off
-
- set rtp+=~/.vim/bundle/Vundle.vim/
- call vundle#rc()
-
- " let Vundle manage Vundle - required:
- Plugin 'VundleVim/Vundle.vim'
-
- " really nice file tree - see keybindings section below for some tweaks:
- Plugin 'scrooloose/nerdtree'
- Plugin 'Xuyuanp/nerdtree-git-plugin'
-
- " fancy start screen with recent files & bookmarks
- " CUSTOMIZE: you'll probably want different bookmarks
- " Plugin 'mhinz/vim-startify'
- " let g:startify_bookmarks = [ {'v': '~/.vimrc'}, '~/.zshrc', '~/notes/', '~/p1k3' ]
-
- " Vim Outliner of Markups - see :help voom - no idea yet if this is any good
- Plugin 'VOoM'
-
- " align text vertically on a string:
- Plugin 'Align'
-
- " wrap common version control commands:
- Plugin 'vcscommand.vim'
- Plugin 'tpope/vim-fugitive'
- " visual marking of changes in working tree:
- " Plugin 'git://github.com/airblade/vim-gitgutter.git'
-
- " match lots of things - this repo seems defunct; not sure who is
- " currently maintaining this one:
- " Plugin 'edsono/vim-matchit'
-
- " commands for surrounding chars:
- Plugin 'tpope/vim-repeat' " used by vim-surround
- Plugin 'tpope/vim-surround'
-
- " readline-style keybindings in command line / insert:
- Plugin 'tpope/vim-rsi'
-
- " a yank/paste ring - hit ctrl-p after pasting:
- " let g:yankring_history_dir = '$HOME/.vim'
- " Plugin 'vim-scripts/YankRing.vim'
-
- " a bunch of colorschemes + a gui menu listing them:
- Plugin 'flazz/vim-colorschemes'
- Plugin 'altercation/vim-colors-solarized'
- Plugin 'chriskempson/vim-tomorrow-theme.git'
- Plugin 'desert-warm-256'
- Plugin 'ColorSchemeMenuMaker'
-
- " beyondgrep.com:
- Plugin 'mileszs/ack.vim'
-
- " navigate & control tmux windows + vim buffers - see also .tmux.conf
- " Plugin 'christoomey/vim-tmux-navigator'
- " Plugin 'benmills/vimux'
-
- " find files / buffers / etc.:
- " Plugin 'L9' " - required by FuzzyFinder
- " Plugin 'FuzzyFinder'
- Plugin 'Shougo/unite.vim'
-
- " fzf - fuzzy finding
- Plugin 'junegunn/fzf'
-
- " ASCII art
- Plugin 'DrawIt'
-
- " most recently used files - my fork allows for a top-level menu
- let g:MRU_Menu_Path = '&Recent\ Files'
- let g:MRU_Max_Menu_Entries = 30
- let g:MRU_Max_Submenu_Entries = 30
- Plugin 'https://code.p1k3.com/gitea/brennen/mru.git'
-
- " database stuffs
- " Plugin 'dbext.vim'
-
- " do stuff with tables - used by some vim-markdown features
- Plugin 'godlygeek/tabular'
-
- " filetypes / modes / language support:
- Plugin 'fatih/vim-go' " golang
-
- " Plugin 'brennen/vim-markdown'
- " the above a fork of plasticboy's version w/tweaks for variants i use
- " you probably want:
- Plugin 'plasticboy/vim-markdown'
-
- " graceful syntax checking for many languages:
- " - apt-get install shellcheck for shell linting
- Plugin 'scrooloose/syntastic'
- let g:syntastic_check_on_open = 1
- let g:syntastic_php_checkers = ['php']
- let g:syntastic_enable_perl_checker = 1
- let g:syntastic_perl_lib_path = ['./lib', './lib/auto']
- let g:syntastic_perl_checkers = ['perl', 'podchecker']
- amenu Syntax.Toggle\ Syntastic :SyntasticToggleMode<CR>
-
- " let g:syntastic_python_checkers = ['pylint']
-
- " add option to show a diff when there's a swapfile on disk:
- " Plugin 'chrisbra/Recover.vim'
-
- " CUSTOMIZE: fancy status line; laststatus can be set so it always shows up
- Plugin 'vim-airline/vim-airline'
- Plugin 'vim-airline/vim-airline-themes'
- " set laststatus=2
- " let g:airline#extensions#tabline#enabled = 1
- " let g:airline_theme = 'base16_solarized'
- if has("gui_running")
- let g:airline_theme = 'base16_ashes'
- endif
-
- " nginx config file highlighting
- Plugin 'nginx.vim'
-
- " GUI font size - use <Leader><Leader>+ or - to adjust:
- Plugin 'drmikehenry/vim-fontsize'
-
- Plugin 'jceb/vim-orgmode'
- Plugin 'tpope/vim-speeddating'
-
- " a calendar - used in conjunction with vimwiki diaries
- let g:calendar_keys = {
- \ 'goto_next_month': '<C-Right>',
- \ 'goto_prev_month': '<C-Left>',
- \ 'goto_next_year': '<C-Up>',
- \ 'goto_prev_year': '<C-Down>'
- \ }
- Plugin 'mattn/calendar-vim'
-
- " CUSTOMIZE: vimwikis - for notes, daily logs, etc. {{{
-
- " main personal wiki
- let wiki = {}
- let wiki.path = '~/notes/vimwiki/'
- let wiki.path_html = '~/notes/html/'
- let wiki.auto_tags = 1
-
- " do syntax highlight in preformatted blocks:
- let wiki.nested_syntaxes = {
- \ 'python': 'python',
- \ 'ruby': 'ruby',
- \ 'perl': 'perl',
- \ 'sh': 'sh'
- \ }
-
- " public p1k3 topics / tags
- let wiki_p1k3 = {}
- let wiki_p1k3.path = '~/p1k3/topics'
- let wiki_p1k3.syntax = 'markdown'
- let wiki_p1k3.ext = '.md'
-
- " there can be many of these:
- let g:vimwiki_list = [wiki, wiki_p1k3]
-
- " don't make temporary wikis based on file extensions in the list
- let g:vimwiki_global_ext = 0
-
- let g:vimwiki_folding = 'expr'
- " let g:vimwiki_folding = 'syntax'
- " let g:vimwiki_folding = 'list'
-
- " links concealing, etc.
- " let g:vimwiki_conceallevel = 1
-
- " don't obscure URLs in links
- " let g:vimwiki_url_maxsave = 0
-
- " make links clickable and such
- let g:vimwiki_use_mouse = 1
-
- " use colors in header highlighting
- let g:vimwiki_hl_headers = 1
-
- " map <Leader> b to go back - the plugin will check for this
- " mapping and not associate it with regular backspace:
- " NOTE: <C-BS> doesn't work here; I tried
- nmap <Leader>b <Plug>VimwikiGoBackLink
-
- " selectively activate foldcolumn:
- " au FileType vimwiki setlocal foldcolumn=3
-
- " au FileType vimwiki :set tw=80
-
- Plugin 'vimwiki/vimwiki'
-
- " regenerate vimwiki diary on file load - this doesn't seem to work,
- " maybe because overrides something in vimwiki (?) but seems like it
- " probably could:
- " au BufReadPost,BufNewFile diary.wiki :VimwikiDiaryGenerateLinks
-
- " set up linewrapping so that long lines more or less work
- au BufRead,BufNewFile *.wiki call BPB_LonglineMode()
-
- " }}}
-
- " snippets
- " Plugin 'SirVer/ultisnips'
- " Plugin 'honza/vim-snippets'
- " " trigger configuration
- " " don't use <tab> if you use https://github.com/Valloric/YouCompleteMe
- " let g:UltiSnipsExpandTrigger="<tab>"
- " let g:UltiSnipsJumpForwardTrigger="<c-b>"
- " let g:UltiSnipsJumpBackwardTrigger="<c-z>"
- " " if you want :UltiSnipsEdit to split your window.
- " let g:UltiSnipsEditSplit="vertical"
-
- filetype plugin on
- filetype indent on
-
- " }}}
-
- " misc UI {{{
-
- " set the window title (usually to filename plus some metadata)
- set title
-
- " pretty colors
- set t_Co=256
- syntax on
-
- " pretty characters
- set encoding=utf-8
-
- " do not beep or flash at me
- " vb is needed to stop beep
- " t_vb sets visual bell action, we're nulling it out here
- " note also that this may need to be repeated in .gvimrc
- set visualbell
- set t_vb=
-
- " enable mouse for (a)ll, (n)ormal, (v)isual, (i)nsert, or (c)ommand line
- " mode - seems to work in most terminals
- set mouse=a
-
- " render a useful popup menu for right-click instead of extending
- " selection (good for spellchecking, etc.):
- set mousemodel=popup_setpos
-
- " let me delete stuff like crazy in insert mode
- set backspace=indent,eol,start
-
- " see :help virtualedit - you probably don't want this
- " set virtualedit=onemore
-
- " display commands as-typed + current position in file
- set showcmd
- set ruler
-
- " display a visual menu for tab-completion of files:
- set wildmenu
-
- " add git status to statusline; otherwise emulate standard line with ruler
- " -- mostly supplanted for the moment by vim-airline
- set statusline=%<%{fugitive#statusline()}\ %f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
-
- " keep lots of command-line history
- set history=10000
-
- " search:
- set incsearch
- set ignorecase
- set smartcase
- set wrapscan
-
- " for gvim. no toolbar, otherwise these are the defaults:
- set guioptions=aegimrLt
-
- " use + register (x window clipboard) as unnamed register (copy to system
- " clipboard on yy, for example):
- set clipboard=unnamedplus,autoselect
-
- " include '-' in words. counts for both movement commands and autocomplete.
- " to test, try moving across and autocompleting for some-words-bunched-together
- " this is an experiment - mainly i want to use inline dashes in identifiers
- " in markdown documents, and so forth
- set iskeyword+=-
-
- " }}}
-
- " file saving/loading/swap/backups {{{
-
- " read (unchanged) buffers when they're modified on filesystem.
- " this saves me a lot of time and agony because i switch git branches
- " constantly, but it might not be what you want.
- set autoread
-
- " disable swapfiles (you may not want this):
- set noswapfile
-
- " }}}
-
- " CUSTOMIZE: whitespace {{{
-
- " display tabs and trailing spaces:
- set listchars=tab:⇾\ ,trail:·
- set list
-
- " display tab characters as 8 spaces, indent 2 spaces,
- " always use spaces instead of tabs:
- set tabstop=8
- set shiftwidth=2
- set softtabstop=2
- set expandtab
- set autoindent
- " set smarttab
- " set smartindent
-
- " for c code, no tab expansion, turn off softtabstop
- au FileType c setlocal noexpandtab
- au FileType c setlocal shiftwidth=8
- au FileType c setlocal softtabstop=0
-
- " turn off tab expansion for Makefiles
- au FileType make setlocal noexpandtab
-
- " wrap entire words in markdown files
- " http://stackoverflow.com/questions/19624105/how-can-i-make-vim-break-lines-only-on-whitespace
- au FileType markdown setlocal wrap linebreak breakat&vim
-
- " }}}
-
- " misc. autocommands {{{
-
- " to get a list of current autocommands:
- " http://vim.wikia.com/wiki/Capture_ex_command_output
- " :redir @a
- " :autocmd
- " :redir END
- " "ap
-
- " assume *.t files are PHP - i was doing this to override the assumption
- " that they're perl
- " au BufRead,BufNewFile *.t set filetype=php
-
- " retain view/folds on a specific file:
- " au BufWinLeave notes.txt mkview
- " au BufWinEnter notes.txt silent loadview
-
- au BufReadPost,BufNewFile *.md set filetype=markdown
-
- " CUSTOMIZE: this invokes a function for doing some custom filetype
- " overrides, like treating blog entries as markdown. it is mostly
- " for places where i couldn't figure out an autocmd, or needed something
- " more complex than the pattern matching offered by au
- "
- " at present, this fails for files named `index`, probably because of
- " a fugitive bug: https://github.com/tpope/vim-fugitive/issues/834
- au BufReadPost,BufNewFile * call BPB_FiletypeOverrides()
-
- au BufNewFile * call BPB_NewFileOverrides()
-
- " TODO: make a colorscheme logger here - it'd be nice to know all the
- " schemes i ever use for later reference:
- " au ColorScheme * call BPB_ColorSchemeOverrides()
-
- " }}}
-
- " keybindings {{{
-
- " CUSTOMIZE: my keybinding habits may be idiosyncratic
-
- " aside from function keys, i try not to stomp on the main keybinding
- " 'namespace' too much, with the exception of replacing K with something
- " useful.
-
- " a handful of functions are called here, all with a prefix of BPB_ -
- " they can be found in the "functions" section below
-
- " many things here have menu entries under 'Cheatsheet', as a cheatsheet for
- " all the stuff i've defined. these can also be accessed with :emenu in
- " terminal vim.
-
- " i use the F-keys a _lot_. this is what makes NERDTree usable.
-
- " F2 toggles the nerdtree file browser pane
- map <F2> :NERDTreeToggle<CR>
- imap <F2> <Esc>:NERDTreeToggle<CR>
- 650amenu Cheatsheet.NERDTree<Tab>F2 <F2>
-
- " F3 finds the current file in nerdtree
- map <F3> :NERDTreeFind<CR>
- amenu Cheatsheet.NERDTreeFind<Tab>F3 <F3>
-
- " F4 toggles line numbers
- " map <F4> :set invnumber<CR>
- " imap <F4> <Esc>:set invnumber<CR>
-
- " this version cycles through a couple versions of relative and absolute
- " line numbers:
- map <F4> :call BPB_CycleLineNumbers()<CR>
- imap <F4> <Esc>:call BPB_CycleLineNumbers()<CR>
-
- amenu Cheatsheet.Toggle\ Line\ Numbers<Tab>F4 <F4>
-
- " F5 saves everything
- map <F5> :wall<CR>
- imap <F5> <Esc><F5>
- amenu Cheatsheet.Write\ All<Tab>F5 <F5>
-
- " F6 brings up a recently-used file list using MRU
- map <F6> :MRU<CR>
- imap <F6> <Esc><F6>
- amenu Cheatsheet.Most\ Recently\ Used<Tab>F6 <F6>
-
- " F7 opens ~/.vimrc (in existing tab if open, new otherwise)
- " see http://learnvimscriptthehardway.stevelosh.com/chapters/07.html
- map <F7> :call BPB_TabDrop($MYVIMRC)<CR>
- imap <F7> <Esc><F7>
- amenu Cheatsheet.Open\ \.vimrc<Tab>F7 <F7>
-
- " F8 inserts a datestamp (eight rhymes with date)
- " (used to open the options window; use :options for that)
- " map <F8> :r! date -Is<CR> " iso-8601
- map <F8> :r! date -Is<CR>kJ
- imap <F8> <Esc><F8>
- amenu Cheatsheet.Insert\ Datestamp<Tab>F8 <F8>
-
- " F9 toggles search highlighting and some other noise
- map <F9> :call BPB_Crosshairs()<CR>
- imap <F9> <Esc><F9>
- amenu Cheatsheet.Crosshairs<Tab>F9 <F9>
-
- " F10 starts a git commit for recent changes
- map <F10> :Gcommit -av<CR>
- amenu Cheatsheet.Gcommit<Tab>F10 <F10>
-
- " F11 i'm leaving unbound because of fullscreen shortcuts in various
- " terminals and window managers
-
- " in normal or insert mode, <F12> copies all in buffer
- " in visual/select modes, it just yanks the selected bit
- nmap <F12> :%y+<CR>
- imap <F12> <Esc><F12>
- vmap <F12> y+
- amenu Cheatsheet.Copy\ All<Tab>F12 <F12>
-
- " add a menu separator
- menu Cheatsheet.-misc- :
-
- " split lines under the cursor (modeled on, maybe, emacs?)
- map K i<CR><Esc>g;
- amenu Cheatsheet.Split\ Line<Tab>K K
-
- " get a datestamp for a p1k3 entry
- nmap <Leader>tD :call BPB_Datestamp()<CR>
- amenu Cheatsheet.p1k3\ Datestamp\ (Uppercase)<Tab>,tD <Leader>tD
-
- " lowercased date for a p1k3 entry (ridiculous)
- nmap <Leader>td :call BPB_Datestamp()<CR>0v$gu
- amenu Cheatsheet.p1k3\ Datestamp\ (Lowercase)<Tab>,td <Leader>td
-
- " CUSTOMIZE: randomize certain text decorations - silly
- nmap <Leader>D :call BPB_RunFilter("filter-decorate")<CR>
- amenu Cheatsheet.Randomize\ Decorations<Tab>,D <Leader>D
- nmap <Leader>d i<p class="centerpiece"> <Esc>:r !fragment-bullet<CR>kJA </p><Esc>
- amenu Cheatsheet.Insert\ Decoration<Tab>,d <Leader>d
-
- " i didn't wind up using this much, and it potentially messes
- " with vimwiki mappings:
- " nmap <Leader>w :call BPB_CommandOutputInNewWindow("dict <cword>"))<CR>
-
- " pull up the last hundred git commits in a scratch buffer
- " 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
- nmap <Leader>l :Glog<CR>:copen<CR>
- amenu Cheatsheet.Git\ Log<Tab>,l <Leader>l
-
- nmap <leader>m :make<CR>
- amenu Cheatsheet.Make<Tab>,m <Leader>m
-
- " requires git-do, from bpb-kit, to execute make in root of current git repo
- nmap <leader>M :!git do make<CR>
- amenu Cheatsheet.Make\ (git\ root)<Tab>,M <Leader>M
-
- " jump to next, previous errors
- nmap <Leader>n :cnext<CR>
- amenu Cheatsheet.Next\ Error<Tab>,n <Leader>n
- nmap <Leader>p :cprev<CR>
- amenu Cheatsheet.Prev\ Error<Tab>,p <Leader>p
-
- " generate a password-like string with apg
- nmap <Leader>pw :r !apg -a 0 -m 20 -n 1<CR>
- amenu Cheatsheet.APG<Tab>,pw <Leader>pw
-
- " reformat a paragraph
- nmap <Leader>q gqip
- amenu Cheatsheet.Reformat\ Para<Tab>,q <Leader>q
- " Q mapping (it usually enters ex mode) based on this mail from bram:
- " https://groups.google.com/forum/#!search/vim/vim_use/iXH_Zxj8iBA/H7YDtbACBAAJ
- map Q gq
-
- " CUSTOMIZE: these are simple filter scripts to preprocess some
- " shell commands in HTML or Markdown files - see scripts for details
- nmap <Leader>r :call BPB_RunFilter("filter-exec-raw")<CR>:call BPB_RunFilter("filter-exec")<CR>:call BPB_RunFilter("filter-exec-stdin")<CR>
- amenu Cheatsheet.Run\ Filters<Tab>,r <Leader>r
-
- " delete trailing whitespace, file-wide
- nmap <Leader>s :%s/\s\+$//e<CR>
- amenu Cheatsheet.Zap\ Trailing\ Space<Tab>,s <Leader>s
-
- " tab navigation somewhat like firefox
- " http://vim.wikia.com/wiki/Alternative_tab_navigation
- nmap <C-S-Tab> :tabprevious<CR>
- nmap <C-Tab> :tabnext<CR>
- map <C-S-Tab> :tabprevious<CR>
- map <C-Tab> :tabnext<CR>
- imap <C-S-Tab> <Esc>:tabprevious<CR>i
- imap <C-Tab> <Esc>:tabnext<CR>i
-
- " new tab:
- nmap <Leader>tn :tabnew<CR>
- amenu Cheatsheet.New\ Tab<Tab>,tn <Leader>tn
-
- " trigger unite.vim
- map <Leader>u :Unite<CR>
-
- " split window navigation (ctrl-j/k, alt-arrows)
- map <C-J> <C-W>j<C-W>_
- map <M-Down> <C-W>j
- map <C-K> <C-W>k<C-W>_
- map <M-Up> <C-W>k
- map <M-Right> <C-W>l
- map <M-Left> <C-W>h
-
- " search the current vimwiki - fails if not in a vimwiki, which i should
- " really do something about
- map <Leader>w/ :VimwikiSearch
-
- " check php syntax - replaced by using Syntastic
- " noremap <Leader>c :echom system('php -l ' . bufname('%'))<CR>
-
- " }}}
-
- " functions {{{
-
- " run the file through a custom filter, leaving the cursor at its original
- " location in the file (or close) - there might be a better way to do this,
- " but i don't know what it is
- function! BPB_RunFilter(filter)
- let l:currentline = line('.')
- exe ":%!" . a:filter
- exe ":" . l:currentline
- endfunction
-
- " do some normal-mode commands and return the cursor to its previous location
- function! BPB_ExecNormalAndReturnCursor(commands)
- let l:currentline = line('.')
- " see http://learnvimscriptthehardway.stevelosh.com/chapters/30.html
- exe "normal! " . a:commands
- exe ":" . l:currentline
- endfunction
-
- " set custom filetypes for some things - invoked by an autocommand above
- function! BPB_FiletypeOverrides()
- " make sure NERDTree windows don't get messed up
- if bufname("%") =~ "NERD_tree"
- return
- endif
-
- " echom 'testing for p1k3 match'
-
- " using expand('%:p') instead of bufname("%") for full path, per:
- " http://vim.wikia.com/wiki/Get_the_name_of_the_current_file
- " the initial slash in the regex seems to be necessary to make \v work
- if expand('%:p') =~ "\\vp1k3\/archives.*([0-9]|[a-z])+$"
- " echom 'p1k3 match - setting filetype to markdown'
- set filetype=markdown
- endif
- endfunction
-
- " if editing a new p1k3 entry, auto-populate with a datestamp
- function! BPB_NewFileOverrides()
- if expand('%:p') =~ "\\vp1k3\/archives.*([0-9]|[a-z])+$"
- call BPB_DatestampHTML()
- endif
- endfunction
-
- function! BPB_DatestampHTML()
- r !fragment-entry
- -7
- delete
- endfunction
-
- " spit out a date for today, using ~/bin/today, on the current line
- function! BPB_Datestamp()
- " . is current line, -1 is 1 line above that, r would otherwise read
- " the output onto the line below the cursor
- .-1r !today
- endfunction
-
- " spit out a current timestamp
- function! BPB_Timestamp()
- .-1r !rightnow
- endfunction
-
- function! BPB_ColorSchemeOverrides()
- endfunction
-
- " make things more amenable to editing long soft-wrapped lines
- " mostly an attempt to make vimwiki a bit more ergonomic, this
- " version adapted from:
- " http://www.baryudin.com/blog/vim-line-wrapping-and-word-boundary.html
- function! BPB_LonglineMode()
- setlocal wrap linebreak
- set virtualedit=
- setlocal display+=lastline
- noremap <buffer> <silent> <Up> gk
- noremap <buffer> <silent> k gk
- noremap <buffer> <silent> <Down> gj
- noremap <buffer> <silent> j gj
- noremap <buffer> <silent> <Home> g<Home>
- noremap <buffer> <silent> <End> g<End>
- inoremap <buffer> <silent> <Up> <C-o>gk
- inoremap <buffer> <silent> <Down> <C-o>gj
- inoremap <buffer> <silent> <Home> <C-o>g<Home>
- inoremap <buffer> <silent> <End> <C-o>g<End>
- endfunction
-
- " add some display sugar that helps highlight cursor, searches, and
- " textwidth. good for fiddling with alignment, reflowing text, etc.
- function! BPB_Crosshairs()
- set invhlsearch
- set invcursorcolumn
- set invcursorline
-
- " toggle a colorcolumn - will get weird if it's set outside this function
- if &colorcolumn == "+1"
- set colorcolumn=0
- else
- " i think this is relative to textwidth
- set colorcolumn=+1
- endif
- endfunction
-
- " cycle between no, absolute, and relative line numbers
- function! BPB_CycleLineNumbers()
- if (&number)
- set nonumber
- return
- endif
-
- if (&relativenumber)
- set number norelativenumber
- else
- set number relativenumber
- endif
- endfunction
-
- " this is pretty much horked from:
- " http://vim.wikia.com/wiki/Display_output_of_shell_commands_in_new_window
- function! BPB_CommandOutputInNewWindow(cmdline)
- echo a:cmdline
- let expanded_cmdline = a:cmdline
- for part in split(a:cmdline, ' ')
- if part[0] =~ '\v[%#<]'
- let expanded_part = fnameescape(expand(part))
- let expanded_cmdline = substitute(expanded_cmdline, part, expanded_part, '')
- endif
- endfor
- botright new
- setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
- call setline(1, 'Command: ' . a:cmdline)
- call setline(2, 'Expanded: ' . expanded_cmdline)
- " display underline with = to length of previous line (pretty clever):
- call setline(3, substitute(getline(2), '.', '=', 'g'))
- execute '$read !' . expanded_cmdline
- setlocal nomodifiable
-
- " enable folding with a column:
- setlocal foldenable
- setlocal foldcolumn=3
- 1
- endfunction
-
- " tab drop (edit in existing or new tab) a file's real path, in case it is a
- " symlink - useful for, frex, symlinked .vimrc. does wildcard expansion on
- " the path. as usual, there are probably better ways to do all of this.
- function! BPB_TabDrop(path)
- let realpath = system('readlink -fn ' . shellescape(expand(a:path)))
- echom realpath
- execute 'tab drop ' . realpath
- endfunction
-
- " try to run timeslice for current path
- function! BPB_TimesliceForFile()
- let realpath = system('readlink -fn ' . shellescape(expand('%')))
- call BPB_CommandOutputInNewWindow('timeslice -f ' . realpath)
- endfunction
- amenu Cheatsheet.Timeslice<Tab>:call\ BPB_TimesliceForFile() :call BPB_TimesliceForFile()<CR>
-
- " get a list of key bindings, along with where they were defined, and
- " open it in a tab. this variant of redir and map seen at:
- " https://stackoverflow.com/questions/7642746/is-there-any-way-to-view-the-currently-mapped-keys-in-vim#7642762
- function! BPB_ListBindings()
- redir! > ~/vim_keys.txt
- silent verbose map
- redir END
- call BPB_TabDrop("~/vim_keys.txt")
- endfunction
- amenu Cheatsheet.List\ Keys<Tab>:call\ BPB_ListBindings() :call BPB_ListBindings()<CR>
-
- " }}}
-
- " colors {{{
- " CUSTOMIZE: you are gonna want some other colors i bet - i have used
- " these all at one time or another and liked them for various reasons
-
- " colorscheme brookstream
- colorscheme mustang
- " colorscheme dark-ruby
- " colorscheme Tomorrow-Night-Bright
- " colorscheme pyte
- " colorscheme wargrey
- " colorscheme hybrid
- " colorscheme icansee
- " colorscheme candycode
- " colorscheme peppers
- " }}}
-
- " folding {{{
-
- " turn off folding by default - i constantly open some file and have to
- " expand folds to see what's going on; this is easy to get back with zi
- set nofoldenable
-
- " use {{{ and }}} to denote a folded section (these can be adjusted by
- " setting foldmarker, but i'm sticking with the vim defaults):
- set foldmethod=marker
-
- " for custom foldline colors:
- " highlight Folded guibg=grey guifg=blue
- highlight FoldColumn ctermbg=darkgrey ctermfg=white guibg=darkgrey guifg=white
-
- " forked from: http://dhruvasagar.com/2013/03/28/vim-better-foldtext
- function! BPB_NeatFoldText()
- let line = ' ' . substitute(getline(v:foldstart), '^\s*"\?\s*\|\s*"\?\s*{{' . '{\d*\s*', '', 'g') . ' '
- let lines_count = v:foldend - v:foldstart + 1
- let lines_count_text = '| ' . printf("%10s", lines_count . ' lines') . ' |'
- let foldchar = matchstr(&fillchars, 'fold:\zs.')
- let foldtextstart = strpart('+' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3)
- let foldtextend = lines_count_text . repeat(foldchar, 8)
- let foldtextlength = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g')) + &foldcolumn
- return foldtextstart . repeat(foldchar, winwidth(0)-foldtextlength) . foldtextend
- endfunction
-
- set foldtext=BPB_NeatFoldText()
-
- " }}}
-
- " vim:foldmethod=marker:foldlevel=0
|