-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathindent_guides.vim
90 lines (75 loc) · 2.98 KB
/
indent_guides.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
" Author: Nate Kane <nathanaelkane AT gmail DOT com>
" Homepage: http://github.com/preservim/vim-indent-guides
" Do not load if vim is too old
if (v:version == 701 && !exists('*matchadd')) || (v:version < 701)
finish
endif
if exists('g:loaded_indent_guides') || &cp
finish
endif
let g:loaded_indent_guides = 1
call indent_guides#define_default_highlights()
function! s:IndentGuidesToggle()
call indent_guides#toggle()
endfunction
function! s:IndentGuidesEnable()
call indent_guides#enable()
endfunction
function! s:IndentGuidesDisable()
call indent_guides#disable()
endfunction
" Commands
command! -bar IndentGuidesToggle call s:IndentGuidesToggle()
command! -bar IndentGuidesEnable call s:IndentGuidesEnable()
command! -bar IndentGuidesDisable call s:IndentGuidesDisable()
"
" Initializes a given variable to a given value. The variable is only
" initialized if it does not exist prior.
"
function s:InitVariable(var, value)
if !exists(a:var)
if type(a:value) == type('')
exec 'let ' . a:var . ' = ' . "'" . a:value . "'"
else
exec 'let ' . a:var . ' = ' . a:value
endif
endif
endfunction
" Fixed global variables
let g:indent_guides_color_hex_pattern = '#[0-9A-Fa-f]\{6\}'
let g:indent_guides_color_hex_guibg_pattern = 'guibg=\zs' . g:indent_guides_color_hex_pattern . '\ze'
let g:indent_guides_color_name_guibg_pattern = "guibg='\\?\\zs[0-9A-Za-z ]\\+\\ze'\\?"
" Configurable global variables
call s:InitVariable('g:indent_guides_indent_levels', 30)
call s:InitVariable('g:indent_guides_auto_colors', 1)
call s:InitVariable('g:indent_guides_color_change_percent', 10) " ie. 10%
call s:InitVariable('g:indent_guides_guide_size', 0)
call s:InitVariable('g:indent_guides_start_level', 1)
call s:InitVariable('g:indent_guides_enable_on_vim_startup', 0)
call s:InitVariable('g:indent_guides_debug', 0)
call s:InitVariable('g:indent_guides_space_guides', 1)
call s:InitVariable('g:indent_guides_tab_guides', 1)
call s:InitVariable('g:indent_guides_soft_pattern', '\s')
call s:InitVariable('g:indent_guides_default_mapping', 1)
if !exists('g:indent_guides_exclude_filetypes')
let g:indent_guides_exclude_filetypes = ['help']
endif
" Default mapping
if !hasmapto('<Plug>IndentGuidesToggle', 'n') && maparg('<Leader>ig', 'n') ==# ''
\ && g:indent_guides_default_mapping != 0
nmap <silent><unique> <Leader>ig <Plug>IndentGuidesToggle
endif
" Plug mappings
nnoremap <unique><script> <Plug>IndentGuidesToggle :IndentGuidesToggle<CR>
nnoremap <unique><script> <Plug>IndentGuidesEnable :IndentGuidesEnable<CR>
nnoremap <unique><script> <Plug>IndentGuidesDisable :IndentGuidesDisable<CR>
" Auto commands
augroup indent_guides
autocmd!
autocmd BufEnter,WinEnter,FileType * call indent_guides#process_autocmds()
if (v:version == 704 && has('patch786')) || (v:version > 704)
autocmd OptionSet tabstop,shiftwidth,expandtab call indent_guides#process_autocmds()
endif
" Trigger BufEnter and process modelines.
autocmd ColorScheme * doautocmd indent_guides BufEnter
augroup END