/bundle/vim-indentLine/after/plugin/indentLine.vim

https://github.com/iverson4664/vim_plugins · Vim Script · 178 lines · 134 code · 30 blank · 14 comment · 27 complexity · ad42b3d0baf37894c5e0a654b19baba7 MD5 · raw file

  1. " Script Name: indentLine.vim
  2. " Author: Yggdroot <archofortune@gmail.com>
  3. "
  4. " Description: To show the indention levels with thin vertical lines
  5. scriptencoding utf-8
  6. if ! has("conceal") || exists("g:indentLine_loaded")
  7. finish
  8. endif
  9. let g:indentLine_loaded = 1
  10. let g:indentLine_char = get(g:,'indentLine_char',(&encoding is# "utf-8" && &term isnot# "linux" ? 'ÂŚ' : '|'))
  11. let g:indentLine_first_char = get(g:,'indentLine_first_char',(&encoding is# "utf-8" && &term isnot# "linux" ? 'ÂŚ' : '|'))
  12. let g:indentLine_indentLevel = get(g:,'indentLine_indentLevel',10)
  13. let g:indentLine_enabled = get(g:,'indentLine_enabled',1)
  14. let g:indentLine_fileType = get(g:,'indentLine_fileType',[])
  15. let g:indentLine_fileTypeExclude = get(g:,'indentLine_fileTypeExclude',[])
  16. let g:indentLine_bufNameExclude = get(g:,'indentLine_bufNameExclude',[])
  17. let g:indentLine_showFirstIndentLevel = get(g:,'indentLine_showFirstIndentLevel',0)
  18. let g:indentLine_maxLines = get(g:,'indentLine_maxLines',3000)
  19. let g:indentLine_setColors = get(g:,'indentLine_setColors',1)
  20. let g:indentLine_faster = get(g:,'indentLine_faster',0)
  21. "{{{1 function! s:InitColor()
  22. function! s:InitColor()
  23. if ! g:indentLine_setColors
  24. return
  25. endif
  26. if ! exists("g:indentLine_color_term")
  27. if &background is# "light"
  28. let term_color = 249
  29. else
  30. let term_color = 239
  31. endif
  32. else
  33. let term_color = g:indentLine_color_term
  34. endif
  35. if ! exists("g:indentLine_color_gui")
  36. if &background is# "light"
  37. let gui_color = "Grey70"
  38. else
  39. let gui_color = "Grey30"
  40. endif
  41. else
  42. let gui_color = g:indentLine_color_gui
  43. endif
  44. execute "highlight Conceal ctermfg=" . term_color . " ctermbg=NONE"
  45. execute "highlight Conceal guifg=" . gui_color . " guibg=NONE"
  46. if &term is# "linux"
  47. if &background is# "light"
  48. let tty_color = exists("g:indentLine_color_tty_light") ? g:indentLine_color_tty_light : 4
  49. else
  50. let tty_color = exists("g:indentLine_color_tty_dark") ? g:indentLine_color_tty_dark : 2
  51. endif
  52. execute "highlight Conceal cterm=bold ctermfg=" . tty_color . " ctermbg=NONE"
  53. endif
  54. endfunction
  55. "{{{1 function! s:SetIndentLine()
  56. function! s:SetIndentLine()
  57. let b:indentLine_enabled = 1
  58. let space = &l:shiftwidth is 0 ? &l:tabstop : &l:shiftwidth
  59. if g:indentLine_showFirstIndentLevel
  60. execute 'syntax match IndentLine /^ / containedin=ALL conceal cchar=' . g:indentLine_first_char
  61. endif
  62. if g:indentLine_faster
  63. execute 'syntax match IndentLineSpace /^\s\+/ containedin=ALL contains=IndentLine'
  64. execute 'syntax match IndentLine / \{'.(space-1).'}\zs / contained conceal cchar=' . g:indentLine_char
  65. execute 'syntax match IndentLine /\t\zs / contained conceal cchar=' . g:indentLine_char
  66. else
  67. let pattern = line('$') < g:indentLine_maxLines ? 'v' : 'c'
  68. for i in range(space+1, space * g:indentLine_indentLevel + 1, space)
  69. execute 'syntax match IndentLine /\%(^\s\+\)\@<=\%'.i.pattern.' / containedin=ALL conceal cchar=' . g:indentLine_char
  70. endfor
  71. endif
  72. endfunction
  73. "{{{1 function! s:ResetWidth(...)
  74. function! s:ResetWidth(...)
  75. if 0 < a:0
  76. let &l:shiftwidth = a:1
  77. endif
  78. if exists("b:indentLine_enabled")
  79. syntax clear IndentLine
  80. endif
  81. call s:SetIndentLine()
  82. endfunction
  83. "{{{1 function! s:IndentLinesEnable()
  84. function! s:IndentLinesEnable()
  85. call s:SetIndentLine()
  86. endfunction
  87. "{{{1 function! s:IndentLinesDisable()
  88. function! s:IndentLinesDisable()
  89. let b:indentLine_enabled = 0
  90. syntax clear IndentLine
  91. endfunction
  92. "{{{1 function! s:IndentLinesToggle()
  93. function! s:IndentLinesToggle()
  94. if ! exists("b:indentLine_enabled")
  95. let b:indentLine_enabled = 0
  96. endif
  97. if b:indentLine_enabled
  98. call s:IndentLinesDisable()
  99. else
  100. call s:IndentLinesEnable()
  101. endif
  102. endfunction
  103. "{{{1 function! s:Setup()
  104. function! s:Setup()
  105. if index(g:indentLine_fileTypeExclude, &filetype) isnot -1
  106. return
  107. endif
  108. if len(g:indentLine_fileType) isnot 0 && index(g:indentLine_fileType, &filetype) is -1
  109. return
  110. end
  111. for name in g:indentLine_bufNameExclude
  112. if matchstr(bufname(''), name) is bufname('')
  113. return
  114. endif
  115. endfor
  116. if ! exists("b:indentLine_bufNr")
  117. let b:indentLine_bufNr = bufnr('%')
  118. let g:indentLine_bufNr = bufnr('%')
  119. elseif g:indentLine_bufNr != bufnr('%') && &hidden
  120. let g:indentLine_bufNr = bufnr('%')
  121. return
  122. endif
  123. if ! exists("g:indentLine_noConcealCursor")
  124. setlocal concealcursor=inc
  125. endif
  126. setlocal conceallevel=2
  127. if &filetype is# ""
  128. call s:InitColor()
  129. endif
  130. if ! exists("b:indentLine_enabled")
  131. let b:indentLine_enabled = g:indentLine_enabled
  132. endif
  133. if b:indentLine_enabled
  134. call s:SetIndentLine()
  135. endif
  136. endfunction
  137. "{{{1 augroup indentLine
  138. augroup indentLine
  139. autocmd!
  140. autocmd BufWinEnter * call <SID>Setup()
  141. autocmd BufRead,BufNewFile,ColorScheme,Syntax * call <SID>InitColor()
  142. augroup END
  143. "{{{1 commands
  144. command! -nargs=? IndentLinesReset call <SID>ResetWidth(<f-args>)
  145. command! IndentLinesToggle call <SID>IndentLinesToggle()
  146. command! IndentLinesEnable call <SID>IndentLinesEnable()
  147. command! IndentLinesDisable call <SID>IndentLinesDisable()
  148. " vim:et:ts=4:sw=4:fdm=marker:fmr={{{,}}}