From fe337504f2fb3ded76326b1e3d4d02787a27d853 Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Wed, 5 Jun 2013 10:50:57 -0500 Subject: Aand that's all the plugins. --- vim/plugin/31-create-scala.vim | 55 - vim/plugin/fugitive.vim | 2220 -------------------- vim/plugin/gist.vim | 826 -------- vim/plugin/indent-object.vim | 224 -- vim/plugin/rails.vim | 339 --- vim/plugin/searchfold_0.9.vim | 319 --- vim/plugin/showmarks.vim | 507 ----- vim/plugin/snipMate.vim | 271 --- vim/plugin/supertab.vim | 737 ------- vim/plugin/surround.vim | 625 ------ vim/plugin/syntastic.vim | 614 ------ vim/plugin/tagbar.vim | 118 -- vim/plugin/taglist.vim | 4546 ---------------------------------------- vim/plugin/unimpaired.vim | 315 --- vim/plugin/vim-rspec.rb | 32 - vim/plugin/vim-rspec.vim | 174 -- vim/plugin/vim-rspec.xsl | 55 - 17 files changed, 11977 deletions(-) delete mode 100644 vim/plugin/31-create-scala.vim delete mode 100644 vim/plugin/fugitive.vim delete mode 100644 vim/plugin/gist.vim delete mode 100644 vim/plugin/indent-object.vim delete mode 100644 vim/plugin/rails.vim delete mode 100644 vim/plugin/searchfold_0.9.vim delete mode 100644 vim/plugin/showmarks.vim delete mode 100644 vim/plugin/snipMate.vim delete mode 100644 vim/plugin/supertab.vim delete mode 100644 vim/plugin/surround.vim delete mode 100644 vim/plugin/syntastic.vim delete mode 100644 vim/plugin/tagbar.vim delete mode 100644 vim/plugin/taglist.vim delete mode 100644 vim/plugin/unimpaired.vim delete mode 100644 vim/plugin/vim-rspec.rb delete mode 100644 vim/plugin/vim-rspec.vim delete mode 100644 vim/plugin/vim-rspec.xsl (limited to 'vim/plugin') diff --git a/vim/plugin/31-create-scala.vim b/vim/plugin/31-create-scala.vim deleted file mode 100644 index e4ecb44..0000000 --- a/vim/plugin/31-create-scala.vim +++ /dev/null @@ -1,55 +0,0 @@ -" Vim plugin that generates new Scala source file when you type -" vim nonexistent.scala. -" Scripts tries to detect package name from the directory path, e. g. -" .../src/main/scala/com/mycompany/myapp/app.scala gets header -" package com.mycompany.myapp -" -" Author : Stepan Koltsov - -function! MakeScalaFile() - if exists("b:template_used") && b:template_used - return - endif - - let b:template_used = 1 - - let filename = expand(":p") - let x = substitute(filename, "\.scala$", "", "") - - let p = substitute(x, "/[^/]*$", "", "") - let p = substitute(p, "/", ".", "g") - let p = substitute(p, ".*\.src$", "@", "") " unnamed package - let p = substitute(p, ".*\.src\.", "!", "") - let p = substitute(p, "^!main\.scala\.", "!", "") " - let p = substitute(p, "^!.*\.ru\.", "!ru.", "") - let p = substitute(p, "^!.*\.org\.", "!org.", "") - let p = substitute(p, "^!.*\.com\.", "!com.", "") - - " ! marks that we found package name. - if match(p, "^!") == 0 - let p = substitute(p, "^!", "", "") - else - " Don't know package name. - let p = "@" - endif - - let class = substitute(x, ".*/", "", "") - - if p != "@" - call append("0", "package " . p) - endif - - "norm G - "call append(".", "class " . class . " {") - - "norm G - "call append(".", "} /// end of " . class) - - call append(".", "// vim: set ts=4 sw=4 et:") - call append(".", "") - -endfunction - -au BufNewFile *.scala call MakeScalaFile() - -" vim: set ts=4 sw=4 et: diff --git a/vim/plugin/fugitive.vim b/vim/plugin/fugitive.vim deleted file mode 100644 index 17d52fc..0000000 --- a/vim/plugin/fugitive.vim +++ /dev/null @@ -1,2220 +0,0 @@ -" fugitive.vim - A Git wrapper so awesome, it should be illegal -" Maintainer: Tim Pope -" Version: 1.2 -" GetLatestVimScripts: 2975 1 :AutoInstall: fugitive.vim - -if exists('g:loaded_fugitive') || &cp - finish -endif -let g:loaded_fugitive = 1 - -if !exists('g:fugitive_git_executable') - let g:fugitive_git_executable = 'git' -endif - -" Utility {{{1 - -function! s:function(name) abort - return function(substitute(a:name,'^s:',matchstr(expand(''), '\d\+_'),'')) -endfunction - -function! s:sub(str,pat,rep) abort - return substitute(a:str,'\v\C'.a:pat,a:rep,'') -endfunction - -function! s:gsub(str,pat,rep) abort - return substitute(a:str,'\v\C'.a:pat,a:rep,'g') -endfunction - -function! s:shellesc(arg) abort - if a:arg =~ '^[A-Za-z0-9_/.-]\+$' - return a:arg - elseif &shell =~# 'cmd' && a:arg !~# '"' - return '"'.a:arg.'"' - else - return shellescape(a:arg) - endif -endfunction - -function! s:fnameescape(file) abort - if exists('*fnameescape') - return fnameescape(a:file) - else - return escape(a:file," \t\n*?[{`$\\%#'\"|!<") - endif -endfunction - -function! s:throw(string) abort - let v:errmsg = 'fugitive: '.a:string - throw v:errmsg -endfunction - -function! s:warn(str) - echohl WarningMsg - echomsg a:str - echohl None - let v:warningmsg = a:str -endfunction - -function! s:shellslash(path) - if exists('+shellslash') && !&shellslash - return s:gsub(a:path,'\\','/') - else - return a:path - endif -endfunction - -function! s:recall() - let rev = s:buffer().rev() - if rev ==# ':' - return matchstr(getline('.'),'^#\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( (new commits)\)\=$\|^\d\{6} \x\{40\} \d\t\zs.*') - endif - return rev -endfunction - -function! s:add_methods(namespace, method_names) abort - for name in a:method_names - let s:{a:namespace}_prototype[name] = s:function('s:'.a:namespace.'_'.name) - endfor -endfunction - -let s:commands = [] -function! s:command(definition) abort - let s:commands += [a:definition] -endfunction - -function! s:define_commands() - for command in s:commands - exe 'command! -buffer '.command - endfor -endfunction - -function! s:compatibility_check() - if exists('b:git_dir') && exists('*GitBranchInfoCheckGitDir') && !exists('g:fugitive_did_compatibility_warning') - let g:fugitive_did_compatibility_warning = 1 - call s:warn("See http://github.com/tpope/vim-fugitive/issues#issue/1 for why you should remove git-branch-info.vim") - endif -endfunction - -augroup fugitive_utility - autocmd! - autocmd User Fugitive call s:define_commands() - autocmd VimEnter * call s:compatibility_check() -augroup END - -let s:abstract_prototype = {} - -" }}}1 -" Initialization {{{1 - -function! s:ExtractGitDir(path) abort - let path = s:shellslash(a:path) - if path =~? '^fugitive://.*//' - return matchstr(path,'fugitive://\zs.\{-\}\ze//') - endif - let fn = fnamemodify(path,':s?[\/]$??') - let ofn = "" - let nfn = fn - while fn != ofn - if filereadable(fn . '/.git/HEAD') - return s:sub(simplify(fnamemodify(fn . '/.git',':p')),'\W$','') - elseif fn =~ '\.git$' && filereadable(fn . '/HEAD') - return s:sub(simplify(fnamemodify(fn,':p')),'\W$','') - endif - let ofn = fn - let fn = fnamemodify(ofn,':h') - endwhile - return '' -endfunction - -function! s:Detect(path) - if exists('b:git_dir') && b:git_dir ==# '' - unlet b:git_dir - endif - if !exists('b:git_dir') - let dir = s:ExtractGitDir(a:path) - if dir != '' - let b:git_dir = dir - endif - endif - if exists('b:git_dir') - silent doautocmd User Fugitive - cnoremap recall() - let buffer = fugitive#buffer() - if expand('%:p') =~# '//' - call buffer.setvar('&path',s:sub(buffer.getvar('&path'),'^\.%(,|$)','')) - endif - if stridx(buffer.getvar('&tags'),escape(b:git_dir.'/tags',', ')) == -1 - call buffer.setvar('&tags',escape(b:git_dir.'/tags',', ').','.buffer.getvar('&tags')) - if &filetype != '' - call buffer.setvar('&tags',escape(b:git_dir.'/'.&filetype.'.tags',', ').','.buffer.getvar('&tags')) - endif - endif - endif -endfunction - -augroup fugitive - autocmd! - autocmd BufNewFile,BufReadPost * call s:Detect(expand(':p')) - autocmd FileType netrw call s:Detect(expand(':p')) - autocmd VimEnter * if expand('')==''|call s:Detect(getcwd())|endif - autocmd BufWinLeave * execute getwinvar(+winnr(), 'fugitive_leave') -augroup END - -" }}}1 -" Repository {{{1 - -let s:repo_prototype = {} -let s:repos = {} - -function! s:repo(...) abort - let dir = a:0 ? a:1 : (exists('b:git_dir') && b:git_dir !=# '' ? b:git_dir : s:ExtractGitDir(expand('%:p'))) - if dir !=# '' - if has_key(s:repos,dir) - let repo = get(s:repos,dir) - else - let repo = {'git_dir': dir} - let s:repos[dir] = repo - endif - return extend(extend(repo,s:repo_prototype,'keep'),s:abstract_prototype,'keep') - endif - call s:throw('not a git repository: '.expand('%:p')) -endfunction - -function! s:repo_dir(...) dict abort - return join([self.git_dir]+a:000,'/') -endfunction - -function! s:repo_tree(...) dict abort - if !self.bare() - let dir = fnamemodify(self.git_dir,':h') - return join([dir]+a:000,'/') - endif - call s:throw('no work tree') -endfunction - -function! s:repo_bare() dict abort - return self.dir() !~# '/\.git$' -endfunction - -function! s:repo_translate(spec) dict abort - if a:spec ==# '.' || a:spec ==# '/.' - return self.bare() ? self.dir() : self.tree() - elseif a:spec =~# '^/' - return fnamemodify(self.dir(),':h').a:spec - elseif a:spec =~# '^:[0-3]:' - return 'fugitive://'.self.dir().'//'.a:spec[1].'/'.a:spec[3:-1] - elseif a:spec ==# ':' - if $GIT_INDEX_FILE =~# '/[^/]*index[^/]*\.lock$' && fnamemodify($GIT_INDEX_FILE,':p')[0:strlen(s:repo().dir())] ==# s:repo().dir('') && filereadable($GIT_INDEX_FILE) - return fnamemodify($GIT_INDEX_FILE,':p') - else - return self.dir('index') - endif - elseif a:spec =~# '^:/' - let ref = self.rev_parse(matchstr(a:spec,'.[^:]*')) - return 'fugitive://'.self.dir().'//'.ref - elseif a:spec =~# '^:' - return 'fugitive://'.self.dir().'//0/'.a:spec[1:-1] - elseif a:spec =~# 'HEAD\|^refs/' && a:spec !~ ':' && filereadable(self.dir(a:spec)) - return self.dir(a:spec) - elseif filereadable(s:repo().dir('refs/'.a:spec)) - return self.dir('refs/'.a:spec) - elseif filereadable(s:repo().dir('refs/tags/'.a:spec)) - return self.dir('refs/tags/'.a:spec) - elseif filereadable(s:repo().dir('refs/heads/'.a:spec)) - return self.dir('refs/heads/'.a:spec) - elseif filereadable(s:repo().dir('refs/remotes/'.a:spec)) - return self.dir('refs/remotes/'.a:spec) - elseif filereadable(s:repo().dir('refs/remotes/'.a:spec.'/HEAD')) - return self.dir('refs/remotes/'.a:spec,'/HEAD') - else - try - let ref = self.rev_parse(matchstr(a:spec,'[^:]*')) - let path = s:sub(matchstr(a:spec,':.*'),'^:','/') - return 'fugitive://'.self.dir().'//'.ref.path - catch /^fugitive:/ - return self.tree(a:spec) - endtry - endif -endfunction - -call s:add_methods('repo',['dir','tree','bare','translate']) - -function! s:repo_git_command(...) dict abort - let git = g:fugitive_git_executable . ' --git-dir='.s:shellesc(self.git_dir) - return git.join(map(copy(a:000),'" ".s:shellesc(v:val)'),'') -endfunction - -function! s:repo_git_chomp(...) dict abort - return s:sub(system(call(self.git_command,a:000,self)),'\n$','') -endfunction - -function! s:repo_git_chomp_in_tree(...) dict abort - let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' - let dir = getcwd() - try - execute cd.'`=s:repo().tree()`' - return call(s:repo().git_chomp, a:000, s:repo()) - finally - execute cd.'`=dir`' - endtry -endfunction - -function! s:repo_rev_parse(rev) dict abort - let hash = self.git_chomp('rev-parse','--verify',a:rev) - if hash =~ '\<\x\{40\}$' - return matchstr(hash,'\<\x\{40\}$') - endif - call s:throw('rev-parse '.a:rev.': '.hash) -endfunction - -call s:add_methods('repo',['git_command','git_chomp','git_chomp_in_tree','rev_parse']) - -function! s:repo_dirglob(base) dict abort - let base = s:sub(a:base,'^/','') - let matches = split(glob(self.tree(s:gsub(base,'/','*&').'*/')),"\n") - call map(matches,'v:val[ strlen(self.tree())+(a:base !~ "^/") : -1 ]') - return matches -endfunction - -function! s:repo_superglob(base) dict abort - if a:base =~# '^/' || a:base !~# ':' - let results = [] - if a:base !~# '^/' - let heads = ["HEAD","ORIG_HEAD","FETCH_HEAD","MERGE_HEAD"] - let heads += sort(split(s:repo().git_chomp("rev-parse","--symbolic","--branches","--tags","--remotes"),"\n")) - call filter(heads,'v:val[ 0 : strlen(a:base)-1 ] ==# a:base') - let results += heads - endif - if !self.bare() - let base = s:sub(a:base,'^/','') - let matches = split(glob(self.tree(s:gsub(base,'/','*&').'*')),"\n") - call map(matches,'s:shellslash(v:val)') - call map(matches,'v:val !~ "/$" && isdirectory(v:val) ? v:val."/" : v:val') - call map(matches,'v:val[ strlen(self.tree())+(a:base !~ "^/") : -1 ]') - let results += matches - endif - return results - - elseif a:base =~# '^:' - let entries = split(self.git_chomp('ls-files','--stage'),"\n") - call map(entries,'s:sub(v:val,".*(\\d)\\t(.*)",":\\1:\\2")') - if a:base !~# '^:[0-3]\%(:\|$\)' - call filter(entries,'v:val[1] == "0"') - call map(entries,'v:val[2:-1]') - endif - call filter(entries,'v:val[ 0 : strlen(a:base)-1 ] ==# a:base') - return entries - - else - let tree = matchstr(a:base,'.*[:/]') - let entries = split(self.git_chomp('ls-tree',tree),"\n") - call map(entries,'s:sub(v:val,"^04.*\\zs$","/")') - call map(entries,'tree.s:sub(v:val,".*\t","")') - return filter(entries,'v:val[ 0 : strlen(a:base)-1 ] ==# a:base') - endif -endfunction - -call s:add_methods('repo',['dirglob','superglob']) - -function! s:repo_config(conf) dict abort - return matchstr(system(s:repo().git_command('config').' '.a:conf),"[^\r\n]*") -endfun - -function! s:repo_user() dict abort - let username = s:repo().config('user.name') - let useremail = s:repo().config('user.email') - return username.' <'.useremail.'>' -endfun - -function! s:repo_aliases() dict abort - if !has_key(self,'_aliases') - let self._aliases = {} - for line in split(self.git_chomp('config','--get-regexp','^alias[.]'),"\n") - let self._aliases[matchstr(line,'\.\zs\S\+')] = matchstr(line,' \zs.*') - endfor - endif - return self._aliases -endfunction - -call s:add_methods('repo',['config', 'user', 'aliases']) - -function! s:repo_keywordprg() dict abort - let args = ' --git-dir='.escape(self.dir(),"\\\"' ").' show' - if has('gui_running') && !has('win32') - return g:fugitive_git_executable . ' --no-pager' . args - else - return g:fugitive_git_executable . args - endif -endfunction - -call s:add_methods('repo',['keywordprg']) - -" }}}1 -" Buffer {{{1 - -let s:buffer_prototype = {} - -function! s:buffer(...) abort - let buffer = {'#': bufnr(a:0 ? a:1 : '%')} - call extend(extend(buffer,s:buffer_prototype,'keep'),s:abstract_prototype,'keep') - if buffer.getvar('git_dir') !=# '' - return buffer - endif - call s:throw('not a git repository: '.expand('%:p')) -endfunction - -function! fugitive#buffer(...) abort - return s:buffer(a:0 ? a:1 : '%') -endfunction - -function! s:buffer_getvar(var) dict abort - return getbufvar(self['#'],a:var) -endfunction - -function! s:buffer_setvar(var,value) dict abort - return setbufvar(self['#'],a:var,a:value) -endfunction - -function! s:buffer_getline(lnum) dict abort - return getbufline(self['#'],a:lnum)[0] -endfunction - -function! s:buffer_repo() dict abort - return s:repo(self.getvar('git_dir')) -endfunction - -function! s:buffer_type(...) dict abort - if self.getvar('fugitive_type') != '' - let type = self.getvar('fugitive_type') - elseif fnamemodify(self.spec(),':p') =~# '.\git/refs/\|\.git/\w*HEAD$' - let type = 'head' - elseif self.getline(1) =~ '^tree \x\{40\}$' && self.getline(2) == '' - let type = 'tree' - elseif self.getline(1) =~ '^\d\{6\} \w\{4\} \x\{40\}\>\t' - let type = 'tree' - elseif self.getline(1) =~ '^\d\{6\} \x\{40\}\> \d\t' - let type = 'index' - elseif isdirectory(self.spec()) - let type = 'directory' - elseif self.spec() == '' - let type = 'null' - else - let type = 'file' - endif - if a:0 - return !empty(filter(copy(a:000),'v:val ==# type')) - else - return type - endif -endfunction - -if has('win32') - - function! s:buffer_spec() dict abort - let bufname = bufname(self['#']) - let retval = '' - for i in split(bufname,'[^:]\zs\\') - let retval = fnamemodify((retval==''?'':retval.'\').i,':.') - endfor - return s:shellslash(fnamemodify(retval,':p')) - endfunction - -else - - function! s:buffer_spec() dict abort - let bufname = bufname(self['#']) - return s:shellslash(bufname == '' ? '' : fnamemodify(bufname,':p')) - endfunction - -endif - -function! s:buffer_name() dict abort - return self.spec() -endfunction - -function! s:buffer_commit() dict abort - return matchstr(self.spec(),'^fugitive://.\{-\}//\zs\w*') -endfunction - -function! s:buffer_path(...) dict abort - let rev = matchstr(self.spec(),'^fugitive://.\{-\}//\zs.*') - if rev != '' - let rev = s:sub(rev,'\w*','') - else - let rev = self.spec()[strlen(self.repo().tree()) : -1] - endif - return s:sub(s:sub(rev,'.\zs/$',''),'^/',a:0 ? a:1 : '') -endfunction - -function! s:buffer_rev() dict abort - let rev = matchstr(self.spec(),'^fugitive://.\{-\}//\zs.*') - if rev =~ '^\x/' - return ':'.rev[0].':'.rev[2:-1] - elseif rev =~ '.' - return s:sub(rev,'/',':') - elseif self.spec() =~ '\.git/index$' - return ':' - elseif self.spec() =~ '\.git/refs/\|\.git/.*HEAD$' - return self.spec()[strlen(self.repo().dir())+1 : -1] - else - return self.path() - endif -endfunction - -function! s:buffer_sha1() dict abort - if self.spec() =~ '^fugitive://' || self.spec() =~ '\.git/refs/\|\.git/.*HEAD$' - return self.repo().rev_parse(self.rev()) - else - return '' - endif -endfunction - -function! s:buffer_expand(rev) dict abort - if a:rev =~# '^:[0-3]$' - let file = a:rev.self.path(':') - elseif a:rev =~# '^[-:]/$' - let file = '/'.self.path() - elseif a:rev =~# '^-' - let file = 'HEAD^{}'.a:rev[1:-1].self.path(':') - elseif a:rev =~# '^@{' - let file = 'HEAD'.a:rev.self.path(':') - elseif a:rev =~# '^[~^]' - let commit = s:sub(self.commit(),'^\d=$','HEAD') - let file = commit.a:rev.self.path(':') - else - let file = a:rev - endif - return s:sub(s:sub(file,'\%$',self.path()),'\.\@<=/$','') -endfunction - -function! s:buffer_containing_commit() dict abort - if self.commit() =~# '^\d$' - return ':' - elseif self.commit() =~# '.' - return self.commit() - else - return 'HEAD' - endif -endfunction - -call s:add_methods('buffer',['getvar','setvar','getline','repo','type','spec','name','commit','path','rev','sha1','expand','containing_commit']) - -" }}}1 -" Git {{{1 - -call s:command("-bang -nargs=? -complete=customlist,s:GitComplete Git :execute s:Git(0,)") - -function! s:ExecuteInTree(cmd) abort - let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' - let dir = getcwd() - try - execute cd.'`=s:repo().tree()`' - execute a:cmd - finally - execute cd.'`=dir`' - endtry -endfunction - -function! s:Git(bang,cmd) abort - if a:bang - return s:Edit('edit',1,a:cmd) - endif - let git = s:repo().git_command() - if has('gui_running') && !has('win32') - let git .= ' --no-pager' - endif - let cmd = matchstr(a:cmd,'\v\C.{-}%($|\\@ `=s:repo().bare() ? s:repo().dir() : s:repo().tree()`") -call s:command("-bar -bang -nargs=? -complete=customlist,s:DirComplete Glcd :lcd `=s:repo().bare() ? s:repo().dir() : s:repo().tree()`") - -" }}}1 -" Gstatus {{{1 - -call s:command("-bar Gstatus :execute s:Status()") - -function! s:Status() abort - try - Gpedit : - wincmd P - nnoremap q :bdelete - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry - return '' -endfunction - -function! fugitive#reload_status() abort - let mytab = tabpagenr() - for tab in [mytab] + range(1,tabpagenr('$')) - for winnr in range(1,tabpagewinnr(tab,'$')) - if getbufvar(tabpagebuflist(tab)[winnr-1],'fugitive_type') ==# 'index' - execute 'tabnext '.tab - if winnr != winnr() - execute winnr.'wincmd w' - let restorewinnr = 1 - endif - try - if !&modified - call s:BufReadIndex() - endif - finally - if exists('restorewinnr') - wincmd p - endif - execute 'tabnext '.mytab - endtry - endif - endfor - endfor -endfunction - -function! s:StageReloadSeek(target,lnum1,lnum2) - let jump = a:target - let f = matchstr(getline(a:lnum1-1),'^#\t\%([[:alpha:] ]\+: *\)\=\zs.*') - if f !=# '' | let jump = f | endif - let f = matchstr(getline(a:lnum2+1),'^#\t\%([[:alpha:] ]\+: *\)\=\zs.*') - if f !=# '' | let jump = f | endif - silent! edit! - 1 - redraw - call search('^#\t\%([[:alpha:] ]\+: *\)\=\V'.jump.'\%( (new commits)\)\=\$','W') -endfunction - -function! s:StageDiff(diff) abort - let section = getline(search('^# .*:$','bcnW')) - let line = getline('.') - let filename = matchstr(line,'^#\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( (new commits)\)\=$') - if filename ==# '' && section ==# '# Changes to be committed:' - return 'Git diff --cached' - elseif filename ==# '' - return 'Git diff' - elseif line =~# '^#\trenamed:' && filename =~# ' -> ' - let [old, new] = split(filename,' -> ') - execute 'Gedit '.s:fnameescape(':0:'.new) - return a:diff.' HEAD:'.s:fnameescape(old) - elseif section ==# '# Changes to be committed:' - execute 'Gedit '.s:fnameescape(':0:'.filename) - return a:diff.' -' - else - execute 'Gedit '.s:fnameescape('/'.filename) - return a:diff - endif -endfunction - -function! s:StageDiffEdit() abort - let section = getline(search('^# .*:$','bcnW')) - let line = getline('.') - let filename = matchstr(line,'^#\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( (new commits)\)\=$') - let arg = (filename ==# '' ? '.' : filename) - if section ==# '# Changes to be committed:' - return 'Git! diff --cached '.s:shellesc(arg) - elseif section ==# '# Untracked files:' - let repo = s:repo() - call repo.git_chomp_in_tree('add','--intent-to-add',arg) - if arg ==# '.' - silent! edit! - 1 - if !search('^# Change\%(d but not updated\|s not staged for commit\):$','W') - call search('^# Change','W') - endif - else - call s:StageReloadSeek(arg,line('.'),line('.')) - endif - return '' - else - return 'Git! diff '.s:shellesc(arg) - endif -endfunction - -function! s:StageToggle(lnum1,lnum2) abort - try - let output = '' - for lnum in range(a:lnum1,a:lnum2) - let line = getline(lnum) - let repo = s:repo() - if line ==# '# Changes to be committed:' - call repo.git_chomp_in_tree('reset','-q') - silent! edit! - 1 - if !search('^# Untracked files:$','W') - call search('^# Change','W') - endif - return '' - elseif line =~# '^# Change\%(d but not updated\|s not staged for commit\):$' - call repo.git_chomp_in_tree('add','-u') - silent! edit! - 1 - if !search('^# Untracked files:$','W') - call search('^# Change','W') - endif - return '' - elseif line ==# '# Untracked files:' - call repo.git_chomp_in_tree('add','.') - silent! edit! - 1 - call search('^# Change','W') - return '' - endif - let filename = matchstr(line,'^#\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( (\a\+ [[:alpha:], ]\+)\)\=$') - if filename ==# '' - continue - endif - if !exists('first_filename') - let first_filename = filename - endif - execute lnum - let section = getline(search('^# .*:$','bnW')) - if line =~# '^#\trenamed:' && filename =~ ' -> ' - let cmd = ['mv','--'] + reverse(split(filename,' -> ')) - let filename = cmd[-1] - elseif section =~? ' to be ' - let cmd = ['reset','-q','--',filename] - elseif line =~# '^#\tdeleted:' - let cmd = ['rm','--',filename] - else - let cmd = ['add','--',filename] - endif - let output .= call(repo.git_chomp_in_tree,cmd,s:repo())."\n" - endfor - if exists('first_filename') - call s:StageReloadSeek(first_filename,a:lnum1,a:lnum2) - endif - echo s:sub(s:gsub(output,'\n+','\n'),'\n$','') - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry - return 'checktime' -endfunction - -function! s:StagePatch(lnum1,lnum2) abort - let add = [] - let reset = [] - - for lnum in range(a:lnum1,a:lnum2) - let line = getline(lnum) - if line ==# '# Changes to be committed:' - return 'Git reset --patch' - elseif line =~# '^# Change\%(d but not updated\|s not staged for commit\):$' - return 'Git add --patch' - endif - let filename = matchstr(line,'^#\t\%([[:alpha:] ]\+: *\)\=\zs.\{-\}\ze\%( (new commits)\)\=$') - if filename ==# '' - continue - endif - if !exists('first_filename') - let first_filename = filename - endif - execute lnum - let section = getline(search('^# .*:$','bnW')) - if line =~# '^#\trenamed:' && filename =~ ' -> ' - let reset += [split(filename,' -> ')[1]] - elseif section =~? ' to be ' - let reset += [filename] - elseif line !~# '^#\tdeleted:' - let add += [filename] - endif - endfor - try - if !empty(add) - execute "Git add --patch -- ".join(map(add,'s:shellesc(v:val)')) - endif - if !empty(reset) - execute "Git reset --patch -- ".join(map(add,'s:shellesc(v:val)')) - endif - if exists('first_filename') - silent! edit! - 1 - redraw - call search('^#\t\%([[:alpha:] ]\+: *\)\=\V'.first_filename.'\%( (new commits)\)\=\$','W') - endif - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry - return 'checktime' -endfunction - -" }}}1 -" Gcommit {{{1 - -call s:command("-nargs=? -complete=customlist,s:CommitComplete Gcommit :execute s:Commit()") - -function! s:Commit(args) abort - let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' - let dir = getcwd() - let msgfile = s:repo().dir('COMMIT_EDITMSG') - let outfile = tempname() - let errorfile = tempname() - try - execute cd.'`=s:repo().tree()`' - if &shell =~# 'cmd' - let command = '' - let old_editor = $GIT_EDITOR - let $GIT_EDITOR = 'false' - else - let command = 'env GIT_EDITOR=false ' - endif - let command .= s:repo().git_command('commit').' '.a:args - if &shell =~# 'csh' - silent execute '!('.command.' > '.outfile.') >& '.errorfile - elseif a:args =~# '\%(^\| \)--interactive\>' - execute '!'.command.' 2> '.errorfile - else - silent execute '!'.command.' > '.outfile.' 2> '.errorfile - endif - if !has('gui_running') - redraw! - endif - if !v:shell_error - if filereadable(outfile) - for line in readfile(outfile) - echo line - endfor - endif - return '' - else - let errors = readfile(errorfile) - let error = get(errors,-2,get(errors,-1,'!')) - if error =~# '\' - let args = '--cleanup=strip '.args - endif - if bufname('%') == '' && line('$') == 1 && getline(1) == '' && !&mod - keepalt edit `=msgfile` - elseif s:buffer().type() ==# 'index' - keepalt edit `=msgfile` - execute (search('^#','n')+1).'wincmd+' - setlocal nopreviewwindow - else - keepalt split `=msgfile` - endif - let b:fugitive_commit_arguments = args - setlocal bufhidden=delete filetype=gitcommit - return '1' - elseif error ==# '!' - return s:Status() - else - call s:throw(error) - endif - endif - catch /^fugitive:/ - return 'echoerr v:errmsg' - finally - if exists('old_editor') - let $GIT_EDITOR = old_editor - endif - call delete(outfile) - call delete(errorfile) - execute cd.'`=dir`' - call fugitive#reload_status() - endtry -endfunction - -function! s:CommitComplete(A,L,P) abort - if a:A =~ '^-' || type(a:A) == type(0) " a:A is 0 on :Gcommit - - let args = ['-C', '-F', '-a', '-c', '-e', '-i', '-m', '-n', '-o', '-q', '-s', '-t', '-u', '-v', '--all', '--allow-empty', '--amend', '--author=', '--cleanup=', '--dry-run', '--edit', '--file=', '--include', '--interactive', '--message=', '--no-verify', '--only', '--quiet', '--reedit-message=', '--reuse-message=', '--signoff', '--template=', '--untracked-files', '--verbose'] - return filter(args,'v:val[0 : strlen(a:A)-1] ==# a:A') - else - return s:repo().superglob(a:A) - endif -endfunction - -function! s:FinishCommit() - let args = getbufvar(+expand(''),'fugitive_commit_arguments') - if !empty(args) - call setbufvar(+expand(''),'fugitive_commit_arguments','') - return s:Commit(args) - endif - return '' -endfunction - -augroup fugitive_commit - autocmd! - autocmd VimLeavePre,BufDelete *.git/COMMIT_EDITMSG execute s:sub(s:FinishCommit(), '^echoerr (.*)', 'echohl ErrorMsg|echo \1|echohl NONE') -augroup END - -" }}}1 -" Ggrep, Glog {{{1 - -if !exists('g:fugitive_summary_format') - let g:fugitive_summary_format = '%s' -endif - -call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Ggrep :execute s:Grep(0,)") -call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Glog :execute s:Log('grep',)") - -function! s:Grep(bang,arg) abort - let grepprg = &grepprg - let grepformat = &grepformat - let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' - let dir = getcwd() - try - execute cd.'`=s:repo().tree()`' - let &grepprg = s:repo().git_command('--no-pager', 'grep', '-n') - let &grepformat = '%f:%l:%m' - exe 'grep! '.escape(matchstr(a:arg,'\v\C.{-}%($|[''" ]\@=\|)@='),'|') - let list = getqflist() - for entry in list - if bufname(entry.bufnr) =~ ':' - let entry.filename = s:repo().translate(bufname(entry.bufnr)) - unlet! entry.bufnr - elseif a:arg =~# '\%(^\| \)--cached\>' - let entry.filename = s:repo().translate(':0:'.bufname(entry.bufnr)) - unlet! entry.bufnr - endif - endfor - call setqflist(list,'r') - if !a:bang && !empty(list) - return 'cfirst'.matchstr(a:arg,'\v\C[''" ]\zs\|.*') - else - return matchstr(a:arg,'\v\C[''" ]\|\zs.*') - endif - finally - let &grepprg = grepprg - let &grepformat = grepformat - execute cd.'`=dir`' - endtry -endfunction - -function! s:Log(cmd,...) - let path = s:buffer().path('/') - if path =~# '^/\.git\%(/\|$\)' || index(a:000,'--') != -1 - let path = '' - endif - let cmd = ['--no-pager', 'log', '--no-color'] - let cmd += [escape('--pretty=format:fugitive://'.s:repo().dir().'//%H'.path.'::'.g:fugitive_summary_format,'%')] - if empty(filter(a:000[0 : index(a:000,'--')],'v:val !~# "^-"')) - if s:buffer().commit() =~# '\x\{40\}' - let cmd += [s:buffer().commit()] - elseif s:buffer().path() =~# '^\.git/refs/\|^\.git/.*HEAD$' - let cmd += [s:buffer().path()[5:-1]] - endif - end - let cmd += map(copy(a:000),'s:sub(v:val,"^\\%(%(:\\w)*)","\\=fnamemodify(s:buffer().path(),submatch(1))")') - if path =~# '/.' - let cmd += ['--',path[1:-1]] - endif - let grepformat = &grepformat - let grepprg = &grepprg - let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' - let dir = getcwd() - try - execute cd.'`=s:repo().tree()`' - let &grepprg = call(s:repo().git_command,cmd,s:repo()) - let &grepformat = '%f::%m' - exe a:cmd - finally - let &grepformat = grepformat - let &grepprg = grepprg - execute cd.'`=dir`' - endtry -endfunction - -" }}}1 -" Gedit, Gpedit, Gsplit, Gvsplit, Gtabedit, Gread {{{1 - -function! s:Edit(cmd,bang,...) abort - if a:cmd !~# 'read' - if &previewwindow && getbufvar('','fugitive_type') ==# 'index' - wincmd p - if &diff - let mywinnr = winnr() - for winnr in range(winnr('$'),1,-1) - if winnr != mywinnr && getwinvar(winnr,'&diff') - execute winnr.'wincmd w' - close - wincmd p - endif - endfor - endif - endif - endif - - if a:bang - let args = s:gsub(a:0 ? a:1 : '', '\\@>>>>>> - if getline(1) !~# '^diff ' - setlocal readonly nomodifiable - endif - if a:cmd =~# 'pedit' - wincmd p - endif - return echo - endif - return '' - endif - - if a:0 && a:1 == '' - return '' - elseif a:0 - let file = s:buffer().expand(a:1) - elseif expand('%') ==# '' - let file = ':' - elseif s:buffer().commit() ==# '' && s:buffer().path('/') !~# '^/.git\>' - let file = s:buffer().path(':') - else - let file = s:buffer().path('/') - endif - try - let file = s:repo().translate(file) - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry - if a:cmd ==# 'read' - return 'silent %delete_|read '.s:fnameescape(file).'|silent 1delete_|diffupdate|'.line('.') - else - return a:cmd.' '.s:fnameescape(file) - endif -endfunction - -function! s:EditComplete(A,L,P) abort - return s:repo().superglob(a:A) -endfunction - -function! s:EditRunComplete(A,L,P) abort - if a:L =~# '^\w\+!' - return s:GitComplete(a:A,a:L,a:P) - else - return s:repo().superglob(a:A) - endif -endfunction - -call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Ge :execute s:Edit('edit',0,)") -call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gedit :execute s:Edit('edit',0,)") -call s:command("-bar -bang -nargs=? -complete=customlist,s:EditRunComplete Gpedit :execute s:Edit('pedit',0,)") -call s:command("-bar -bang -nargs=? -complete=customlist,s:EditRunComplete Gsplit :execute s:Edit('split',0,)") -call s:command("-bar -bang -nargs=? -complete=customlist,s:EditRunComplete Gvsplit :execute s:Edit('vsplit',0,)") -call s:command("-bar -bang -nargs=? -complete=customlist,s:EditRunComplete Gtabedit :execute s:Edit('tabedit',0,)") -call s:command("-bar -bang -nargs=? -count -complete=customlist,s:EditRunComplete Gread :execute s:Edit((! && ? '' : ).'read',0,)") - -" }}}1 -" Gwrite, Gwq {{{1 - -call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gwrite :execute s:Write(0,)") -call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gw :execute s:Write(0,)") -call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gwq :execute s:Wq(0,)") - -function! s:Write(force,...) abort - if exists('b:fugitive_commit_arguments') - return 'write|bdelete' - elseif expand('%:t') == 'COMMIT_EDITMSG' && $GIT_INDEX_FILE != '' - return 'wq' - elseif s:buffer().type() == 'index' - return 'Gcommit' - elseif s:buffer().path() ==# '' && getline(4) =~# '^+++ ' - let filename = getline(4)[6:-1] - setlocal buftype= - silent write - setlocal buftype=nowrite - if matchstr(getline(2),'index [[:xdigit:]]\+\.\.\zs[[:xdigit:]]\{7\}') ==# s:repo().rev_parse(':0:'.filename)[0:6] - let err = s:repo().git_chomp('apply','--cached','--reverse',s:buffer().spec()) - else - let err = s:repo().git_chomp('apply','--cached',s:buffer().spec()) - endif - if err !=# '' - let v:errmsg = split(err,"\n")[0] - return 'echoerr v:errmsg' - elseif a:force - return 'bdelete' - else - return 'Gedit '.fnameescape(filename) - endif - endif - let mytab = tabpagenr() - let mybufnr = bufnr('') - let path = a:0 ? a:1 : s:buffer().path() - if path =~# '^:\d\>' - return 'write'.(a:force ? '! ' : ' ').s:fnameescape(s:repo().translate(s:buffer().expand(path))) - endif - let always_permitted = (s:buffer().path() ==# path && s:buffer().commit() =~# '^0\=$') - if !always_permitted && !a:force && s:repo().git_chomp_in_tree('diff','--name-status','HEAD','--',path) . s:repo().git_chomp_in_tree('ls-files','--others','--',path) !=# '' - let v:errmsg = 'fugitive: file has uncommitted changes (use ! to override)' - return 'echoerr v:errmsg' - endif - let file = s:repo().translate(path) - let treebufnr = 0 - for nr in range(1,bufnr('$')) - if fnamemodify(bufname(nr),':p') ==# file - let treebufnr = nr - endif - endfor - - if treebufnr > 0 && treebufnr != bufnr('') - let temp = tempname() - silent execute '%write '.temp - for tab in [mytab] + range(1,tabpagenr('$')) - for winnr in range(1,tabpagewinnr(tab,'$')) - if tabpagebuflist(tab)[winnr-1] == treebufnr - execute 'tabnext '.tab - if winnr != winnr() - execute winnr.'wincmd w' - let restorewinnr = 1 - endif - try - let lnum = line('.') - let last = line('$') - silent execute '$read '.temp - silent execute '1,'.last.'delete_' - silent write! - silent execute lnum - let did = 1 - finally - if exists('restorewinnr') - wincmd p - endif - execute 'tabnext '.mytab - endtry - endif - endfor - endfor - if !exists('did') - call writefile(readfile(temp,'b'),file,'b') - endif - else - execute 'write! '.s:fnameescape(s:repo().translate(path)) - endif - - if a:force - let error = s:repo().git_chomp_in_tree('add', '--force', file) - else - let error = s:repo().git_chomp_in_tree('add', file) - endif - if v:shell_error - let v:errmsg = 'fugitive: '.error - return 'echoerr v:errmsg' - endif - if s:buffer().path() ==# path && s:buffer().commit() =~# '^\d$' - set nomodified - endif - - let one = s:repo().translate(':1:'.path) - let two = s:repo().translate(':2:'.path) - let three = s:repo().translate(':3:'.path) - for nr in range(1,bufnr('$')) - if bufloaded(nr) && !getbufvar(nr,'&modified') && (bufname(nr) == one || bufname(nr) == two || bufname(nr) == three) - execute nr.'bdelete' - endif - endfor - - unlet! restorewinnr - let zero = s:repo().translate(':0:'.path) - for tab in range(1,tabpagenr('$')) - for winnr in range(1,tabpagewinnr(tab,'$')) - let bufnr = tabpagebuflist(tab)[winnr-1] - let bufname = bufname(bufnr) - if bufname ==# zero && bufnr != mybufnr - execute 'tabnext '.tab - if winnr != winnr() - execute winnr.'wincmd w' - let restorewinnr = 1 - endif - try - let lnum = line('.') - let last = line('$') - silent $read `=file` - silent execute '1,'.last.'delete_' - silent execute lnum - set nomodified - diffupdate - finally - if exists('restorewinnr') - wincmd p - endif - execute 'tabnext '.mytab - endtry - break - endif - endfor - endfor - call fugitive#reload_status() - return 'checktime' -endfunction - -function! s:Wq(force,...) abort - let bang = a:force ? '!' : '' - if exists('b:fugitive_commit_arguments') - return 'wq'.bang - endif - let result = call(s:function('s:Write'),[a:force]+a:000) - if result =~# '^\%(write\|wq\|echoerr\)' - return s:sub(result,'^write','wq') - else - return result.'|quit'.bang - endif -endfunction - -" }}}1 -" Gdiff {{{1 - -call s:command("-bang -bar -nargs=? -complete=customlist,s:EditComplete Gdiff :execute s:Diff(0,)") -call s:command("-bar -nargs=? -complete=customlist,s:EditComplete Gvdiff :execute s:Diff(0,)") -call s:command("-bar -nargs=? -complete=customlist,s:EditComplete Gsdiff :execute s:Diff(1,)") - -augroup fugitive_diff - autocmd! - autocmd BufWinLeave * if s:diff_window_count() == 2 && &diff && getbufvar(+expand(''), 'git_dir') !=# '' | call s:diffoff_all(getbufvar(+expand(''), 'git_dir')) | endif - autocmd BufWinEnter * if s:diff_window_count() == 1 && &diff && getbufvar(+expand(''), 'git_dir') !=# '' | call s:diffoff() | endif -augroup END - -function! s:diff_window_count() - let c = 0 - for nr in range(1,winnr('$')) - let c += getwinvar(nr,'&diff') - endfor - return c -endfunction - -function! s:diffthis() - if !&diff - let w:fugitive_diff_restore = 'setlocal nodiff noscrollbind' - let w:fugitive_diff_restore .= ' scrollopt=' . &l:scrollopt - let w:fugitive_diff_restore .= &l:wrap ? ' wrap' : ' nowrap' - let w:fugitive_diff_restore .= ' foldmethod=' . &l:foldmethod - let w:fugitive_diff_restore .= ' foldcolumn=' . &l:foldcolumn - diffthis - endif -endfunction - -function! s:diffoff() - if exists('w:fugitive_diff_restore') - execute w:fugitive_diff_restore - unlet w:fugitive_diff_restore - else - diffoff - endif -endfunction - -function! s:diffoff_all(dir) - for nr in range(1,winnr('$')) - if getwinvar(nr,'&diff') - if nr != winnr() - execute nr.'wincmd w' - let restorewinnr = 1 - endif - if exists('b:git_dir') && b:git_dir ==# a:dir - call s:diffoff() - endif - if exists('restorewinnr') - wincmd p - endif - endif - endfor -endfunction - -function! s:buffer_compare_age(commit) dict abort - let scores = {':0': 1, ':1': 2, ':2': 3, ':': 4, ':3': 5} - let my_score = get(scores,':'.self.commit(),0) - let their_score = get(scores,':'.a:commit,0) - if my_score || their_score - return my_score < their_score ? -1 : my_score != their_score - elseif self.commit() ==# a:commit - return 0 - endif - let base = self.repo().git_chomp('merge-base',self.commit(),a:commit) - if base ==# self.commit() - return -1 - elseif base ==# a:commit - return 1 - endif - let my_time = +self.repo().git_chomp('log','--max-count=1','--pretty=format:%at',self.commit()) - let their_time = +self.repo().git_chomp('log','--max-count=1','--pretty=format:%at',a:commit) - return my_time < their_time ? -1 : my_time != their_time -endfunction - -call s:add_methods('buffer',['compare_age']) - -function! s:Diff(bang,...) abort - let split = a:bang ? 'split' : 'vsplit' - if exists(':DiffGitCached') - return 'DiffGitCached' - elseif (!a:0 || a:1 == ':') && s:buffer().commit() =~# '^[0-1]\=$' && s:repo().git_chomp_in_tree('ls-files', '--unmerged', '--', s:buffer().path()) !=# '' - let nr = bufnr('') - execute 'leftabove '.split.' `=fugitive#buffer().repo().translate(s:buffer().expand('':2''))`' - execute 'nnoremap dp :diffput '.nr.'diffupdate' - call s:diffthis() - wincmd p - execute 'rightbelow '.split.' `=fugitive#buffer().repo().translate(s:buffer().expand('':3''))`' - execute 'nnoremap dp :diffput '.nr.'diffupdate' - call s:diffthis() - wincmd p - call s:diffthis() - return '' - elseif a:0 - if a:1 ==# '' - return '' - elseif a:1 ==# '/' - let file = s:buffer().path('/') - elseif a:1 ==# ':' - let file = s:buffer().path(':0:') - elseif a:1 =~# '^:/.' - try - let file = s:repo().rev_parse(a:1).s:buffer().path(':') - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry - else - let file = s:buffer().expand(a:1) - endif - if file !~# ':' && file !~# '^/' && s:repo().git_chomp('cat-file','-t',file) =~# '^\%(tag\|commit\)$' - let file = file.s:buffer().path(':') - endif - else - let file = s:buffer().path(s:buffer().commit() == '' ? ':0:' : '/') - endif - try - let spec = s:repo().translate(file) - let commit = matchstr(spec,'\C[^:/]//\zs\x\+') - if s:buffer().compare_age(commit) < 0 - execute 'rightbelow '.split.' `=spec`' - else - execute 'leftabove '.split.' `=spec`' - endif - call s:diffthis() - wincmd p - call s:diffthis() - return '' - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry -endfunction - -" }}}1 -" Gmove, Gremove {{{1 - -function! s:Move(force,destination) - if a:destination =~# '^/' - let destination = a:destination[1:-1] - else - let destination = fnamemodify(s:sub(a:destination,'[%#]%(:\w)*','\=expand(submatch(0))'),':p') - if destination[0:strlen(s:repo().tree())] ==# s:repo().tree('') - let destination = destination[strlen(s:repo().tree('')):-1] - endif - endif - if isdirectory(s:buffer().name()) - " Work around Vim parser idiosyncrasy - let discarded = s:buffer().setvar('&swapfile',0) - endif - let message = call(s:repo().git_chomp_in_tree,['mv']+(a:force ? ['-f'] : [])+['--', s:buffer().path(), destination], s:repo()) - if v:shell_error - let v:errmsg = 'fugitive: '.message - return 'echoerr v:errmsg' - endif - let destination = s:repo().tree(destination) - if isdirectory(destination) - let destination = fnamemodify(s:sub(destination,'/$','').'/'.expand('%:t'),':.') - endif - call fugitive#reload_status() - if s:buffer().commit() == '' - if isdirectory(destination) - return 'edit '.s:fnameescape(destination) - else - return 'saveas! '.s:fnameescape(destination) - endif - else - return 'file '.s:fnameescape(s:repo().translate(':0:'.destination) - endif -endfunction - -function! s:MoveComplete(A,L,P) - if a:A =~ '^/' - return s:repo().superglob(a:A) - else - let matches = split(glob(a:A.'*'),"\n") - call map(matches,'v:val !~ "/$" && isdirectory(v:val) ? v:val."/" : v:val') - return matches - endif -endfunction - -function! s:Remove(force) - if s:buffer().commit() ==# '' - let cmd = ['rm'] - elseif s:buffer().commit() ==# '0' - let cmd = ['rm','--cached'] - else - let v:errmsg = 'fugitive: rm not supported here' - return 'echoerr v:errmsg' - endif - if a:force - let cmd += ['--force'] - endif - let message = call(s:repo().git_chomp_in_tree,cmd+['--',s:buffer().path()],s:repo()) - if v:shell_error - let v:errmsg = 'fugitive: '.s:sub(message,'error:.*\zs\n\(.*-f.*',' (add ! to force)') - return 'echoerr '.string(v:errmsg) - else - call fugitive#reload_status() - return 'bdelete'.(a:force ? '!' : '') - endif -endfunction - -augroup fugitive_remove - autocmd! - autocmd User Fugitive if s:buffer().commit() =~# '^0\=$' | - \ exe "command! -buffer -bar -bang -nargs=1 -complete=customlist,s:MoveComplete Gmove :execute s:Move(0,)" | - \ exe "command! -buffer -bar -bang Gremove :execute s:Remove(0)" | - \ endif -augroup END - -" }}}1 -" Gblame {{{1 - -augroup fugitive_blame - autocmd! - autocmd BufReadPost *.fugitiveblame setfiletype fugitiveblame - autocmd FileType fugitiveblame setlocal nomodeline | if exists('b:git_dir') | let &l:keywordprg = s:repo().keywordprg() | endif - autocmd Syntax fugitiveblame call s:BlameSyntax() - autocmd User Fugitive if s:buffer().type('file', 'blob') | exe "command! -buffer -bar -bang -range=0 -nargs=* Gblame :execute s:Blame(0,,,,[])" | endif -augroup END - -function! s:Blame(bang,line1,line2,count,args) abort - try - if s:buffer().path() == '' - call s:throw('file or blob required') - endif - if filter(copy(a:args),'v:val !~# "^\\%(--root\|--show-name\\|-\\=\\%([ltwfs]\\|[MC]\\d*\\)\\+\\)$"') != [] - call s:throw('unsupported option') - endif - call map(a:args,'s:sub(v:val,"^\\ze[^-]","-")') - let cmd = ['--no-pager', 'blame', '--show-number'] + a:args - if s:buffer().commit() =~# '\D\|..' - let cmd += [s:buffer().commit()] - else - let cmd += ['--contents', '-'] - endif - let basecmd = escape(call(s:repo().git_command,cmd+['--',s:buffer().path()],s:repo()),'!') - try - let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' - if !s:repo().bare() - let dir = getcwd() - execute cd.'`=s:repo().tree()`' - endif - if a:count - execute 'write !'.substitute(basecmd,' blame ',' blame -L '.a:line1.','.a:line2.' ','g') - else - let error = tempname() - let temp = error.'.fugitiveblame' - if &shell =~# 'csh' - silent! execute '%write !('.basecmd.' > '.temp.') >& '.error - else - silent! execute '%write !'.basecmd.' > '.temp.' 2> '.error - endif - if exists('l:dir') - execute cd.'`=dir`' - unlet dir - endif - if v:shell_error - call s:throw(join(readfile(error),"\n")) - endif - let bufnr = bufnr('') - let restore = 'call setwinvar(bufwinnr('.bufnr.'),"&scrollbind",0)' - if &l:wrap - let restore .= '|call setwinvar(bufwinnr('.bufnr.'),"&wrap",1)' - endif - if &l:foldenable - let restore .= '|call setwinvar(bufwinnr('.bufnr.'),"&foldenable",1)' - endif - let winnr = winnr() - windo set noscrollbind - exe winnr.'wincmd w' - setlocal scrollbind nowrap nofoldenable - let top = line('w0') + &scrolloff - let current = line('.') - let s:temp_files[temp] = s:repo().dir() - exe 'leftabove vsplit '.temp - let b:fugitive_blamed_bufnr = bufnr - let w:fugitive_leave = restore - let b:fugitive_blame_arguments = join(a:args,' ') - execute top - normal! zt - execute current - execute "vertical resize ".(match(getline('.'),'\s\+\d\+)')+1) - setlocal nomodified nomodifiable nonumber scrollbind nowrap foldcolumn=0 nofoldenable filetype=fugitiveblame - if exists('+relativenumber') - setlocal norelativenumber - endif - nnoremap :exe BlameJump('') - nnoremap P :exe BlameJump('^'.v:count1) - nnoremap ~ :exe BlameJump('~'.v:count1) - nnoremap o :exe Edit((&splitbelow ? "botright" : "topleft")." split", 0, matchstr(getline('.'),'\x\+')) - nnoremap O :exe Edit("tabedit", 0, matchstr(getline('.'),'\x\+')) - syncbind - endif - finally - if exists('l:dir') - execute cd.'`=dir`' - endif - endtry - return '' - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry -endfunction - -function! s:BlameJump(suffix) abort - let commit = matchstr(getline('.'),'^\^\=\zs\x\+') - if commit =~# '^0\+$' - let commit = ':0' - endif - let lnum = matchstr(getline('.'),'\d\+\ze\s\+[([:digit:]]') - let path = matchstr(getline('.'),'^\^\=\zs\x\+\s\+\zs.\{-\}\ze\s*\d\+ ') - if path ==# '' - let path = s:buffer(b:fugitive_blamed_bufnr).path() - endif - let args = b:fugitive_blame_arguments - let offset = line('.') - line('w0') - let bufnr = bufnr('%') - let winnr = bufwinnr(b:fugitive_blamed_bufnr) - if winnr > 0 - exe winnr.'wincmd w' - endif - execute s:Edit('edit', 0, commit.a:suffix.':'.path) - if winnr > 0 - exe bufnr.'bdelete' - endif - execute 'Gblame '.args - execute lnum - let delta = line('.') - line('w0') - offset - if delta > 0 - execute 'norm! 'delta."\" - elseif delta < 0 - execute 'norm! '(-delta)."\" - endif - syncbind - return '' -endfunction - -function! s:BlameSyntax() abort - let b:current_syntax = 'fugitiveblame' - syn match FugitiveblameBoundary "^\^" - syn match FugitiveblameBlank "^\s\+\s\@=" nextgroup=FugitiveblameAnnotation,fugitiveblameOriginalFile,FugitiveblameOriginalLineNumber skipwhite - syn match FugitiveblameHash "\%(^\^\=\)\@<=\x\{7,40\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite - syn match FugitiveblameUncommitted "\%(^\^\=\)\@<=0\{7,40\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite - syn region FugitiveblameAnnotation matchgroup=FugitiveblameDelimiter start="(" end="\%( \d\+\)\@<=)" contained keepend oneline - syn match FugitiveblameTime "[0-9:/+-][0-9:/+ -]*[0-9:/+-]\%( \+\d\+)\)\@=" contained containedin=FugitiveblameAnnotation - syn match FugitiveblameLineNumber " \@<=\d\+)\@=" contained containedin=FugitiveblameAnnotation - syn match FugitiveblameOriginalFile " \%(\f\+\D\@<=\|\D\@=\f\+\)\%(\%(\s\+\d\+\)\=\s\%((\|\s*\d\+)\)\)\@=" contained nextgroup=FugitiveblameOriginalLineNumber,FugitiveblameAnnotation skipwhite - syn match FugitiveblameOriginalLineNumber " \@<=\d\+\%(\s(\)\@=" contained nextgroup=FugitiveblameAnnotation skipwhite - syn match FugitiveblameOriginalLineNumber " \@<=\d\+\%(\s\+\d\+)\)\@=" contained nextgroup=FugitiveblameShort skipwhite - syn match FugitiveblameShort "\d\+)" contained contains=FugitiveblameLineNumber - syn match FugitiveblameNotCommittedYet "(\@<=Not Committed Yet\>" contained containedin=FugitiveblameAnnotation - hi def link FugitiveblameBoundary Keyword - hi def link FugitiveblameHash Identifier - hi def link FugitiveblameUncommitted Function - hi def link FugitiveblameTime PreProc - hi def link FugitiveblameLineNumber Number - hi def link FugitiveblameOriginalFile String - hi def link FugitiveblameOriginalLineNumber Float - hi def link FugitiveblameShort FugitiveblameDelimiter - hi def link FugitiveblameDelimiter Delimiter - hi def link FugitiveblameNotCommittedYet Comment -endfunction - -" }}}1 -" Gbrowse {{{1 - -call s:command("-bar -bang -count=0 -nargs=? -complete=customlist,s:EditComplete Gbrowse :execute s:Browse(0,,,)") - -function! s:Browse(bang,line1,count,...) abort - try - let rev = a:0 ? substitute(a:1,'@[[:alnum:]_-]*\%(://.\{-\}\)\=$','','') : '' - if rev ==# '' - let expanded = s:buffer().rev() - elseif rev ==# ':' - let expanded = s:buffer().path('/') - else - let expanded = s:buffer().expand(rev) - endif - let full = s:repo().translate(expanded) - let commit = '' - if full =~# '^fugitive://' - let commit = matchstr(full,'://.*//\zs\w\+') - let path = matchstr(full,'://.*//\w\+\zs/.*') - if commit =~ '..' - let type = s:repo().git_chomp('cat-file','-t',commit.s:sub(path,'^/',':')) - else - let type = 'blob' - endif - let path = path[1:-1] - elseif s:repo().bare() - let path = '.git/' . full[strlen(s:repo().dir())+1:-1] - let type = '' - else - let path = full[strlen(s:repo().tree())+1:-1] - if path =~# '^\.git/' - let type = '' - elseif isdirectory(full) - let type = 'tree' - else - let type = 'blob' - endif - endif - if path =~# '^\.git/.*HEAD' && filereadable(s:repo().dir(path[5:-1])) - let body = readfile(s:repo().dir(path[5:-1]))[0] - if body =~# '^\x\{40\}$' - let commit = body - let type = 'commit' - let path = '' - elseif body =~# '^ref: refs/' - let path = '.git/' . matchstr(body,'ref: \zs.*') - endif - endif - - if a:0 && a:1 =~# '@[[:alnum:]_-]*\%(://.\{-\}\)\=$' - let remote = matchstr(a:1,'@\zs[[:alnum:]_-]\+\%(://.\{-\}\)\=$') - elseif path =~# '^\.git/refs/remotes/.' - let remote = matchstr(path,'^\.git/refs/remotes/\zs[^/]\+') - else - let remote = 'origin' - let branch = matchstr(rev,'^[[:alnum:]/._-]\+\ze[:^~@]') - if branch ==# '' && path =~# '^\.git/refs/\w\+/' - let branch = s:sub(path,'^\.git/refs/\w+/','') - endif - if filereadable(s:repo().dir('refs/remotes/'.branch)) - let remote = matchstr(branch,'[^/]\+') - let rev = rev[strlen(remote)+1:-1] - else - if branch ==# '' - let branch = matchstr(s:repo().head_ref(),'\\)' - return root . '/admin' - elseif path =~# '^\.git\>' - return root - endif - if a:rev =~# '^[[:alnum:]._-]\+:' - let commit = matchstr(a:rev,'^[^:]*') - elseif a:commit =~# '^\d\=$' - let local = matchstr(a:repo.head_ref(),'\' - return root - endif - let url = root - if a:commit =~# '^\x\{40\}$' - if a:type ==# 'commit' - let url .= ';a=commit' - endif - let url .= ';h=' . a:repo.rev_parse(a:commit . (a:path == '' ? '' : ':' . a:path)) - else - if a:type ==# 'blob' - let tmp = tempname() - silent execute 'write !'.a:repo.git_command('hash-object','-w','--stdin').' > '.tmp - let url .= ';h=' . readfile(tmp)[0] - else - try - let url .= ';h=' . a:repo.rev_parse((a:commit == '' ? 'HEAD' : ':' . a:commit) . ':' . a:path) - catch /^fugitive:/ - call s:throw('fugitive: cannot browse uncommitted file') - endtry - endif - let root .= ';hb=' . matchstr(a:repo.head_ref(),'[^ ]\+$') - endif - if a:path !=# '' - let url .= ';f=' . a:path - endif - if a:0 && a:1 - let url .= '#l' . a:1 - endif - return url -endfunction - -" }}}1 -" File access {{{1 - -function! s:ReplaceCmd(cmd,...) abort - let fn = bufname('') - let tmp = tempname() - let prefix = '' - try - if a:0 && a:1 != '' - if &shell =~# 'cmd' - let old_index = $GIT_INDEX_FILE - let $GIT_INDEX_FILE = a:1 - else - let prefix = 'env GIT_INDEX_FILE='.s:shellesc(a:1).' ' - endif - endif - if &shell =~# 'cmd' - call system('cmd /c "'.prefix.a:cmd.' > '.tmp.'"') - else - call system(' ('.prefix.a:cmd.' > '.tmp.') ') - endif - finally - if exists('old_index') - let $GIT_INDEX_FILE = old_index - endif - endtry - silent exe 'keepalt file '.tmp - silent edit! - silent exe 'keepalt file '.s:fnameescape(fn) - call delete(tmp) - if bufname('$') == tmp - silent execute 'bwipeout '.bufnr('$') - endif - silent exe 'doau BufReadPost '.s:fnameescape(fn) -endfunction - -function! s:BufReadIndex() - if !exists('b:fugitive_display_format') - let b:fugitive_display_format = filereadable(expand('%').'.lock') - endif - let b:fugitive_display_format = b:fugitive_display_format % 2 - let b:fugitive_type = 'index' - try - let b:git_dir = s:repo().dir() - setlocal noro ma - if fnamemodify($GIT_INDEX_FILE !=# '' ? $GIT_INDEX_FILE : b:git_dir . '/index', ':p') ==# expand('%:p') - let index = '' - else - let index = expand('%:p') - endif - if b:fugitive_display_format - call s:ReplaceCmd(s:repo().git_command('ls-files','--stage'),index) - set ft=git nospell - else - let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' - let dir = getcwd() - try - execute cd.'`=s:repo().tree()`' - call s:ReplaceCmd(s:repo().git_command('status'),index) - finally - execute cd.'`=dir`' - endtry - set ft=gitcommit - endif - setlocal ro noma nomod nomodeline bufhidden=wipe - call s:JumpInit() - nunmap P - nunmap ~ - nnoremap :call search('^#\t.*','W'). - nnoremap :call search('^#\t.*','Wbe'). - nnoremap - :execute StageToggle(line('.'),line('.')+v:count1-1) - xnoremap - :execute StageToggle(line("'<"),line("'>")) - nnoremap a :let b:fugitive_display_format += 1exe BufReadIndex() - nnoremap i :let b:fugitive_display_format -= 1exe BufReadIndex() - nnoremap C :Gcommit - nnoremap cA :Gcommit --amend --reuse-message=HEAD - nnoremap ca :Gcommit --amend - nnoremap cc :Gcommit - nnoremap D :execute StageDiff('Gvdiff') - nnoremap dd :execute StageDiff('Gvdiff') - nnoremap dh :execute StageDiff('Gsdiff') - nnoremap ds :execute StageDiff('Gsdiff') - nnoremap dp :execute StageDiffEdit() - nnoremap dv :execute StageDiff('Gvdiff') - nnoremap p :execute StagePatch(line('.'),line('.')+v:count1-1) - xnoremap p :execute StagePatch(line("'<"),line("'>")) - nnoremap q :if bufnr('$') == 1quitelsebdeleteendif - nnoremap R :edit - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry -endfunction - -function! s:FileRead() - try - let repo = s:repo(s:ExtractGitDir(expand(''))) - let path = s:sub(s:sub(matchstr(expand(''),'fugitive://.\{-\}//\zs.*'),'/',':'),'^\d:',':&') - let hash = repo.rev_parse(path) - if path =~ '^:' - let type = 'blob' - else - let type = repo.git_chomp('cat-file','-t',hash) - endif - " TODO: use count, if possible - return "read !".escape(repo.git_command('cat-file',type,hash),'%#\') - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry -endfunction - -function! s:BufReadIndexFile() - try - let b:fugitive_type = 'blob' - let b:git_dir = s:repo().dir() - call s:ReplaceCmd(s:repo().git_command('cat-file','blob',s:buffer().sha1())) - if &bufhidden ==# '' - setlocal bufhidden=delete - endif - return '' - catch /^fugitive: rev-parse/ - silent exe 'doau BufNewFile '.s:fnameescape(bufname('')) - return '' - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry -endfunction - -function! s:BufWriteIndexFile() - let tmp = tempname() - try - let path = matchstr(expand(''),'//\d/\zs.*') - let stage = matchstr(expand(''),'//\zs\d') - silent execute 'write !'.s:repo().git_command('hash-object','-w','--stdin').' > '.tmp - let sha1 = readfile(tmp)[0] - let old_mode = matchstr(s:repo().git_chomp('ls-files','--stage',path),'^\d\+') - if old_mode == '' - let old_mode = executable(s:repo().tree(path)) ? '100755' : '100644' - endif - let info = old_mode.' '.sha1.' '.stage."\t".path - call writefile([info],tmp) - if has('win32') - let error = system('type '.tmp.'|'.s:repo().git_command('update-index','--index-info')) - else - let error = system(s:repo().git_command('update-index','--index-info').' < '.tmp) - endif - if v:shell_error == 0 - setlocal nomodified - silent execute 'doautocmd BufWritePost '.s:fnameescape(expand('%:p')) - call fugitive#reload_status() - return '' - else - return 'echoerr '.string('fugitive: '.error) - endif - finally - call delete(tmp) - endtry -endfunction - -function! s:BufReadObject() - try - setlocal noro ma - let b:git_dir = s:repo().dir() - let hash = s:buffer().sha1() - if !exists("b:fugitive_type") - let b:fugitive_type = s:repo().git_chomp('cat-file','-t',hash) - endif - if b:fugitive_type !~# '^\%(tag\|commit\|tree\|blob\)$' - return "echoerr 'fugitive: unrecognized git type'" - endif - let firstline = getline('.') - if !exists('b:fugitive_display_format') && b:fugitive_type != 'blob' - let b:fugitive_display_format = +getbufvar('#','fugitive_display_format') - endif - - let pos = getpos('.') - silent %delete - setlocal endofline - - if b:fugitive_type == 'tree' - let b:fugitive_display_format = b:fugitive_display_format % 2 - if b:fugitive_display_format - call s:ReplaceCmd(s:repo().git_command('ls-tree',hash)) - else - call s:ReplaceCmd(s:repo().git_command('show','--no-color',hash)) - endif - elseif b:fugitive_type == 'tag' - let b:fugitive_display_format = b:fugitive_display_format % 2 - if b:fugitive_display_format - call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash)) - else - call s:ReplaceCmd(s:repo().git_command('cat-file','-p',hash)) - endif - elseif b:fugitive_type == 'commit' - let b:fugitive_display_format = b:fugitive_display_format % 2 - if b:fugitive_display_format - call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash)) - else - call s:ReplaceCmd(s:repo().git_command('show','--no-color','--pretty=format:tree %T%nparent %P%nauthor %an <%ae> %ad%ncommitter %cn <%ce> %cd%nencoding %e%n%n%s%n%n%b',hash)) - call search('^parent ') - if getline('.') ==# 'parent ' - silent delete_ - else - silent s/\%(^parent\)\@\)\=$','W',line('.')+3) - silent delete_ - end - 1 - endif - elseif b:fugitive_type ==# 'blob' - call s:ReplaceCmd(s:repo().git_command('cat-file',b:fugitive_type,hash)) - endif - call setpos('.',pos) - setlocal ro noma nomod nomodeline - if &bufhidden ==# '' - setlocal bufhidden=delete - endif - if b:fugitive_type !=# 'blob' - set filetype=git - nnoremap a :let b:fugitive_display_format += v:count1exe BufReadObject() - nnoremap i :let b:fugitive_display_format -= v:count1exe BufReadObject() - else - call s:JumpInit() - endif - - return '' - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry -endfunction - -augroup fugitive_files - autocmd! - autocmd BufReadCmd *.git/index exe s:BufReadIndex() - autocmd BufReadCmd *.git/*index*.lock exe s:BufReadIndex() - autocmd FileReadCmd fugitive://**//[0-3]/** exe s:FileRead() - autocmd BufReadCmd fugitive://**//[0-3]/** exe s:BufReadIndexFile() - autocmd BufWriteCmd fugitive://**//[0-3]/** exe s:BufWriteIndexFile() - autocmd BufReadCmd fugitive://**//[0-9a-f][0-9a-f]* exe s:BufReadObject() - autocmd FileReadCmd fugitive://**//[0-9a-f][0-9a-f]* exe s:FileRead() - autocmd FileType git call s:JumpInit() -augroup END - -" }}}1 -" Temp files {{{1 - -let s:temp_files = {} - -augroup fugitive_temp - autocmd! - autocmd BufNewFile,BufReadPost * - \ if has_key(s:temp_files,expand(':p')) | - \ let b:git_dir = s:temp_files[expand(':p')] | - \ let b:git_type = 'temp' | - \ call s:Detect(expand(':p')) | - \ setlocal bufhidden=delete | - \ nnoremap q :bdelete | - \ endif -augroup END - -" }}}1 -" Go to file {{{1 - -function! s:JumpInit() abort - nnoremap :exe GF("edit") - if !&modifiable - nnoremap o :exe GF("split") - nnoremap O :exe GF("tabedit") - nnoremap P :exe Edit('edit',0,buffer().commit().'^'.v:count1.buffer().path(':')) - nnoremap ~ :exe Edit('edit',0,buffer().commit().'~'.v:count1.buffer().path(':')) - nnoremap C :exe Edit('edit',0,buffer().containing_commit()) - nnoremap cc :exe Edit('edit',0,buffer().containing_commit()) - nnoremap co :exe Edit('split',0,buffer().containing_commit()) - nnoremap cO :exe Edit('tabedit',0,buffer().containing_commit()) - nnoremap cp :exe Edit('pedit',0,buffer().containing_commit()) - endif -endfunction - -function! s:GF(mode) abort - try - let buffer = s:buffer() - let myhash = buffer.sha1() - if myhash ==# '' && getline(1) =~# '^\%(commit\|tag\) \w' - let myhash = matchstr(getline(1),'^\w\+ \zs\S\+') - endif - - if buffer.type('tree') - let showtree = (getline(1) =~# '^tree ' && getline(2) == "") - if showtree && line('.') == 1 - return "" - elseif showtree && line('.') > 2 - return s:Edit(a:mode,0,buffer.commit().':'.s:buffer().path().(buffer.path() =~# '^$\|/$' ? '' : '/').s:sub(getline('.'),'/$','')) - elseif getline('.') =~# '^\d\{6\} \l\{3,8\} \x\{40\}\t' - return s:Edit(a:mode,0,buffer.commit().':'.s:buffer().path().(buffer.path() =~# '^$\|/$' ? '' : '/').s:sub(matchstr(getline('.'),'\t\zs.*'),'/$','')) - endif - - elseif buffer.type('blob') - let ref = expand("") - try - let sha1 = buffer.repo().rev_parse(ref) - catch /^fugitive:/ - endtry - if exists('sha1') - return s:Edit(a:mode,0,ref) - endif - - else - - " Index - if getline('.') =~# '^\d\{6\} \x\{40\} \d\t' - let ref = matchstr(getline('.'),'\x\{40\}') - let file = ':'.s:sub(matchstr(getline('.'),'\d\t.*'),'\t',':') - return s:Edit(a:mode,0,file) - - elseif getline('.') =~# '^#\trenamed:.* -> ' - let file = '/'.matchstr(getline('.'),' -> \zs.*') - return s:Edit(a:mode,0,file) - elseif getline('.') =~# '^#\t[[:alpha:] ]\+: *.' - let file = '/'.matchstr(getline('.'),': *\zs.\{-\}\ze\%( (new commits)\)\=$') - return s:Edit(a:mode,0,file) - elseif getline('.') =~# '^#\t.' - let file = '/'.matchstr(getline('.'),'#\t\zs.*') - return s:Edit(a:mode,0,file) - elseif getline('.') =~# ': needs merge$' - let file = '/'.matchstr(getline('.'),'.*\ze: needs merge$') - return s:Edit(a:mode,0,file).'|Gdiff' - - elseif getline('.') ==# '# Not currently on any branch.' - return s:Edit(a:mode,0,'HEAD') - elseif getline('.') =~# '^# On branch ' - let file = 'refs/heads/'.getline('.')[12:] - return s:Edit(a:mode,0,file) - elseif getline('.') =~# "^# Your branch .*'" - let file = matchstr(getline('.'),"'\\zs\\S\\+\\ze'") - return s:Edit(a:mode,0,file) - endif - - let showtree = (getline(1) =~# '^tree ' && getline(2) == "") - - if getline('.') =~# '^ref: ' - let ref = strpart(getline('.'),5) - - elseif getline('.') =~# '^commit \x\{40\}\>' - let ref = matchstr(getline('.'),'\x\{40\}') - return s:Edit(a:mode,0,ref) - - elseif getline('.') =~# '^parent \x\{40\}\>' - let ref = matchstr(getline('.'),'\x\{40\}') - let line = line('.') - let parent = 0 - while getline(line) =~# '^parent ' - let parent += 1 - let line -= 1 - endwhile - return s:Edit(a:mode,0,ref) - - elseif getline('.') =~ '^tree \x\{40\}$' - let ref = matchstr(getline('.'),'\x\{40\}') - if s:repo().rev_parse(myhash.':') == ref - let ref = myhash.':' - endif - return s:Edit(a:mode,0,ref) - - elseif getline('.') =~# '^object \x\{40\}$' && getline(line('.')+1) =~ '^type \%(commit\|tree\|blob\)$' - let ref = matchstr(getline('.'),'\x\{40\}') - let type = matchstr(getline(line('.')+1),'type \zs.*') - - elseif getline('.') =~# '^\l\{3,8\} '.myhash.'$' - return '' - - elseif getline('.') =~# '^\l\{3,8\} \x\{40\}\>' - let ref = matchstr(getline('.'),'\x\{40\}') - echoerr "warning: unknown context ".matchstr(getline('.'),'^\l*') - - elseif getline('.') =~# '^[+-]\{3\} [ab/]' - let ref = getline('.')[4:] - - elseif getline('.') =~# '^rename from ' - let ref = 'a/'.getline('.')[12:] - elseif getline('.') =~# '^rename to ' - let ref = 'b/'.getline('.')[10:] - - elseif getline('.') =~# '^diff --git \%(a/.*\|/dev/null\) \%(b/.*\|/dev/null\)' - let dref = matchstr(getline('.'),'\Cdiff --git \zs\%(a/.*\|/dev/null\)\ze \%(b/.*\|/dev/null\)') - let ref = matchstr(getline('.'),'\Cdiff --git \%(a/.*\|/dev/null\) \zs\%(b/.*\|/dev/null\)') - let dcmd = 'Gdiff' - - elseif getline('.') =~# '^index ' && getline(line('.')-1) =~# '^diff --git \%(a/.*\|/dev/null\) \%(b/.*\|/dev/null\)' - let line = getline(line('.')-1) - let dref = matchstr(line,'\Cdiff --git \zs\%(a/.*\|/dev/null\)\ze \%(b/.*\|/dev/null\)') - let ref = matchstr(line,'\Cdiff --git \%(a/.*\|/dev/null\) \zs\%(b/.*\|/dev/null\)') - let dcmd = 'Gdiff!' - - elseif line('$') == 1 && getline('.') =~ '^\x\{40\}$' - let ref = getline('.') - else - let ref = '' - endif - - if myhash ==# '' - let ref = s:sub(ref,'^a/','HEAD:') - let ref = s:sub(ref,'^b/',':0:') - if exists('dref') - let dref = s:sub(dref,'^a/','HEAD:') - endif - else - let ref = s:sub(ref,'^a/',myhash.'^:') - let ref = s:sub(ref,'^b/',myhash.':') - if exists('dref') - let dref = s:sub(dref,'^a/',myhash.'^:') - endif - endif - - if ref ==# '/dev/null' - " Empty blob - let ref = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391' - endif - - if exists('dref') - return s:Edit(a:mode,0,ref) . '|'.dcmd.' '.s:fnameescape(dref) - elseif ref != "" - return s:Edit(a:mode,0,ref) - endif - - endif - return '' - catch /^fugitive:/ - return 'echoerr v:errmsg' - endtry -endfunction - -" }}}1 -" Statusline {{{1 - -function! s:repo_head_ref() dict abort - return readfile(s:repo().dir('HEAD'))[0] -endfunction - -call s:add_methods('repo',['head_ref']) - -function! fugitive#statusline(...) - if !exists('b:git_dir') - return '' - endif - let status = '' - if s:buffer().commit() != '' - let status .= ':' . s:buffer().commit()[0:7] - endif - let head = s:repo().head_ref() - if head =~# '^ref: ' - let status .= s:sub(head,'^ref: %(refs/%(heads/|remotes/|tags/)=)=','(').')' - elseif head =~# '^\x\{40\}$' - let status .= '('.head[0:7].')' - endif - if &statusline =~# '%[MRHWY]' && &statusline !~# '%[mrhwy]' - return ',GIT'.status - else - return '[Git'.status.']' - endif -endfunction - -" }}}1 - -" vim:set ft=vim ts=8 sw=2 sts=2: diff --git a/vim/plugin/gist.vim b/vim/plugin/gist.vim deleted file mode 100644 index 9081d00..0000000 --- a/vim/plugin/gist.vim +++ /dev/null @@ -1,826 +0,0 @@ -"============================================================================= -" File: gist.vim -" Author: Yasuhiro Matsumoto -" Last Change: 20-Aug-2011. -" Version: 5.0 -" WebPage: http://github.com/mattn/gist-vim -" License: BSD -" Usage: -" -" :Gist -" post current buffer to gist, using default privicy option -" (see g:gist_private) -" -" :'<,'>Gist -" post selected text to gist., using default privicy option -" This applies to all permutations listed below (except multi) -" (see g:gist_private) -" -" :Gist -p -" create a private gist -" -" :Gist -P -" create a public gist -" (only relevant if you've set gists to be private by default) -" -" :Gist -P -" post whole text to gist as public -" This is only relevant if you've set gists to be private by default -" :Gist -a -" create a gist anonymously -" -" :Gist -m -" create a gist with all open buffers -" -" :Gist -e -" edit the gist. (you need to have opend the gist buffer first) -" you can update the gist with :w command on gist buffer -" -" :Gist -d -" delete the gist. (you need to have opend the gist buffer first) -" password authentication is needed -" -" :Gist -f -" fork the gist. (you need to have opend the gist buffer first) -" password authentication is needed -" -" :Gist -e foo.js -" edit the gist with name 'foo.js'. (you need to have opend the gist buffer first) -" -" :Gist XXXXX -" get gist XXXXX -" -" :Gist -c XXXXX -" get gist XXXXX and add to clipboard -" -" :Gist -l -" list your public gists -" -" :Gist -l mattn -" list gists from mattn -" -" :Gist -la -" list all your (public and private) gists -" -" Tips: -" * if set g:gist_clip_command, gist.vim will copy the gist code -" with option '-c'. -" -" # mac -" let g:gist_clip_command = 'pbcopy' -" -" # linux -" let g:gist_clip_command = 'xclip -selection clipboard' -" -" # others(cygwin?) -" let g:gist_clip_command = 'putclip' -" -" * if you want to detect filetype from gist's filename... -" -" # detect filetype if vim failed auto-detection. -" let g:gist_detect_filetype = 1 -" -" # detect filetype always. -" let g:gist_detect_filetype = 2 -" -" * if you want to open browser after the post... -" -" let g:gist_open_browser_after_post = 1 -" -" * if you want to change the browser... -" -" let g:gist_browser_command = 'w3m %URL%' -" -" or -" -" let g:gist_browser_command = 'opera %URL% &' -" -" on windows, should work with original setting. -" -" * if you want to show your private gists with ':Gist -l' -" -" let g:gist_show_privates = 1 -" -" * if don't you want to copy URL of the post... -" -" let g:gist_put_url_to_clipboard_after_post = 0 -" -" or if you want to copy URL and add linefeed at the last of URL, -" -" let g:gist_put_url_to_clipboard_after_post = 2 -" -" default value is 1. -" -" Thanks: -" MATSUU Takuto: -" removed carriage return -" gist_browser_command enhancement -" edit support -" -" GetLatestVimScripts: 2423 1 :AutoInstall: gist.vim -" script type: plugin - -if &cp || (exists('g:loaded_gist_vim') && g:loaded_gist_vim) - finish -endif -let g:loaded_gist_vim = 1 - -if (!exists('g:github_user') || !exists('g:github_token')) && !executable('git') - echohl ErrorMsg | echomsg "Gist: require 'git' command" | echohl None - finish -endif - -if !executable('curl') - echohl ErrorMsg | echomsg "Gist: require 'curl' command" | echohl None - finish -endif - -if !exists('g:gist_open_browser_after_post') - let g:gist_open_browser_after_post = 0 -endif - -if !exists('g:gist_put_url_to_clipboard_after_post') - let g:gist_put_url_to_clipboard_after_post = 1 -endif - -if !exists('g:gist_curl_options') - let g:gist_curl_options = "" -endif - -if !exists('g:gist_browser_command') - if has('win32') || has('win64') - let g:gist_browser_command = "!start rundll32 url.dll,FileProtocolHandler %URL%" - elseif has('mac') - let g:gist_browser_command = "open %URL%" - elseif executable('xdg-open') - let g:gist_browser_command = "xdg-open %URL%" - else - let g:gist_browser_command = "firefox %URL% &" - endif -endif - -if !exists('g:gist_detect_filetype') - let g:gist_detect_filetype = 0 -endif - -if !exists('g:gist_private') - let g:gist_private = 0 -endif - -if !exists('g:gist_show_privates') - let g:gist_show_privates = 0 -endif - -if !exists('g:gist_cookie_dir') - let g:gist_cookie_dir = substitute(expand(':p:h'), '[/\\]plugin$', '', '').'/cookies' -endif - -function! s:nr2hex(nr) - let n = a:nr - let r = "" - while n - let r = '0123456789ABCDEF'[n % 16] . r - let n = n / 16 - endwhile - return r -endfunction - -function! s:encodeURIComponent(instr) - let instr = iconv(a:instr, &enc, "utf-8") - let len = strlen(instr) - let i = 0 - let outstr = '' - while i < len - let ch = instr[i] - if ch =~# '[0-9A-Za-z-._~!''()*]' - let outstr = outstr . ch - elseif ch == ' ' - let outstr = outstr . '+' - else - let outstr = outstr . '%' . substitute('0' . s:nr2hex(char2nr(ch)), '^.*\(..\)$', '\1', '') - endif - let i = i + 1 - endwhile - return outstr -endfunction - -" Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it. -let s:bufprefix = 'gist' . (has('unix') ? ':' : '_') -function! s:GistList(user, token, gistls, page) - if a:gistls == '-all' - let url = 'https://gist.github.com/gists' - elseif g:gist_show_privates && a:gistls == a:user - let url = 'https://gist.github.com/mine' - else - let url = 'https://gist.github.com/'.a:gistls - endif - let winnum = bufwinnr(bufnr(s:bufprefix.a:gistls)) - if winnum != -1 - if winnum != bufwinnr('%') - exe winnum 'wincmd w' - endif - setlocal modifiable - else - exec 'silent split' s:bufprefix.a:gistls - endif - if a:page > 1 - let oldlines = getline(0, line('$')) - let url = url . '?page=' . a:page - endif - - setlocal foldmethod=manual - let oldlines = [] - if g:gist_show_privates - echon 'Login to gist... ' - silent %d _ - let res = s:GistGetPage(url, a:user, '', '-L') - silent put =res.content - else - silent %d _ - exec 'silent r! curl -s' g:gist_curl_options url - endif - - 1delete _ - silent! %s/>/>\r/g - silent! %s/ */>/g - silent! %v/^\(gist:\|
\|\)/d _
-  silent! %s/]*>/\r  /g
-  silent! %s/<\/pre>/\r/g
-  silent! %g/^gist:/,/]\+>//g
-  silent! %s/\r//g
-  silent! %s/ / /g
-  silent! %s/"/"/g
-  silent! %s/&/\&/g
-  silent! %s/>/>/g
-  silent! %s/</   :call GistListAction()
-
-  cal cursor(1+len(oldlines),1)
-  setlocal foldmethod=expr
-  setlocal foldexpr=getline(v:lnum)=~'^\\(gist:\\\|more\\)'?'>1':'='
-  setlocal foldtext=getline(v:foldstart)
-endfunction
-
-function! s:GistGetFileName(gistid)
-  let url = 'https://gist.github.com/'.a:gistid
-  let res = system('curl -s '.g:gist_curl_options.' '.url)
-  let res = substitute(res, '^.*
-  endif
-endfunction
-
-function! s:GistGet(user, token, gistid, clipboard)
-  let url = 'https://raw.github.com/gist/'.a:gistid
-  let winnum = bufwinnr(bufnr(s:bufprefix.a:gistid))
-  if winnum != -1
-    if winnum != bufwinnr('%')
-      exe winnum 'wincmd w'
-    endif
-    setlocal modifiable
-  else
-    exec 'silent split' s:bufprefix.a:gistid
-  endif
-  filetype detect
-  silent %d _
-  exec 'silent 0r! curl -s' g:gist_curl_options url
-  $delete _
-  setlocal buftype=acwrite bufhidden=delete noswapfile
-  setlocal nomodified
-  doau StdinReadPost 
-  if (&ft == '' && g:gist_detect_filetype == 1) || g:gist_detect_filetype == 2
-    call s:GistDetectFiletype(a:gistid)
-  endif
-  if a:clipboard
-    if exists('g:gist_clip_command')
-      exec 'silent w !'.g:gist_clip_command
-    else
-      %yank +
-    endif
-  endif
-  1
-  au! BufWriteCmd  call s:GistWrite(expand(""))
-endfunction
-
-function! s:GistListAction()
-  let line = getline('.')
-  let mx = '^gist:\(\w\+\).*'
-  if line =~# mx
-    let gistid = substitute(line, mx, '\1', '')
-    call s:GistGet(g:github_user, g:github_token, gistid, 0)
-    return
-  endif
-  if line =~# '^more\.\.\.$'
-    delete
-    call s:GistList(b:user, b:token, b:gistls, b:page+1)
-    return
-  endif
-endfunction
-
-function! s:GistUpdate(user, token, content, gistid, gistnm)
-  if len(a:gistnm) == 0
-    let name = s:GistGetFileName(a:gistid)
-  else
-    let name = a:gistnm
-  endif
-  let namemx = '^[^.]\+\(.\+\)$'
-  let ext = ''
-  if name =~ namemx
-    let ext = substitute(name, namemx, '\1', '')
-  endif
-  let query = [
-    \ '_method=put',
-    \ 'file_ext[gistfile1%s]=%s',
-    \ 'file_name[gistfile1%s]=%s',
-    \ 'file_contents[gistfile1%s]=%s',
-    \ 'login=%s',
-    \ 'token=%s',
-    \ ]
-  let squery = printf(join(query, '&'),
-    \ s:encodeURIComponent(ext), s:encodeURIComponent(ext),
-    \ s:encodeURIComponent(ext), s:encodeURIComponent(name),
-    \ s:encodeURIComponent(ext), s:encodeURIComponent(a:content),
-    \ s:encodeURIComponent(a:user),
-    \ s:encodeURIComponent(a:token))
-  unlet query
-
-  let file = tempname()
-  call writefile([squery], file)
-  echon 'Updating it to gist... '
-  let quote = &shellxquote == '"' ?  "'" : '"'
-  let url = 'https://gist.github.com/gists/'.a:gistid
-  let res = system('curl -i '.g:gist_curl_options.' -d @'.quote.file.quote.' '.url)
-  call delete(file)
-  let headers = split(res, '\(\r\?\n\|\r\n\?\)')
-  let location = matchstr(headers, '^Location: ')
-  let location = substitute(location, '^[^:]\+: ', '', '')
-  if len(location) > 0 && location =~ '^\(http\|https\):\/\/gist\.github\.com\/'
-    setlocal nomodified
-    redraw
-    echo 'Done: '.location
-  else
-    let message = matchstr(headers, '^Status: ')
-    let message = substitute(message, '^[^:]\+: [0-9]\+ ', '', '')
-    echohl ErrorMsg | echomsg 'Edit failed: '.message | echohl None
-  endif
-  return location
-endfunction
-
-function! s:GistGetPage(url, user, param, opt)
-  if !isdirectory(g:gist_cookie_dir)
-    call mkdir(g:gist_cookie_dir, 'p')
-  endif
-  let cookie_file = g:gist_cookie_dir.'/github'
-
-  if len(a:url) == 0
-    call delete(cookie_file)
-    return
-  endif
-
-  let quote = &shellxquote == '"' ?  "'" : '"'
-  if !filereadable(cookie_file)
-    let password = inputsecret('Password:')
-    if len(password) == 0
-      echo 'Canceled'
-      return
-    endif
-    let url = 'https://gist.github.com/login?return_to=gist'
-    let res = system('curl -L -s '.g:gist_curl_options.' -c '.quote.cookie_file.quote.' '.quote.url.quote)
-    let token = substitute(res, '^.* name="authenticity_token" type="hidden" value="\([^"]\+\)".*$', '\1', '')
-
-    let query = [
-      \ 'authenticity_token=%s',
-      \ 'login=%s',
-      \ 'password=%s',
-      \ 'return_to=gist',
-      \ 'commit=Log+in',
-      \ ]
-    let squery = printf(join(query, '&'),
-      \ s:encodeURIComponent(token),
-      \ s:encodeURIComponent(a:user),
-      \ s:encodeURIComponent(password))
-    unlet query
-
-    let file = tempname()
-    let command = 'curl -s '.g:gist_curl_options.' -i'
-    let command .= ' -b '.quote.cookie_file.quote
-    let command .= ' -c '.quote.cookie_file.quote
-    let command .= ' '.quote.'https://gist.github.com/session'.quote
-    let command .= ' -d @' . quote.file.quote
-    call writefile([squery], file)
-    let res = system(command)
-    call delete(file)
-    let res = matchstr(split(res, '\(\r\?\n\|\r\n\?\)'), '^Location: ')
-    let res = substitute(res, '^[^:]\+: ', '', '')
-    if len(res) == 0
-      call delete(cookie_file)
-      return ''
-    endif
-  endif
-  let command = 'curl -s '.g:gist_curl_options.' -i '.a:opt
-  if len(a:param)
-    let command .= ' -d '.quote.a:param.quote
-  endif
-  let command .= ' -b '.quote.cookie_file.quote
-  let command .= ' '.quote.a:url.quote
-  let res = iconv(system(command), "utf-8", &encoding)
-  let pos = stridx(res, "\r\n\r\n")
-  if pos != -1
-    let content = res[pos+4:]
-  else
-    let pos = stridx(res, "\n\n")
-    let content = res[pos+2:]
-  endif
-  return {
-  \ "header" : split(res[0:pos], '\r\?\n'),
-  \ "content" : content
-  \}
-endfunction
-
-function! s:GistDelete(user, token, gistid)
-  echon 'Deleting gist... '
-  let res = s:GistGetPage('https://gist.github.com/'.a:gistid, a:user, '', '')
-  if (!len(res)) 
-      echohl ErrorMsg | echomsg 'Wrong password? no response received from github trying to delete ' . a:gistid | echohl None
-      return
-  endif
-  let mx = '^.* name="authenticity_token" type="hidden" value="\([^"]\+\)".*$'
-  let token = substitute(matchstr(res.content, mx), mx, '\1', '')
-  if len(token) > 0
-    let res = s:GistGetPage('https://gist.github.com/delete/'.a:gistid, a:user, '_method=delete&authenticity_token='.token, '')
-    if len(res.content) > 0
-      redraw
-      echo 'Done: '
-    else
-      let message = matchstr(res.header, '^Status: ')
-      let message = substitute(message, '^[^:]\+: [0-9]\+ ', '', '')
-      echohl ErrorMsg | echomsg 'Delete failed: '.message | echohl None
-    endif
-  else
-    echohl ErrorMsg | echomsg 'Delete failed' | echohl None
-  endif
-endfunction
-
-
-" GistPost function:
-"   Post new gist to github
-"
-"   if there is an embedded gist url or gist id in your file,
-"   it will just update it.
-"                                                   -- by c9s
-"
-"   embedded gist url format:
-"
-"       Gist: https://gist.github.com/123123
-"
-"   embedded gist id format:
-"
-"       GistID: 123123
-"
-function! s:GistPost(user, token, content, private)
-
-  " find GistID: in content, then we should just update
-  for l in split(a:content, "\n")
-    if l =~ '\ 0 && len(a:token) > 0
-    call add(query, 'login=%s')
-    call add(query, 'token=%s')
-  else
-    call add(query, '%.0s%.0s')
-  endif
-
-  if a:private
-    call add(query, 'action_button=private')
-  endif
-  let squery = printf(join(query, '&'),
-    \ s:encodeURIComponent(ext),
-    \ s:encodeURIComponent(name),
-    \ s:encodeURIComponent(a:content),
-    \ s:encodeURIComponent(a:user),
-    \ s:encodeURIComponent(a:token))
-  unlet query
-
-  let file = tempname()
-  call writefile([squery], file)
-  echon 'Posting it to gist... '
-  let quote = &shellxquote == '"' ?  "'" : '"'
-  let url = 'https://gist.github.com/gists'
-  let res = system('curl -i '.g:gist_curl_options.' -d @'.quote.file.quote.' '.url)
-  call delete(file)
-  let headers = split(res, '\(\r\?\n\|\r\n\?\)')
-  let location = matchstr(headers, '^Location: ')
-  let location = substitute(location, '^[^:]\+: ', '', '')
-  if len(location) > 0 && location =~ '^\(http\|https\):\/\/gist\.github\.com\/'
-    redraw
-    echo 'Done: '.location
-  else
-    let message = matchstr(headers, '^Status: ')
-    let message = substitute(message, '^[^:]\+: [0-9]\+ ', '', '')
-    echohl ErrorMsg | echomsg 'Post failed: '.message | echohl None
-  endif
-  return location
-endfunction
-
-function! s:GistPostBuffers(user, token, private)
-  let bufnrs = range(1, bufnr("$"))
-  let bn = bufnr('%')
-  let query = []
-  if len(a:user) > 0 && len(a:token) > 0
-    call add(query, 'login=%s')
-    call add(query, 'token=%s')
-  else
-    call add(query, '%.0s%.0s')
-  endif
-  if a:private
-    call add(query, 'action_button=private')
-  endif
-  let squery = printf(join(query, "&"),
-    \ s:encodeURIComponent(a:user),
-    \ s:encodeURIComponent(a:token)) . '&'
-
-  let query = [
-    \ 'file_ext[gistfile]=%s',
-    \ 'file_name[gistfile]=%s',
-    \ 'file_contents[gistfile]=%s',
-    \ ]
-  let format = join(query, "&") . '&'
-
-  let index = 1
-  for bufnr in bufnrs
-    if !bufexists(bufnr) || buflisted(bufnr) == 0
-      continue
-    endif
-    echo "Creating gist content".index."... "
-    silent! exec "buffer!" bufnr
-    let content = join(getline(1, line('$')), "\n")
-    let ext = expand('%:e')
-    let ext = len(ext) ? '.'.ext : ''
-    let name = expand('%:t')
-    let squery .= printf(substitute(format, 'gistfile', 'gistfile'.index, 'g'),
-      \ s:encodeURIComponent(ext),
-      \ s:encodeURIComponent(name),
-      \ s:encodeURIComponent(content))
-    let index = index + 1
-  endfor
-  silent! exec "buffer!" bn
-
-  let file = tempname()
-  call writefile([squery], file)
-  echo "Posting it to gist... "
-  let quote = &shellxquote == '"' ?  "'" : '"'
-  let url = 'https://gist.github.com/gists'
-  let res = system('curl -i '.g:gist_curl_options.' -d @'.quote.file.quote.' '.url)
-  call delete(file)
-  let res = matchstr(split(res, '\(\r\?\n\|\r\n\?\)'), '^Location: ')
-  let res = substitute(res, '^.*: ', '', '')
-  if len(res) > 0 && res =~ '^\(http\|https\):\/\/gist\.github\.com\/'
-    redraw
-    echo 'Done: '.res
-  else
-    echohl ErrorMsg | echomsg 'Post failed' | echohl None
-  endif
-  return res
-endfunction
-
-function! Gist(line1, line2, ...)
-  if !exists('g:github_user')
-    let g:github_user = substitute(system('git config --global github.user'), "\n", '', '')
-    if strlen(g:github_user) == 0
-      let g:github_user = $GITHUB_USER
-    end
-  endif
-  if !exists('g:github_token')
-    let g:github_token = substitute(system('git config --global github.token'), "\n", '', '')
-    if strlen(g:github_token) == 0
-      let g:github_token = $GITHUB_TOKEN
-    end
-  endif
-  if strlen(g:github_user) == 0 || strlen(g:github_token) == 0
-    echohl ErrorMsg
-    echomsg "You have no setting for github."
-    echohl WarningMsg
-    echo "git config --global github.user  your-name"
-    echo "git config --global github.token your-token"
-    echo "or set g:github_user and g:github_token in your vimrc"
-    echo "or set shell env vars GITHUB_USER and GITHUB_TOKEN"
-    echohl None
-    return 0
-  end
-
-  let bufname = bufname("%")
-  let user = g:github_user
-  let token = g:github_token
-  let gistid = ''
-  let gistls = ''
-  let gistnm = ''
-  let private = g:gist_private
-  let multibuffer = 0
-  let clipboard = 0
-  let deletepost = 0
-  let editpost = 0
-  let listmx = '^\(-l\|--list\)\s*\([^\s]\+\)\?$'
-  let bufnamemx = '^' . s:bufprefix .'\([0-9a-f]\+\)$'
-
-  let args = (a:0 > 0) ? split(a:1, ' ') : []
-  for arg in args
-    if arg =~ '^\(-la\|--listall\)$\C'
-      let gistls = '-all'
-    elseif arg =~ '^\(-l\|--list\)$\C'
-      if g:gist_show_privates
-        let gistls = 'mine'
-      else
-        let gistls = g:github_user
-      endif
-    elseif arg == '--abandon\C'
-      call s:GistGetPage('', '', '', '')
-      return
-    elseif arg =~ '^\(-m\|--multibuffer\)$\C'
-      let multibuffer = 1
-    elseif arg =~ '^\(-p\|--private\)$\C'
-      let private = 1
-    elseif arg =~ '^\(-P\|--public\)$\C'
-      let private = 0
-    elseif arg =~ '^\(-a\|--anonymous\)$\C'
-      let user = ''
-      let token = ''
-    elseif arg =~ '^\(-c\|--clipboard\)$\C'
-      let clipboard = 1
-    elseif arg =~ '^\(-d\|--delete\)$\C' && bufname =~ bufnamemx
-      let deletepost = 1
-      let gistid = substitute(bufname, bufnamemx, '\1', '')
-    elseif arg =~ '^\(-e\|--edit\)$\C' && bufname =~ bufnamemx
-      let editpost = 1
-      let gistid = substitute(bufname, bufnamemx, '\1', '')
-    elseif arg =~ '^\(-f\|--fork\)$\C' && bufname =~ bufnamemx
-      let gistid = substitute(bufname, bufnamemx, '\1', '')
-      let res = s:GistGetPage("https://gist.github.com/fork/".gistid, g:github_user, '', '')
-      let loc = filter(res.header, 'v:val =~ "^Location:"')[0]
-      let loc = substitute(loc, '^[^:]\+: ', '', '')
-      let mx = '^https://gist.github.com/\([0-9a-z]\+\)$'
-      if loc =~ mx
-        let gistid = substitute(loc, mx, '\1', '')
-      else
-        echohl ErrorMsg | echomsg 'Fork failed' | echohl None
-        return
-      endif
-    elseif arg !~ '^-' && len(gistnm) == 0
-      if editpost == 1 || deletepost == 1
-        let gistnm = arg
-      elseif len(gistls) > 0 && arg != '^\w\+$\C'
-        let gistls = arg
-      elseif arg =~ '^[0-9a-z]\+$\C'
-        let gistid = arg
-      else
-        echohl ErrorMsg | echomsg 'Invalid arguments' | echohl None
-        unlet args
-        return 0
-      endif
-    elseif len(arg) > 0
-      echohl ErrorMsg | echomsg 'Invalid arguments' | echohl None
-      unlet args
-      return 0
-    endif
-  endfor
-  unlet args
-  "echo "gistid=".gistid
-  "echo "gistls=".gistls
-  "echo "gistnm=".gistnm
-  "echo "private=".private
-  "echo "clipboard=".clipboard
-  "echo "editpost=".editpost
-  "echo "deletepost=".deletepost
-
-  if len(gistls) > 0
-    call s:GistList(user, token, gistls, 1)
-  elseif len(gistid) > 0 && editpost == 0 && deletepost == 0
-    call s:GistGet(user, token, gistid, clipboard)
-  else
-    let url = ''
-    if multibuffer == 1
-      let url = s:GistPostBuffers(user, token, private)
-    else
-      let content = join(getline(a:line1, a:line2), "\n")
-      if editpost == 1
-        let url = s:GistUpdate(user, token, content, gistid, gistnm)
-      elseif deletepost == 1
-        call s:GistDelete(user, token, gistid)
-      else
-        let url = s:GistPost(user, token, content, private)
-      endif
-    endif
-    if len(url) > 0
-      if g:gist_open_browser_after_post
-        let cmd = substitute(g:gist_browser_command, '%URL%', url, 'g')
-        if cmd =~ '^!'
-          silent! exec cmd
-        elseif cmd =~ '^:[A-Z]'
-          exec cmd
-        else
-          call system(cmd)
-        endif
-      endif
-      if g:gist_put_url_to_clipboard_after_post > 0
-        if g:gist_put_url_to_clipboard_after_post == 2
-          let url = url . "\n"
-        endif
-        if exists('g:gist_clip_command')
-          call system(g:gist_clip_command, url)
-        elseif has('unix') && !has('xterm_clipboard')
-          let @" = url
-        else
-          let @+ = url
-        endif
-      endif
-    endif
-  endif
-  return 1
-endfunction
-
-command! -nargs=? -range=% Gist :call Gist(, , )
-" vim:set et:
diff --git a/vim/plugin/indent-object.vim b/vim/plugin/indent-object.vim
deleted file mode 100644
index afb8edd..0000000
--- a/vim/plugin/indent-object.vim
+++ /dev/null
@@ -1,224 +0,0 @@
-"--------------------------------------------------------------------------------
-"
-"  Copyright (c) 2010 Michael Smith 
-"
-"  http://github.com/michaeljsmith/vim-indent-object
-"
-"  Permission is hereby granted, free of charge, to any person obtaining a copy
-"  of this software and associated documentation files (the "Software"), to
-"  deal in the Software without restriction, including without limitation the
-"  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-"  sell copies of the Software, and to permit persons to whom the Software is
-"  furnished to do so, subject to the following conditions:
-"  
-"  The above copyright notice and this permission notice shall be included in
-"  all copies or substantial portions of the Software.
-"  
-"  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-"  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-"  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-"  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-"  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-"  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-"  IN THE SOFTWARE.
-"
-"--------------------------------------------------------------------------------
-
-" Mappings excluding line below.
-onoremap ai :cal HandleTextObjectMapping(0, 0, 0, [line("."), line("."), col("."), col(".")])
-onoremap ii :cal HandleTextObjectMapping(1, 0, 0, [line("."), line("."), col("."), col(".")])
-vnoremap ai :cal HandleTextObjectMapping(0, 0, 1, [line("'<"), line("'>"), col("'<"), col("'>")])gv
-vnoremap ii :cal HandleTextObjectMapping(1, 0, 1, [line("'<"), line("'>"), col("'<"), col("'>")])gv
-
-" Mappings including line below.
-onoremap aI :cal HandleTextObjectMapping(0, 1, 0, [line("."), line("."), col("."), col(".")])
-onoremap iI :cal HandleTextObjectMapping(1, 1, 0, [line("."), line("."), col("."), col(".")])
-vnoremap aI :cal HandleTextObjectMapping(0, 1, 1, [line("'<"), line("'>"), col("'<"), col("'>")])gv
-vnoremap iI :cal HandleTextObjectMapping(1, 1, 1, [line("'<"), line("'>"), col("'<"), col("'>")])gv
-
-let s:l0 = -1
-let s:l1 = -1
-let s:c0 = -1
-let s:c1 = -1
-
-function! TextObject(inner, incbelow, vis, range, count)
-
-	" Record the current state of the visual region.
-	let vismode = "V"
-
-	" Detect if this is a completely new visual selction session.
-	let new_vis = 0
-	let new_vis = new_vis || s:l0 != a:range[0]
-	let new_vis = new_vis || s:l1 != a:range[1]
-	let new_vis = new_vis || s:c0 != a:range[2]
-	let new_vis = new_vis || s:c1 != a:range[3]
-
-	let s:l0 = a:range[0]
-	let s:l1 = a:range[1]
-	let s:c0 = a:range[2]
-	let s:c1 = a:range[3]
-
-	" Repeatedly increase the scope of the selection.
-	let itr_cnt = 0
-	let cnt = a:count
-	while cnt > 0
-
-		" Look for the minimum indentation in the current visual region.
-		let l = s:l0
-		let idnt_invalid = 1000
-		let idnt = idnt_invalid
-		while l <= s:l1
-			if !(getline(l) =~ "^\\s*$")
-				let idnt = min([idnt, indent(l)])
-			endif
-			let l += 1
-		endwhile
-
-		" Keep track of where the range should be expanded to.
-		let l_1 = s:l0
-		let l_1o = l_1
-		let l2 = s:l1
-		let l2o = l2
-
-		" If we are highlighting only blank lines, we may not have found a
-		" valid indent. In this case we need to look for the next and previous
-		" non blank lines and check which of those has the largest indent.
-		if idnt == idnt_invalid
-			let idnt = 0
-			let pnb = prevnonblank(s:l0)
-			if pnb
-				let idnt = max([idnt, indent(pnb)])
-				let l_1 = pnb
-			endif
-			let nnb = nextnonblank(s:l0)
-			if nnb
-				let idnt = max([idnt, indent(nnb)])
-			endif
-
-			" If we are in whitespace at the beginning of a block, skip over
-			" it when we are selecting the range. Similarly, if we are in
-			" whitespace at the end, ignore it.
-			if idnt > indent(pnb)
-				let l_1 = nnb
-			endif
-			if idnt > indent(nnb)
-				let l2 = pnb
-			endif
-		endif
-
-		" Search backward for the first line with less indent than the target
-		" indent (skipping blank lines).
-		let blnk = getline(l_1) =~ "^\\s*$"
-		while l_1 > 0 && ((idnt == 0 && !blnk) || (idnt != 0 && (blnk || indent(l_1) >= idnt)))
-			if !blnk || !a:inner
-				let l_1o = l_1
-			endif
-			let l_1 -= 1
-			let blnk = getline(l_1) =~ "^\\s*$"
-		endwhile
-
-		" Search forward for the first line with more indent than the target
-		" indent (skipping blank lines).
-		let line_cnt = line("$")
-		let blnk = getline(l2) =~ "^\\s*$"
-		while l2 <= line_cnt && ((idnt == 0 && !blnk) || (idnt != 0 && (blnk || indent(l2) >= idnt)))
-			if !blnk || !a:inner
-				let l2o = l2
-			endif
-			let l2 += 1
-			let blnk = getline(l2) =~ "^\\s*$"
-		endwhile
-
-		" Determine which of these extensions to include. Include neither if
-		" we are selecting an 'inner' object. Exclude the bottom unless are
-		" told to include it.
-		let idnt2 = max([indent(l_1), indent(l2)])
-		if indent(l_1) < idnt2 || a:inner
-			let l_1 = l_1o
-		endif
-		if indent(l2) < idnt2 || a:inner || !a:incbelow
-			let l2 = l2o
-		endif
-		let l_1 = max([l_1, 1])
-		let l2 = min([l2, line("$")])
-
-		" Extend the columns to the start and end.
-		" If inner is selected, set the final cursor pos to the start
-		" of the text in the line.
-		let c_1 = 1
-		if a:inner
-			let c_1 = match(getline(l_1), "\\c\\S") + 1
-		endif
-		let c2 = len(getline(l2))
-		if !a:inner
-			let c2 += 1
-		endif
-
-		" Make sure there's no change if we haven't really made a
-		" significant change in linewise mode - this makes sure that
-		" we can iteratively increase selection in linewise mode.
-		if itr_cnt == 0 && vismode ==# 'V' && s:l0 == l_1 && s:l1 == l2
-			let c_1 = s:c0
-			let c2 = s:c1
-		endif
-
-		" Check whether the visual region has changed.
-		let chg = 0
-		let chg = chg || s:l0 != l_1
-		let chg = chg || s:l1 != l2
-		let chg = chg || s:c0 != c_1
-		let chg = chg || s:c1 != c2
-
-		if vismode ==# 'V' && new_vis
-			let chg = 1
-		endif
-
-		" Update the vars.
-		let s:l0 = l_1
-		let s:l1 = l2
-		let s:c0 = c_1
-		let s:c1 = c2
-
-		" If there was no change, then don't decrement the count (it didn't
-		" count because it didn't do anything).
-		if chg
-			let cnt = cnt - 1
-		else
-			" Since this didn't work, push the selection back one char. This
-			" will have the effect of getting the enclosing block. Do it at
-			" the beginning rather than the end - the beginning is very likely
-			" to be only one indentation level different.
-			if s:l0 == 0
-				return
-			endif
-			let s:l0 -= 1
-			let s:c0 = len(getline(s:l0))
-		endif
-
-		let itr_cnt += 1
-
-	endwhile
-
-	" Apply the range we have found. Make sure to use the current visual mode.
-	call cursor(s:l0, s:c0)
-	exe "normal! " . vismode
-	call cursor(s:l1, s:c1)
-	normal! o
-
-	" Update these static variables - we need to keep these up-to-date between
-	" invocations because it's the only way we can detect whether it's a new
-	" visual mode. We need to know if it's a new visual mode because otherwise
-	" if there's a single line block in visual line mode and we select it with
-	" "V", we can't tell whether it's already been selected using Vii.
-	exe "normal! \"
-	let s:l0 = line("'<")
-	let s:l1 = line("'>")
-	let s:c0 = col("'<")
-	let s:c1 = col("'>")
-	normal gv
-
-endfunction
-
-function! HandleTextObjectMapping(inner, incbelow, vis, range)
-	call TextObject(a:inner, a:incbelow, a:vis, a:range, v:count1)
-endfunction
diff --git a/vim/plugin/rails.vim b/vim/plugin/rails.vim
deleted file mode 100644
index 2dd17f7..0000000
--- a/vim/plugin/rails.vim
+++ /dev/null
@@ -1,339 +0,0 @@
-" rails.vim - Detect a rails application
-" Author:       Tim Pope 
-" GetLatestVimScripts: 1567 1 :AutoInstall: rails.vim
-
-" Install this file as plugin/rails.vim.  See doc/rails.txt for details. (Grab
-" it from the URL above if you don't have it.)  To access it from Vim, see
-" :help add-local-help (hint: :helptags ~/.vim/doc) Afterwards, you should be
-" able to do :help rails
-
-if exists('g:loaded_rails') || &cp || v:version < 700
-  finish
-endif
-let g:loaded_rails = 1
-
-" Utility Functions {{{1
-
-function! s:error(str)
-  echohl ErrorMsg
-  echomsg a:str
-  echohl None
-  let v:errmsg = a:str
-endfunction
-
-function! s:autoload(...)
-  if !exists("g:autoloaded_rails") && v:version >= 700
-    runtime! autoload/rails.vim
-  endif
-  if exists("g:autoloaded_rails")
-    if a:0
-      exe a:1
-    endif
-    return 1
-  endif
-  if !exists("g:rails_no_autoload_warning")
-    let g:rails_no_autoload_warning = 1
-    if v:version >= 700
-      call s:error("Disabling rails.vim: autoload/rails.vim is missing")
-    else
-      call s:error("Disabling rails.vim: Vim version 7 or higher required")
-    endif
-  endif
-  return ""
-endfunction
-
-" }}}1
-" Configuration {{{
-
-function! s:SetOptDefault(opt,val)
-  if !exists("g:".a:opt)
-    let g:{a:opt} = a:val
-  endif
-endfunction
-
-call s:SetOptDefault("rails_statusline",1)
-call s:SetOptDefault("rails_syntax",1)
-call s:SetOptDefault("rails_mappings",1)
-call s:SetOptDefault("rails_abbreviations",1)
-call s:SetOptDefault("rails_ctags_arguments","--languages=-javascript")
-call s:SetOptDefault("rails_default_file","README")
-call s:SetOptDefault("rails_root_url",'http://localhost:3000/')
-call s:SetOptDefault("rails_modelines",0)
-call s:SetOptDefault("rails_menu",0)
-call s:SetOptDefault("rails_gnu_screen",1)
-call s:SetOptDefault("rails_history_size",5)
-call s:SetOptDefault("rails_generators","controller\ngenerator\nhelper\nintegration_test\nmailer\nmetal\nmigration\nmodel\nobserver\nperformance_test\nplugin\nresource\nscaffold\nscaffold_controller\nsession_migration\nstylesheets")
-if exists("g:loaded_dbext") && executable("sqlite3") && ! executable("sqlite")
-  " Since dbext can't find it by itself
-  call s:SetOptDefault("dbext_default_SQLITE_bin","sqlite3")
-endif
-
-" }}}1
-" Detection {{{1
-
-function! s:escvar(r)
-  let r = fnamemodify(a:r,':~')
-  let r = substitute(r,'\W','\="_".char2nr(submatch(0))."_"','g')
-  let r = substitute(r,'^\d','_&','')
-  return r
-endfunction
-
-function! s:Detect(filename)
-  let fn = substitute(fnamemodify(a:filename,":p"),'\c^file://','','')
-  let sep = matchstr(fn,'^[^\\/]\{3,\}\zs[\\/]')
-  if sep != ""
-    let fn = getcwd().sep.fn
-  endif
-  if fn =~ '[\/]config[\/]environment\.rb$'
-    return s:BufInit(strpart(fn,0,strlen(fn)-22))
-  endif
-  if isdirectory(fn)
-    let fn = fnamemodify(fn,':s?[\/]$??')
-  else
-    let fn = fnamemodify(fn,':s?\(.*\)[\/][^\/]*$?\1?')
-  endif
-  let ofn = ""
-  let nfn = fn
-  while nfn != ofn && nfn != ""
-    if exists("s:_".s:escvar(nfn))
-      return s:BufInit(nfn)
-    endif
-    let ofn = nfn
-    let nfn = fnamemodify(nfn,':h')
-  endwhile
-  let ofn = ""
-  while fn != ofn
-    if filereadable(fn . "/config/environment.rb")
-      return s:BufInit(fn)
-    endif
-    let ofn = fn
-    let fn = fnamemodify(ofn,':s?\(.*\)[\/]\(app\|config\|db\|doc\|features\|lib\|log\|public\|script\|spec\|stories\|test\|tmp\|vendor\)\($\|[\/].*$\)?\1?')
-  endwhile
-  return 0
-endfunction
-
-function! s:BufInit(path)
-  let s:_{s:escvar(a:path)} = 1
-  if s:autoload()
-    return RailsBufInit(a:path)
-  endif
-endfunction
-
-" }}}1
-" Initialization {{{1
-
-augroup railsPluginDetect
-  autocmd!
-  autocmd BufNewFile,BufRead * call s:Detect(expand(":p"))
-  autocmd VimEnter * if expand("") == "" && !exists("b:rails_root") | call s:Detect(getcwd()) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
-  autocmd FileType netrw if !exists("b:rails_root") | call s:Detect(expand(":p")) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
-  autocmd BufEnter * if exists("b:rails_root")|silent doau User BufEnterRails|endif
-  autocmd BufLeave * if exists("b:rails_root")|silent doau User BufLeaveRails|endif
-  autocmd Syntax railslog if s:autoload()|call rails#log_syntax()|endif
-augroup END
-
-command! -bar -bang -nargs=* -complete=dir Rails :if s:autoload()|call rails#new_app_command(0,)|endif
-
-" }}}1
-" abolish.vim support {{{1
-
-function! s:function(name)
-    return function(substitute(a:name,'^s:',matchstr(expand(''), '\d\+_'),''))
-endfunction
-
-augroup railsPluginAbolish
-  autocmd!
-  autocmd VimEnter * call s:abolish_setup()
-augroup END
-
-function! s:abolish_setup()
-  if exists('g:Abolish') && has_key(g:Abolish,'Coercions')
-    if !has_key(g:Abolish.Coercions,'l')
-      let g:Abolish.Coercions.l = s:function('s:abolish_l')
-    endif
-    if !has_key(g:Abolish.Coercions,'t')
-      let g:Abolish.Coercions.t = s:function('s:abolish_t')
-    endif
-  endif
-endfunction
-
-function! s:abolish_l(word)
-  let singular = rails#singularize(a:word)
-  return a:word ==? singular ? rails#pluralize(a:word) : singular
-endfunction
-
-function! s:abolish_t(word)
-  if a:word =~# '\u'
-    return rails#pluralize(rails#underscore(a:word))
-  else
-    return rails#singularize(rails#camelize(a:word))
-  endif
-endfunction
-
-" }}}1
-" Menus {{{1
-
-if !(g:rails_menu && has("menu"))
-  finish
-endif
-
-function! s:sub(str,pat,rep)
-  return substitute(a:str,'\v\C'.a:pat,a:rep,'')
-endfunction
-
-function! s:gsub(str,pat,rep)
-  return substitute(a:str,'\v\C'.a:pat,a:rep,'g')
-endfunction
-
-function! s:menucmd(priority)
-  return 'anoremenu