""" Library of commands command! -nargs=+ -complete=shellcmd Sh call system() function! MkdirIfNotExists(dir) let dir = expand(a:dir) if !isdirectory(dir) call mkdir(dir, 'p', 0700) endif endfunction command! -bar Makesession call Makesession() function! s:Makesession() " Use $PWD instead of getcwd() to avoid window-local cwd let dir = '~/.cache/vim/session' . $PWD call MkdirIfNotExists(dir) execute 'mksession! ' . fnameescape(dir) . '/Session.vim' endfunction " Will place history in global input history instead of command history (which " may be a good thing in some cases), as well as offering direct control of " completions. function! Prompt(...) if a:0 == 3 let buf = input(a:1, a:2, a:3) elseif a:0 == 2 let buf = input(a:1, a:2, 'file') elseif a:0 == 1 let buf = input(a:1, '', 'file') endif if !empty(buf) | execute a:1 . buf | endif endfunction command! -nargs=+ -complete=command -bar Mapall call Mapall('nore', '', ) " {{{1 command! -nargs=+ -complete=command -bar ReMapall call Mapall('', '', ) command! -nargs=+ -complete=command -bar BufMapall call Mapall('nore', '', ) command! -nargs=+ -complete=command -bar BufReMapall call Mapall('', '', ) function! s:Mapall(prefix, mods, ...) execute a:prefix . 'map ' . a:mods . ' '. join(a:000) execute a:prefix . 'map! ' . a:mods . ' '. a:1 . ' ' . join(a:000[1:]) endfunction command! -nargs=* -bang -bar SetWhitespace call SetWhitespace('', ) "{{{1 function! s:SetWhitespace(bang, ...) if a:0 let local = empty(a:bang) ? 'local' : '' execute 'set' . local . ' shiftwidth=' . a:1 execute 'set' . local . ' softtabstop=' . a:1 execute 'set' . local . ' tabstop=' . (a:0 == 2 ? a:2 : a:1) else echo 'sw=' . &shiftwidth . ' sts=' . &softtabstop . ' ts=' . &tabstop endif endfunction command! -nargs=* -bang -bar SetTextwidth call s:SetTextwidth('', ) "{{{1 function! s:SetTextwidth(bang, ...) if a:0 let local = empty(a:bang) ? 'local' : '' execute 'set' . local . ' textwidth=' . a:1 if g:__FEATURES__['par'] let paropts = a:0 == 2 ? a:2 : 'heq' execute 'set' . local . ' formatprg=par\ ' . paropts . '\ ' . a:1 endif else echo 'tw=' . &textwidth . ' fp=' . &formatprg endif endfunction command! -nargs=? -bang -bar SetAutowrap call SetAutowrap('', ) "{{{1 function! s:SetAutowrap(bang, ...) let status = empty(a:bang) ? (a:0 ? a:1 : -1) : (&formatoptions =~ 'a' ? 0 : 1) if status == -1 echo &formatoptions =~ 'a' ? 'Autowrap is on' : 'Autowrap is off' elseif status execute 'setlocal formatoptions+=t formatoptions+=a formatoptions+=w' else execute 'setlocal formatoptions-=t formatoptions-=a formatoptions-=w' endif endfunction command! -bang -bar SetIskeyword call SetIskeyword('') "{{{1 function! s:SetIskeyword(bang) let nonspaces = '@,1-31,33-127' if empty(a:bang) setlocal iskeyword? elseif &iskeyword != nonspaces let b:__iskeyword__ = &iskeyword execute 'setlocal iskeyword=' . nonspaces else execute 'setlocal iskeyword=' . b:__iskeyword__ endif endfunction command! -bang -bar SetDiff call SetDiff('') "{{{1 function! s:SetDiff(bang) if empty(a:bang) setlocal diff? elseif &diff windo if expand('%:t') !=# 'index' && &buftype !~# '\vquickfix|help' | diffoff | endif else windo if expand('%:t') !=# 'index' && &buftype !~# '\vquickfix|help' | diffthis | endif endif endfunction command! -bang -bar SetVerbose call SetVerbose('') "{{{1 function! s:SetVerbose(bang) let enable = !exists('g:__SetVerbose__') if !empty(a:bang) call writefile([], '/tmp/verbose.vim') end if enable let g:__SetVerbose__ = 1 set verbose=100 verbosefile=/tmp/verbose.vim echo '♫ BEGIN VERBOSE MODE ♫' else echo '♫ END VERBOSE MODE ♫' set verbose=0 verbosefile= unlet! g:__SetVerbose__ endif endfunction command! -nargs=? -complete=file -bar UndoRemove call UndoRemove() function! s:UndoRemove(...) let file = undofile(a:0 ? a:1 : expand('%')) let s = delete(file) == 0 echo printf('%successfully deleted %s', s ? 'S' : 'Uns', file) endfunction command! -nargs=* -complete=function -bar Profile call Profile() function! s:Profile(...) profile start /tmp/profile.vim for pat in a:000 if pat =~# '\v^file:' execute 'profile file ' . substitute(pat, '\vfile:(.*)', '\1', '') else execute 'profile func *' . pat . '*' endif endfor endfunction command! -bar Syntime call Syntime() function! s:Syntime() if exists('g:__syntime_on__') unlet g:__syntime_on__ syntime off Capture syntime report else let g:__syntime_on__ = 1 syntime clear syntime on endif endfunction command! -bar SynStack call SynStack() "{{{1 function! s:SynStack() " TextMate style syntax highlighting stack for word under cursor " http://vimcasts.org/episodes/creating-colorschemes-for-vim/ if exists("*synstack") echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') endif endfunction command! -nargs=? -bar -complete=file Todo call Todo() "{{{1 function! s:Todo(...) let words = ['TODO', 'FIXME', 'XXX'] let arg = a:0 ? shellescape(expand(a:1), 1) : '.' " Fugitive detects Git repos for us if exists(':Ggrep') execute 'silent! Ggrep! -Ew "' . join(words,'|') . '" ' . (a:0 ? arg : shellescape(getcwd(), 1)) elseif exists(':Ack') execute 'silent! Ack! -w "' . join(words,'\|') . '" ' . arg else execute 'silent! grep! -r -Ew "' . join(words,'\|') . '" ' . arg endif endfunction command! -bar Ctags call Ctags() "{{{1 function! s:Ctags() if &filetype == 'javascript' let cmd = 'jsctags.js -f .jstags' . shellescape(expand('%')) elseif &filetype == 'go' let cmd = 'gotags -R -f .tags .' else let cmd = 'ctags -R' endif execute 'Sh (' . cmd . '; notify -? $?) >/dev/null 2>&1 &' | echo cmd endfunction function! MarkdownFoldExpr(lnum) if getline(a:lnum) =~# '\v^#' || getline(a:lnum + 1) =~# '\v^[=-]+$' return '>1' else return '=' endif endfunction function! ShellFoldExpr(lnum) if getline(a:lnum) =~# '\v^\s*\#\#\#\s' && empty(getline(a:lnum - 1)) return '>1' else return '=' endif endfunction function! CFoldExpr(lnum) let line = getline(a:lnum) if line[0] == '{' return '>1' elseif getline(a:lnum - 1)[0] == '}' return '0' else return '=' endif endfunction function! DiffFoldExpr(lnum) "{{{1 if getline(a:lnum) =~# '\v^diff>' return '>1' elseif getline(a:lnum - 3) =~# '\v^-- ' || \ getline(a:lnum) =~# '\v^Only in ' return '0' else return '=' endif endfunction function! VimFoldExpr(lnum) "{{{1 let line = getline(a:lnum) if line =~# '\v\{\{\{\d*\s*$' return '>1' elseif line =~# '\v^\s*aug%[roup] END' return '=' elseif line =~# '\v^\s*(fu%[nction]|com%[mand]|aug%[roup])' return '>1' elseif line[0] ==# '"' && getline(a:lnum - 1)[0] !=# '"' return '>1' else return '=' endif endfunction function! VimHelpFoldExpr(lnum) "{{{1 let line = getline(a:lnum) if line =~# '\v\*\S+\*\s*$' return getline(a:lnum - 1) =~# '\v\*\S+\*\s*$' ? '=' : '>1' elseif line =~# '\v\~$' return '>1' else return '=' endif endfunction function! LispFoldExpr(lnum) "{{{1 let line = getline(a:lnum) if line[0] ==# '(' return '>1' elseif line[0] ==# ';' return '>1' else return '=' endif endfunction command! -bar RainbowParens call RainbowParens() function! s:RainbowParens() " Rainbow parens call rainbow_parentheses#load(0) call rainbow_parentheses#load(1) call rainbow_parentheses#load(2) call rainbow_parentheses#activate() endfunction command! -bar LispBufferSetup call LispBufferSetup() "{{{1 function! s:LispBufferSetup() let b:loaded_delimitMate = 1 SetWhitespace 2 8 setlocal foldmethod=expr foldexpr=LispFoldExpr(v:lnum) noremap <4-CR> A; noremap! <4-CR> A; nnoremap tl :call ToggleLispwords(expand('')) endfunction command! -bar TimLBufferSetup call TimLBufferSetup() "{{{1 function! s:TimLBufferSetup() LispBufferSetup nmap cp(sexp_outer_list)`` imap nmap X cp(sexp_outer_top_list)`` imap X X nmap x cp(sexp_inner_element)`` imap x x endfunction command! -bar ClojureBufferSetup call ClojureBufferSetup() "{{{1 function! s:ClojureBufferSetup() LispBufferSetup vmap FireplacePrint nmap FireplacePrint(sexp_outer_list)`` imap nmap X FireplacePrint(sexp_outer_top_list)`` imap X X nmap x FireplacePrint(sexp_inner_element)`` imap x x nnoremap r :Require \| ClojureHighlightReferences nnoremap R :call fireplace#session_eval('(guns.repl/refresh)') \| ClojureHighlightReferences nnoremap :call fireplace#session_eval('(guns.repl/refresh-all)') \| ClojureHighlightReferences nnoremap :Require! clojure.tools.analyzer.jvm nnoremap co :execute 'Connect nrepl://localhost:' . readfile('.nrepl-port')[0] nnoremap cp :Capture call fireplace#session_eval('(guns.repl/print-classpath!)') \| setfiletype plain nnoremap cs :call ClojureCheatSheet('\A\Q' . fireplace#ns() . '\E\z') nnoremap cS :call ClojureCheatSheet(input('Namespace filter: ')) nnoremap CS :call ClojureCheatSheet('.') nnoremap e :call ClojurePprint('*e') nnoremap i :call fireplace#session_eval('(do (load-file "' . expand('~/.local/lib/clojure/guns/src/guns/repl.clj') . '") (guns.repl/init!))') nnoremap ja :Capture call fireplace#session_eval('(guns.repl/print-jvm-args!)') \| setfiletype plain nnoremap l :Last nnoremap m1 :call ClojureMacroexpand(0) nnoremap me :call ClojureMacroexpand(1) nnoremap mE :call ClojureMacroexpand(2) nnoremap ns :call ClojureViewNsGraph(input('Constraints: ', ":dependents '" . fireplace#ns() . ' ')) nnoremap nS :call ClojureViewNsGraph(input('Constraints: ', ":dependencies '" . fireplace#ns() . ' ')) nnoremap p :call ClojurePprint('*1') nnoremap R :Repl nnoremap r :ReplHere nnoremap od :call ClojureElementRedir('guns.repl/disassemble') nnoremap or :call ClojureElementRedir('(comp clojure.pprint/pprint guns.repl/reflect)') nnoremap os :call ClojureElementRedir('(comp println guns.repl/object-scaffold)') nnoremap ss :call fireplace#session_eval('(guns.system/boot)') nnoremap sS :call fireplace#session_eval('(guns.system/stop)') nnoremap sr :call fireplace#session_eval('(guns.system/restart)') nnoremap si :call ClojurePprint('@guns.system/instance') nnoremap sl :call ClojurePprint('@system/log') nnoremap sc :call ClojurePprint('system/config') nnoremap sp :call ClojureSetPrintLength(input('Max print length: ')) nnoremap sh :Slamhound nnoremap st :call ClojureStackTrace() nnoremap tf :call ClojureFilterForm("(guns.repl/thread-form '-> %s)") nnoremap tF :call ClojureFilterForm("(guns.repl/thread-form '->> %s)") nnoremap TF :call ClojureFilterForm("(guns.repl/unthread-form %s)") nnoremap tr :call fireplace#session_eval('(guns.repl/toggle-warn-on-reflection!)') nnoremap tt :call ClojureRunTests() nnoremap tT :call ClojureRunTests(input('Test filter: ')) nnoremap TT :call ClojureRunAllTests() nnoremap tv :call fireplace#session_eval('(guns.repl/toggle-schema-validation!)') nnoremap tw :call fireplace#session_eval('(guns.repl/toggle-warnings! true)') nnoremap tW :call fireplace#session_eval('(guns.repl/toggle-warnings! false)') nnoremap wc :call fireplace#session_eval("(do (require 'com.sungpae.warn-closeable) (com.sungpae.warn-closeable/warn-closeable! [*ns*]))") nnoremap WC :call fireplace#session_eval("(do (require 'com.sungpae.warn-closeable) (com.sungpae.warn-closeable/warn-closeable!))") endfunction function! s:ClojurePprint(expr) silent call fireplace#session_eval('(do (clojure.pprint/pprint (do ' . a:expr . ')) ' . a:expr . ')') Last normal! yG pclose Sscratch setfiletype clojure execute "normal! gg\"_dGVPG\"_dd" wincmd L endfunction function! s:ClojureStackTrace() silent call fireplace#session_eval('(clojure.stacktrace/e)') Last wincmd L endfunction function! s:ClojureCheatSheet(pattern) if empty(a:pattern) | return | endif let file = fireplace#evalparse('(guns.repl/write-cheat-sheet! #"' . escape(a:pattern, '"') . '")') if empty(file) redraw! " Clear command line echo "No matching namespaces." else execute 'vsplit ' . escape(file, '%') . ' | wincmd L' endif endfunction function! s:ClojureFilterForm(fmt) execute "normal \"fy\(sexp_outer_list)" let @f = fireplace#evalparse(printf(a:fmt, '"' . escape(@f, '\"') . '"')) execute "normal gv\"fp\(sexp_indent)" endfunction function! s:ClojureMacroexpand(once) let reg_save = @m let expand = ['macroexpand-1', 'macroexpand', 'clojure.walk/macroexpand-all'][a:once] execute "normal \"my\(sexp_outer_list)" call s:ClojurePprint('(' . expand . ' (quote ' . @m . '))') wincmd L let @m = reg_save endfunction function! s:ClojureViewNsGraph(constraints) if len(a:constraints) call fireplace#session_eval('(guns.repl/view-ns-graph ' . a:constraints . ')') endif endfunction function! s:ClojureRunTests(...) if a:0 if empty(a:1) | return | endif let b:clojure_test_filter = a:1 elseif !exists('b:clojure_test_filter') let b:clojure_test_filter = '.' endif if b:clojure_test_filter == '.' call fireplace#session_eval('(guns.repl/run-tests-for-current-ns)') else echo "\r" call fireplace#session_eval('(guns.repl/run-tests-for-current-ns #"' . escape(b:clojure_test_filter, '"') . '")') endif endfunction function! s:ClojureRunAllTests() Require! return fireplace#session_eval('(clojure.test/run-all-tests)') endfunction function! s:ClojureElementRedir(fn) try let reg_save = [@e, @r] execute "normal \"ey\(sexp_inner_element)" redir @r silent call fireplace#session_eval('(' . a:fn . ' ' . @e . ')') finally redir END Sscratch wincmd L setfiletype clojure normal! gg"_dG"rPdd let [@e, @r] = reg_save endtry endfunction function! s:ClojureSetPrintLength(input) if empty(a:input) | return | endif let args = split(a:input) if len(args) == 2 let [length, depth] = args else let length = args[0] let depth = length endif redraw echo fireplace#evalparse('(do (guns.repl/set-print-length! ' . +length . ' ' . +depth . ')' \ . '[*print-length* *print-level*])') endfunction function! s:ToggleLispwords(word) " Strip leading namespace qualifiers and macro characters from symbol let word = substitute(a:word, "\\v%(.*/|[#'`~@^,]*)(.*)", '\1', '') if &lispwords =~# '\V\<' . word . '\>' execute 'setlocal lispwords-=' . word echo "Removed " . word . " from lispwords." else execute 'setlocal lispwords+=' . word echo "Added " . word . " to lispwords." endif endfunction command! -nargs=? -complete=shellcmd -bar Screen call Screen() "{{{1 function! s:Screen(command) let map = { \ 'ruby' : 'irb', \ 'clojure' : 'lein REPL', \ 'python' : 'python', \ 'scheme' : 'scheme', \ 'haskell' : 'ghci', \ 'javascript' : 'node', \ 'j' : 'J' \ } let cmd = empty(a:command) ? (has_key(map, &filetype) ? map[&filetype] : '') : a:command execute 'ScreenShell ' . cmd endfunction command! -bar OrgBufferSetup call OrgBufferSetup() "{{{1 function! s:OrgBufferSetup() SetWhitespace 2 8 nnoremap <4-m> :call AppendMinutesDelta()$:call search('\v\d+:\d+:\d+', 'W') map <4-M> :call CalculateTotalMinutes() map <4-[> OrgPromoteHeadingNormal imap <4-[> OrgPromoteHeadingNormal map <4-]> OrgDemoteHeadingNormal imap <4-]> OrgDemoteHeadingNormal map OrgMoveSubtreeDownward imap OrgMoveSubtreeDownward map OrgMoveSubtreeUpward imap OrgMoveSubtreeUpward map OrgPromoteSubtreeNormal imap OrgPromoteSubtreeNormal map OrgDemoteSubtreeNormal imap OrgDemoteSubtreeNormal map <4-CR> OrgNewHeadingBelowNormal imap <4-CR> OrgNewHeadingBelowNormal map OrgNewHeadingBelowNormalOrgDemoteHeadingNormal imap " Please don't remap core keybindings! silent! iunmap silent! iunmap endfunction if has('ruby') function! s:AppendMinutesDelta() ruby << EORUBY require 'time' line = VIM::Buffer.current.line if not line.include? '=>' begin from, to = line.scan(/\d+:\d+:\d+/).take(2).map { |s| Time.parse s } VIM::Buffer.current.line = '%s => %sm' % [line, ((to - from)/60.0).round] rescue end end EORUBY endfunction function! s:CalculateDailyMinutes() execute "normal v\OrgAInnerTreeVisual" . '"my' ruby << EORUBY line = VIM::Buffer.current.line if not line.include? '=>' buf = VIM.evaluate '@m' total = buf.scan(/ => (\d+)m/).flatten.map(&:to_i).reduce :+ VIM::Buffer.current.line = '%s => TOTAL: %sm' % [line, total] end EORUBY endfunction function! s:CalculateTotalInvoiceMinutes() ruby << EORUBY buf = VIM::Buffer.current dates, minutes = [], [] (1..buf.count).each do |i| if buf[i] =~ /\*\s*(.+) => TOTAL: (\d+)m/ dates << $1 minutes << $2 end end lines = [] dw = dates.map(&:size).max sum = minutes.map(&:to_i).reduce(&:+) mw = sum.to_s.size lines << ("─" * (dw+1) << "┬" << "─" * (mw+2)) fmt = "%-#{dw}s │ %#{mw}dm" dates.zip(minutes).each do |dm| lines << fmt % dm end lines << ("─" * (dw+1) << "┼" << "─" * (mw+2)) lines << (" " * (dw-5) << "TOTAL │ #{sum}m") lines.each_with_index do |l, i| buf.append i, l end EORUBY endfunction function! s:CalculateTotalMinutes() if getpos('.')[1] == 1 && len(getline(1)) == 0 call s:CalculateTotalInvoiceMinutes() else call s:CalculateDailyMinutes() execute "normal \OrgJumpToNextSkipChildrenNormal" endif endfunction endif command! -bar GoBufferSetup call GoBufferSetup() function! s:GoBufferSetup() noremap! <- noremap! := nmap K (go-doc-vertical) nmap (go-def) nmap (go-def-split) nmap [c (go-callers) nmap ]c (go-callees) nmap [d (go-info) nmap ]d (go-describe) nmap b (go-build) noremap B :GoOptimizations nmap c (go-channelpeers) nmap C (go-coverage) noremap d :GoDoc noremap D :GoDocBrowser noremap e :GoErrCheck -abspath -ignore=fmt:^$ ./... noremap E :GoErrCheck -abspath -asserts -blank -ignore=fmt:^$ ./... nmap f vaB:GoFreevars vnoremap f :GoFreevars nmap i (go-implements) nmap I (go-install) noremap l :GoMetaLinter noremap L :GoLint -min_confidence=0 ./... noremap o :GoOracleScope . noremap O :GoOracleScope "" nmap r (go-referrers) nmap R (go-rename) nmap s (go-callstack) noremap t :GoTest -tags test noremap T :GoTestFunc -tags test noremap v :GoVet -test -shadowstrict . endfunction function! s:CompareQuickfix(p, q) let p = bufname(a:p['bufnr']) let q = bufname(a:q['bufnr']) return p > q ? 1 : (p < q ? -1 : (a:p['lnum'] > a:q['lnum'] ? 1 : -1)) endfunction command! -bar GoOptimizations call GoOptimizations() function! s:GoOptimizations() GoBuild -gcflags=-m let visited = {} let qflist = getqflist() let newqflist = [] for item in qflist let k = string(item) if !has_key(visited, k) let visited[k] = item call add(newqflist, item) endif endfor call setqflist(sort(newqflist, "s:CompareQuickfix")) endfunction command! -bar Open call Open(expand('')) "{{{1 function! s:Open(word) " Parameter is a whitespace delimited WORD, thus URLs may not contain spaces. " Worth the simple implementation IMO. let rdelims = "\"');>" let capture = 'https?://[^' . rdelims . ']+|(https?://)@Qfdo() "{{{1 function! s:Qfdo(expr) " Run a command over all lines in the quickfix buffer let qflist = getqflist() for item in qflist execute item['bufnr'] . 'buffer!' call cursor(item['lnum'], item['col']) execute a:expr endfor endfunction command! -nargs=* -bar Grepqflist call Grepqflist(1, ) command! -nargs=* -bar Removeqflist call Grepqflist(0, ) function! s:Grepqflist(match, pat) call setqflist(filter(getqflist(), "bufname(v:val['bufnr']) . v:val['text'] " . (a:match ? '=~' : '!~') . " a:pat")) endfunction command! -bar ToggleMinorWindows call ToggleMinorWindows() "{{{1 function! s:ToggleMinorWindows() if empty(filter(map(tabpagebuflist(), 'getbufvar(v:val, "&buftype")'), 'v:val == "quickfix"')) try topleft lwindow | wincmd p cwindow | wincmd p catch /./ lclose | cclose | pclose endtry else lclose | cclose | pclose endif endfunction command! -bar UniteOpen call fugitive#detect('.') | execute 'Unite -no-split ' . (exists('b:git_dir') ? 'git_cached git_untracked' : 'file') command! -nargs=+ -complete=file -bar TabOpen call TabOpen() "{{{1 function! s:TabOpen(path) let path = substitute(a:path, '\v^(\~[^/]*)', '\=expand(submatch(1))', '') let path = substitute(path, '\v(\$\w+)', '\=expand(submatch(1))', 'g') let path = resolve(path) for t in range(tabpagenr('$')) for b in tabpagebuflist(t + 1) if path ==# expand('#' . b . ':p') execute ':' . (t + 1) . 'tabnext' execute ':' . bufwinnr(b) . 'wincmd w' return endif endfor endfor execute 'tabedit ' . fnameescape(path) endfunction command! -bar TabmoveNext call Tabmove(1) " {{{1 command! -bar TabmovePrev call Tabmove(-1) function! s:Tabmove(n) if version >= 703 && has('patch591') execute 'tabmove ' . printf('%+d', a:n) else let nr = a:n > 0 ? tabpagenr() + a:n - 1 : tabpagenr() - a:n - 3 execute 'tabmove ' . (nr < 0 ? 0 : nr) endif endfunction command! -bar MapReadlineUnicodeBindings call MapReadlineUnicodeBindings() "{{{1 function! s:MapReadlineUnicodeBindings() let inputrc = expand('~/.inputrc.d/utf-8') if filereadable(inputrc) for line in readfile(inputrc) if line[0] == '"' " Example: "\el": "λ" let key = line[3] let char = line[8 : len(line) - 2] " By convention, we'll always map as Meta-. execute 'noremap! ' . key . ' ' . char endif endfor endif endfunction command! -bar CapturePane call CapturePane() "{{{1 function! s:CapturePane() " Tmux-esque capture-pane let buf = bufnr('%') let only = len(tabpagebuflist()) == 1 " Only window in current tab? wincmd q if !only tabprevious endif execute buf . 'sbuffer' wincmd L endfunction command! -nargs=+ -complete=command -bar Capture call Capture() "{{{1 command! CaptureMaps \ execute 'Capture verbose map \| silent! verbose map!' | \ :%! ruby -Eutf-8 -e 'puts $stdin.read.chars.map { |c| c.unpack("U").pack "U" rescue "UTF-8-ERROR" }.join.gsub(/\n\t/, " \" ")' " Redirect output of given commands into a scratch buffer function! s:Capture(cmd) try let reg_save = @r redir @r execute 'silent! ' . a:cmd finally redir END new | setlocal buftype=nofile filetype=vim | normal! "rp execute "normal! d/\\v^\\s*\\S\" let @r = reg_save endtry endfunction command! -nargs=* -complete=file -bang -bar Org call Org('', ) "{{{1 function! s:Org(bang, ...) let tab = empty(a:bang) ? 'tab' : '' if a:0 for f in a:000 if filereadable(f . '.org') execute tab . 'edit ' . f . '.org' else execute tab . 'edit ' . join([g:org_home, f . '.org'], '/') execute 'lcd ' . g:org_home endif endfor else if empty(a:bang) | tabnew | endif execute 'lcd ' . g:org_home | Unite -no-split git_cached git_untracked endif endfunction command! -nargs=1 -bar Speak call system('speak ' . shellescape()) command! -bar -range Interleave \ '<,'>! ruby -e 'l = $stdin.read.lines; puts l.take(l.count/2).zip(l.drop l.count/2).join' " http://vim.wikia.com/wiki/Xterm256_color_names_for_console_Vim command! -bar Hitest \ 45vnew | \ source $VIMRUNTIME/syntax/hitest.vim | \ setlocal synmaxcol=5000 nocursorline nocursorcolumn function! CwordOrSel(...) " {{{1 try let reg_save = @v if a:0 && a:1 normal! gv"vy return @v else return expand('') endif finally let @v = reg_save endtry endfunction " Modify selected text using combining diacritics " https://vim.wikia.com/wiki/Create_underlines,_overlines,_and_strikethroughs_using_combining_characters command! -range -nargs=0 Overline call s:CombineSelection(, , '0305') command! -range -nargs=0 Underline call s:CombineSelection(, , '0332') command! -range -nargs=0 DoubleUnderline call s:CombineSelection(, , '0333') command! -range -nargs=0 Strikethrough call s:CombineSelection(, , '0336') command! -range -nargs=0 Slashthrough call s:CombineSelection(, , '0338') function! s:CombineSelection(line1, line2, cp) execute 'let char = "\u'.a:cp.'"' execute a:line1.','.a:line2.'s/\%V[^[:cntrl:]]/&'.char.'/ge' endfunction