The ultimate Vim configuration: vimrc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

347 lines
12 KiB

10 years ago
7 years ago
10 years ago
10 years ago
7 years ago
10 years ago
7 years ago
7 years ago
7 years ago
10 years ago
7 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
7 years ago
10 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
10 years ago
10 years ago
10 years ago
7 years ago
10 years ago
7 years ago
10 years ago
10 years ago
7 years ago
10 years ago
7 years ago
  1. " pathogen.vim - path option manipulation
  2. " Maintainer: Tim Pope <http://tpo.pe/>
  3. " Version: 2.3
  4. " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
  5. "
  6. " For management of individually installed plugins in ~/.vim/bundle (or
  7. " ~\vimfiles\bundle), adding `execute pathogen#infect()` to the top of your
  8. " .vimrc is the only other setup necessary.
  9. "
  10. " The API is documented inline below.
  11. if exists("g:loaded_pathogen") || &cp
  12. finish
  13. endif
  14. let g:loaded_pathogen = 1
  15. " Point of entry for basic default usage. Give a relative path to invoke
  16. " pathogen#interpose() (defaults to "bundle/{}"), or an absolute path to invoke
  17. " pathogen#surround(). Curly braces are expanded with pathogen#expand():
  18. " "bundle/{}" finds all subdirectories inside "bundle" inside all directories
  19. " in the runtime path.
  20. function! pathogen#infect(...) abort
  21. for path in a:0 ? filter(reverse(copy(a:000)), 'type(v:val) == type("")') : ['bundle/{}']
  22. if path =~# '^\%({\=[$~\\/]\|{\=\w:[\\/]\).*[{}*]'
  23. call pathogen#surround(path)
  24. elseif path =~# '^\%([$~\\/]\|\w:[\\/]\)'
  25. call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
  26. call pathogen#surround(path . '/{}')
  27. elseif path =~# '[{}*]'
  28. call pathogen#interpose(path)
  29. else
  30. call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
  31. call pathogen#interpose(path . '/{}')
  32. endif
  33. endfor
  34. call pathogen#cycle_filetype()
  35. if pathogen#is_disabled($MYVIMRC)
  36. return 'finish'
  37. endif
  38. return ''
  39. endfunction
  40. " Split a path into a list.
  41. function! pathogen#split(path) abort
  42. if type(a:path) == type([]) | return a:path | endif
  43. if empty(a:path) | return [] | endif
  44. let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
  45. return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
  46. endfunction
  47. " Convert a list to a path.
  48. function! pathogen#join(...) abort
  49. if type(a:1) == type(1) && a:1
  50. let i = 1
  51. let space = ' '
  52. else
  53. let i = 0
  54. let space = ''
  55. endif
  56. let path = ""
  57. while i < a:0
  58. if type(a:000[i]) == type([])
  59. let list = a:000[i]
  60. let j = 0
  61. while j < len(list)
  62. let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
  63. let path .= ',' . escaped
  64. let j += 1
  65. endwhile
  66. else
  67. let path .= "," . a:000[i]
  68. endif
  69. let i += 1
  70. endwhile
  71. return substitute(path,'^,','','')
  72. endfunction
  73. " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
  74. function! pathogen#legacyjoin(...) abort
  75. return call('pathogen#join',[1] + a:000)
  76. endfunction
  77. " Turn filetype detection off and back on again if it was already enabled.
  78. function! pathogen#cycle_filetype() abort
  79. if exists('g:did_load_filetypes')
  80. filetype off
  81. filetype on
  82. endif
  83. endfunction
  84. " Check if a bundle is disabled. A bundle is considered disabled if its
  85. " basename or full name is included in the list g:pathogen_disabled.
  86. function! pathogen#is_disabled(path) abort
  87. if a:path =~# '\~$'
  88. return 1
  89. endif
  90. let sep = pathogen#slash()
  91. let blacklist = map(
  92. \ get(g:, 'pathogen_blacklist', get(g:, 'pathogen_disabled', [])) +
  93. \ pathogen#split($VIMBLACKLIST),
  94. \ 'substitute(v:val, "[\\/]$", "", "")')
  95. return index(blacklist, fnamemodify(a:path, ':t')) != -1 || index(blacklist, a:path) != -1
  96. endfunction "}}}1
  97. " Prepend the given directory to the runtime path and append its corresponding
  98. " after directory. Curly braces are expanded with pathogen#expand().
  99. function! pathogen#surround(path) abort
  100. let sep = pathogen#slash()
  101. let rtp = pathogen#split(&rtp)
  102. let path = fnamemodify(a:path, ':p:?[\\/]\=$??')
  103. let before = filter(pathogen#expand(path), '!pathogen#is_disabled(v:val)')
  104. let after = filter(reverse(pathogen#expand(path.sep.'after')), '!pathogen#is_disabled(v:val[0:-7])')
  105. call filter(rtp, 'index(before + after, v:val) == -1')
  106. let &rtp = pathogen#join(before, rtp, after)
  107. return &rtp
  108. endfunction
  109. " For each directory in the runtime path, add a second entry with the given
  110. " argument appended. Curly braces are expanded with pathogen#expand().
  111. function! pathogen#interpose(name) abort
  112. let sep = pathogen#slash()
  113. let name = a:name
  114. if has_key(s:done_bundles, name)
  115. return ""
  116. endif
  117. let s:done_bundles[name] = 1
  118. let list = []
  119. for dir in pathogen#split(&rtp)
  120. if dir =~# '\<after$'
  121. let list += reverse(filter(pathogen#expand(dir[0:-6].name.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])')) + [dir]
  122. else
  123. let list += [dir] + filter(pathogen#expand(dir.sep.name), '!pathogen#is_disabled(v:val)')
  124. endif
  125. endfor
  126. let &rtp = pathogen#join(pathogen#uniq(list))
  127. return 1
  128. endfunction
  129. let s:done_bundles = {}
  130. " Invoke :helptags on all non-$VIM doc directories in runtimepath.
  131. function! pathogen#helptags() abort
  132. let sep = pathogen#slash()
  133. for glob in pathogen#split(&rtp)
  134. for dir in map(split(glob(glob), "\n"), 'v:val.sep."/doc/".sep')
  135. if (dir)[0 : strlen($VIMRUNTIME)] !=# $VIMRUNTIME.sep && filewritable(dir) == 2 && !empty(split(glob(dir.'*.txt'))) && (!filereadable(dir.'tags') || filewritable(dir.'tags'))
  136. silent! execute 'helptags' pathogen#fnameescape(dir)
  137. endif
  138. endfor
  139. endfor
  140. endfunction
  141. command! -bar Helptags :call pathogen#helptags()
  142. " Execute the given command. This is basically a backdoor for --remote-expr.
  143. function! pathogen#execute(...) abort
  144. for command in a:000
  145. execute command
  146. endfor
  147. return ''
  148. endfunction
  149. " Section: Unofficial
  150. function! pathogen#is_absolute(path) abort
  151. return a:path =~# (has('win32') ? '^\%([\\/]\|\w:\)[\\/]\|^[~$]' : '^[/~$]')
  152. endfunction
  153. " Given a string, returns all possible permutations of comma delimited braced
  154. " alternatives of that string. pathogen#expand('/{a,b}/{c,d}') yields
  155. " ['/a/c', '/a/d', '/b/c', '/b/d']. Empty braces are treated as a wildcard
  156. " and globbed. Actual globs are preserved.
  157. function! pathogen#expand(pattern) abort
  158. if a:pattern =~# '{[^{}]\+}'
  159. let [pre, pat, post] = split(substitute(a:pattern, '\(.\{-\}\){\([^{}]\+\)}\(.*\)', "\\1\001\\2\001\\3", ''), "\001", 1)
  160. let found = map(split(pat, ',', 1), 'pre.v:val.post')
  161. let results = []
  162. for pattern in found
  163. call extend(results, pathogen#expand(pattern))
  164. endfor
  165. return results
  166. elseif a:pattern =~# '{}'
  167. let pat = matchstr(a:pattern, '^.*{}[^*]*\%($\|[\\/]\)')
  168. let post = a:pattern[strlen(pat) : -1]
  169. return map(split(glob(substitute(pat, '{}', '*', 'g')), "\n"), 'v:val.post')
  170. else
  171. return [a:pattern]
  172. endif
  173. endfunction
  174. " \ on Windows unless shellslash is set, / everywhere else.
  175. function! pathogen#slash() abort
  176. return !exists("+shellslash") || &shellslash ? '/' : '\'
  177. endfunction
  178. function! pathogen#separator() abort
  179. return pathogen#slash()
  180. endfunction
  181. " Convenience wrapper around glob() which returns a list.
  182. function! pathogen#glob(pattern) abort
  183. let files = split(glob(a:pattern),"\n")
  184. return map(files,'substitute(v:val,"[".pathogen#slash()."/]$","","")')
  185. endfunction "}}}1
  186. " Like pathogen#glob(), only limit the results to directories.
  187. function! pathogen#glob_directories(pattern) abort
  188. return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
  189. endfunction "}}}1
  190. " Remove duplicates from a list.
  191. function! pathogen#uniq(list) abort
  192. let i = 0
  193. let seen = {}
  194. while i < len(a:list)
  195. if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
  196. call remove(a:list,i)
  197. elseif a:list[i] ==# ''
  198. let i += 1
  199. let empty = 1
  200. else
  201. let seen[a:list[i]] = 1
  202. let i += 1
  203. endif
  204. endwhile
  205. return a:list
  206. endfunction
  207. " Backport of fnameescape().
  208. function! pathogen#fnameescape(string) abort
  209. if exists('*fnameescape')
  210. return fnameescape(a:string)
  211. elseif a:string ==# '-'
  212. return '\-'
  213. else
  214. return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
  215. endif
  216. endfunction
  217. " Like findfile(), but hardcoded to use the runtimepath.
  218. function! pathogen#runtime_findfile(file,count) abort "{{{1
  219. let rtp = pathogen#join(1,pathogen#split(&rtp))
  220. let file = findfile(a:file,rtp,a:count)
  221. if file ==# ''
  222. return ''
  223. else
  224. return fnamemodify(file,':p')
  225. endif
  226. endfunction
  227. " Section: Deprecated
  228. function! s:warn(msg) abort
  229. echohl WarningMsg
  230. echomsg a:msg
  231. echohl NONE
  232. endfunction
  233. " Prepend all subdirectories of path to the rtp, and append all 'after'
  234. " directories in those subdirectories. Deprecated.
  235. function! pathogen#runtime_prepend_subdirectories(path) abort
  236. call s:warn('Change pathogen#runtime_prepend_subdirectories('.string(a:path).') to pathogen#infect('.string(a:path.'/{}').')')
  237. return pathogen#surround(a:path . pathogen#slash() . '{}')
  238. endfunction
  239. function! pathogen#incubate(...) abort
  240. let name = a:0 ? a:1 : 'bundle/{}'
  241. call s:warn('Change pathogen#incubate('.(a:0 ? string(a:1) : '').') to pathogen#infect('.string(name).')')
  242. return pathogen#interpose(name)
  243. endfunction
  244. " Deprecated alias for pathogen#interpose().
  245. function! pathogen#runtime_append_all_bundles(...) abort
  246. if a:0
  247. call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#infect('.string(a:1.'/{}').')')
  248. else
  249. call s:warn('Change pathogen#runtime_append_all_bundles() to pathogen#infect()')
  250. endif
  251. return pathogen#interpose(a:0 ? a:1 . '/{}' : 'bundle/{}')
  252. endfunction
  253. if exists(':Vedit')
  254. finish
  255. endif
  256. let s:vopen_warning = 0
  257. function! s:find(count,cmd,file,lcd)
  258. let rtp = pathogen#join(1,pathogen#split(&runtimepath))
  259. let file = pathogen#runtime_findfile(a:file,a:count)
  260. if file ==# ''
  261. return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
  262. endif
  263. if !s:vopen_warning
  264. let s:vopen_warning = 1
  265. let warning = '|echohl WarningMsg|echo "Install scriptease.vim to continue using :V'.a:cmd.'"|echohl NONE'
  266. else
  267. let warning = ''
  268. endif
  269. if a:lcd
  270. let path = file[0:-strlen(a:file)-2]
  271. execute 'lcd `=path`'
  272. return a:cmd.' '.pathogen#fnameescape(a:file) . warning
  273. else
  274. return a:cmd.' '.pathogen#fnameescape(file) . warning
  275. endif
  276. endfunction
  277. function! s:Findcomplete(A,L,P)
  278. let sep = pathogen#slash()
  279. let cheats = {
  280. \'a': 'autoload',
  281. \'d': 'doc',
  282. \'f': 'ftplugin',
  283. \'i': 'indent',
  284. \'p': 'plugin',
  285. \'s': 'syntax'}
  286. if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0])
  287. let request = cheats[a:A[0]].a:A[1:-1]
  288. else
  289. let request = a:A
  290. endif
  291. let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*'
  292. let found = {}
  293. for path in pathogen#split(&runtimepath)
  294. let path = expand(path, ':p')
  295. let matches = split(glob(path.sep.pattern),"\n")
  296. call map(matches,'isdirectory(v:val) ? v:val.sep : v:val')
  297. call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]')
  298. for match in matches
  299. let found[match] = 1
  300. endfor
  301. endfor
  302. return sort(keys(found))
  303. endfunction
  304. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0)
  305. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0)
  306. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1)
  307. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1)
  308. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1)
  309. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1)
  310. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1)
  311. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1)
  312. " vim:set et sw=2 foldmethod=expr foldexpr=getline(v\:lnum)=~'^\"\ Section\:'?'>1'\:getline(v\:lnum)=~#'^fu'?'a1'\:getline(v\:lnum)=~#'^endf'?'s1'\:'=':