mirror of
https://github.com/preservim/vim-indent-guides.git
synced 2025-11-15 13:13:48 -05:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62a2fd103f | ||
|
|
7826042406 | ||
|
|
6e145a10cf | ||
|
|
60f435ee57 | ||
|
|
5f48d29177 | ||
|
|
a3ba000ddb | ||
|
|
d9c596352a | ||
|
|
7af506c797 | ||
|
|
73703c93ad | ||
|
|
78d34d1018 | ||
|
|
f7d5111c34 | ||
|
|
0a14a1558e | ||
|
|
ed8eff420b | ||
|
|
5146db837f | ||
|
|
feba7e9fa7 | ||
|
|
2415d8b709 | ||
|
|
fa67d46aca | ||
|
|
f972f0264f | ||
|
|
3cd1b09fb3 | ||
|
|
9441c97e57 | ||
|
|
10b809d187 | ||
|
|
4a3c2d3d46 | ||
|
|
353bef3dba | ||
|
|
3c86647883 |
@@ -7,8 +7,9 @@ Indent Guides is a plugin for visually displaying indent levels in Vim.
|
||||
* Will highlight indent levels with alternating colors.
|
||||
* Full support for gVim and basic support for Terminal Vim.
|
||||
* Seems to work on Windows gVim 7.3 (haven't done any extensive tests though).
|
||||
* **NEW:** Customizable size for indent guides, eg. skinny guides (soft-tabs only).
|
||||
* **NEW:** Customizable start indent level.
|
||||
* Customizable size for indent guides, eg. skinny guides (soft-tabs only).
|
||||
* Customizable start indent level.
|
||||
* **NEW:** Highlight support for files with a mixture of tab and space indent styles.
|
||||
|
||||
## Requirements
|
||||
* Vim 7.2+
|
||||
@@ -34,18 +35,23 @@ Here's an example of how to define custom colors instead of using the ones the p
|
||||
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=3
|
||||
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=4
|
||||
|
||||
Alternatively you can add the following lines to your colorscheme file.
|
||||
|
||||
hi IndentGuidesOdd guibg=red ctermbg=3
|
||||
hi IndentGuidesEven guibg=green ctermbg=4
|
||||
|
||||
### Terminal Vim
|
||||
At the moment Terminal Vim only has basic support. This means is that colors won't be automatically calculated based on your colorscheme. Instead, some preset colors are used depending on whether `background` is set to `dark` or `light`.
|
||||
|
||||
When `set background=dark` is used, the following highlight colors will be defined:
|
||||
|
||||
hi IndentGuidesEven ctermbg=darkgrey
|
||||
hi IndentGuidesOdd ctermbg=black
|
||||
hi IndentGuidesEven ctermbg=darkgrey
|
||||
|
||||
Alternatively, when `set background=light` is used, the following highlight colors will be defined:
|
||||
|
||||
hi IndentGuidesEven ctermbg=lightgrey
|
||||
hi IndentGuidesOdd ctermbg=white
|
||||
hi IndentGuidesEven ctermbg=lightgrey
|
||||
|
||||
If for some reason it's incorrectly defining light highlight colors instead of dark ones or vice versa, the first thing you should check is that the `background` value is being set correctly for your colorscheme. Sometimes it's best to manually set the `background` value in your `.vimrc`, for example:
|
||||
|
||||
@@ -62,4 +68,3 @@ Alternatively you can manually setup the highlight colors yourself, see `:help i
|
||||
<img src="http://i.imgur.com/7tMBl.png" width="448" height="448" alt="" />
|
||||
<img src="http://i.imgur.com/EvrqK.png" width="448" height="448" alt="" />
|
||||
<img src="http://i.imgur.com/hHqp2.png" width="448" height="448" alt="" />
|
||||
|
||||
|
||||
@@ -877,4 +877,3 @@ function! color_helper#color_name_to_hex(color_name)
|
||||
|
||||
return l:hex_code
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -40,13 +40,14 @@ function! indent_guides#enable()
|
||||
" loop through each indent level and define a highlight pattern
|
||||
" will automagically figure out whether to use tabs or spaces
|
||||
for l:level in range(s:start_level, s:indent_levels)
|
||||
let l:group = 'IndentGuides' . ((l:level % 2 == 0) ? 'Even' : 'Odd')
|
||||
let l:pattern = '^\s\{' . (l:level * s:indent_size - s:indent_size) . '\}\zs'
|
||||
let l:pattern .= '\s\{' . s:guide_size . '\}'
|
||||
let l:pattern .= '\ze'
|
||||
let l:group = 'IndentGuides' . ((l:level % 2 == 0) ? 'Even' : 'Odd')
|
||||
let l:column_start = (l:level - 1) * s:indent_size + 1
|
||||
let l:soft_pattern = indent_guides#indent_highlight_pattern('\s', l:column_start, s:guide_size)
|
||||
let l:hard_pattern = indent_guides#indent_highlight_pattern('\t', l:column_start, s:indent_size)
|
||||
|
||||
" define the higlight pattern and add to list
|
||||
call add(w:indent_guides_matches, matchadd(l:group, l:pattern))
|
||||
" define the higlight patterns and add to matches list
|
||||
call add(w:indent_guides_matches, matchadd(l:group, l:soft_pattern))
|
||||
call add(w:indent_guides_matches, matchadd(l:group, l:hard_pattern))
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
@@ -152,8 +153,8 @@ endfunction
|
||||
" Define default highlights.
|
||||
"
|
||||
function! indent_guides#define_default_highlights()
|
||||
exe 'hi IndentGuidesOdd guibg=NONE ctermbg=NONE'
|
||||
exe 'hi IndentGuidesEven guibg=NONE ctermbg=NONE'
|
||||
hi default clear IndentGuidesOdd
|
||||
hi default clear IndentGuidesEven
|
||||
endfunction
|
||||
|
||||
"
|
||||
@@ -168,15 +169,18 @@ endfunction
|
||||
" plugin is enabled.
|
||||
"
|
||||
function! indent_guides#init_script_vars()
|
||||
let s:indent_size = indent_guides#get_indent_size()
|
||||
let s:indent_size = &l:shiftwidth
|
||||
let s:guide_size = indent_guides#calculate_guide_size()
|
||||
let s:hi_normal = indent_guides#capture_highlight('Normal')
|
||||
|
||||
" remove 'font=<value>' from the s:hi_normal string (only seems to happen on Vim startup in Windows)
|
||||
let s:hi_normal = substitute(s:hi_normal, ' font=[A-Za-z0-9:]\+', "", "")
|
||||
|
||||
" shortcuts to the global variables - this makes the code easier to read
|
||||
let s:debug = g:indent_guides_debug
|
||||
let s:indent_levels = g:indent_guides_indent_levels
|
||||
let s:auto_colors = g:indent_guides_auto_colors
|
||||
let s:change_percent = g:indent_guides_color_change_percent / 100.0
|
||||
let s:change_percent = g:indent_guides_color_change_percent / str2float("100.0")
|
||||
let s:color_hex_pat = g:indent_guides_color_hex_pattern
|
||||
let s:color_hex_bg_pat = g:indent_guides_color_hex_guibg_pattern
|
||||
let s:color_name_bg_pat = g:indent_guides_color_name_guibg_pattern
|
||||
@@ -203,26 +207,15 @@ endfunction
|
||||
" NOTE: Currently, this only works when soft-tabs are being used.
|
||||
"
|
||||
function! indent_guides#calculate_guide_size()
|
||||
let l:guide_size = g:indent_guides_guide_size
|
||||
let l:indent_size = indent_guides#get_indent_size()
|
||||
let l:guide_size = g:indent_guides_guide_size
|
||||
|
||||
if l:indent_size > 1 && l:guide_size >= 1
|
||||
let l:guide_size = (l:guide_size > s:indent_size) ? s:indent_size : l:guide_size
|
||||
else
|
||||
if l:guide_size == 0 || l:guide_size > s:indent_size
|
||||
let l:guide_size = s:indent_size
|
||||
endif
|
||||
|
||||
return l:guide_size
|
||||
endfunction
|
||||
|
||||
"
|
||||
" Gets the indent size, which depends on whether soft-tabs or hard-tabs are
|
||||
" being used.
|
||||
"
|
||||
function! indent_guides#get_indent_size()
|
||||
return (&l:expandtab == 1) ? &l:shiftwidth : 1
|
||||
endfunction
|
||||
|
||||
"
|
||||
" Captures and returns the output of highlight group definitions.
|
||||
"
|
||||
@@ -238,3 +231,21 @@ function! indent_guides#capture_highlight(group_name)
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
"
|
||||
" Returns a regex pattern for highlighting an indent level.
|
||||
"
|
||||
" Example: indent_guides#indent_highlight_pattern(' ', 1, 4)
|
||||
" Returns: /^ *\%1v\zs *\%5v\ze/
|
||||
"
|
||||
" Example: indent_guides#indent_highlight_pattern('\s', 5, 2)
|
||||
" Returns: /^\s*\%5v\zs\s*\%7v\ze/
|
||||
"
|
||||
" Example: indent_guides#indent_highlight_pattern('\t', 9, 2)
|
||||
" Returns: /^\t*\%9v\zs\t*\%11v\ze/
|
||||
"
|
||||
function! indent_guides#indent_highlight_pattern(indent_pattern, column_start, indent_size)
|
||||
let l:pattern = '^' . a:indent_pattern . '*\%' . a:column_start . 'v\zs'
|
||||
let l:pattern .= a:indent_pattern . '*\%' . (a:column_start + a:indent_size) . 'v'
|
||||
let l:pattern .= '\ze'
|
||||
return l:pattern
|
||||
endfunction
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
|
||||
Author: Nate Kane <nathanaelkane AT gmail DOT com>
|
||||
Version: 1.3
|
||||
Last Change: 17 Jan 2011
|
||||
Version: 1.5
|
||||
Last Change: 13 Mar 2011
|
||||
|
||||
==============================================================================
|
||||
CONTENTS *indent-guides-contents*
|
||||
@@ -41,6 +41,7 @@ Features:~
|
||||
though).
|
||||
* Customizable size for indent guides, eg. skinny guides (soft-tabs only).
|
||||
* Customizable start indent level.
|
||||
* Highlight support for files with a mixture of tab and space indent styles.
|
||||
|
||||
==============================================================================
|
||||
2. COMMANDS *indent-guides-commands*
|
||||
@@ -90,6 +91,12 @@ in an autocmd.
|
||||
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=4
|
||||
<
|
||||
|
||||
Alternatively you can add the following lines to your colorscheme file.
|
||||
>
|
||||
hi IndentGuidesOdd guibg=red ctermbg=3
|
||||
hi IndentGuidesEven guibg=green ctermbg=4
|
||||
<
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*'indent_guides_color_change_percent'*
|
||||
Use this option to control the percent at which the highlight colors will be
|
||||
@@ -126,6 +133,15 @@ Default: 1. Values: between 1 and g:|indent_guides_indent_levels|.
|
||||
let g:indent_guides_start_level = 2
|
||||
<
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*'indent_guides_enable_on_vim_startup'*
|
||||
Use this option to control whether the plugin is enabled on Vim startup.
|
||||
|
||||
Default: 0. Values: 0 or 1.
|
||||
>
|
||||
let g:indent_guides_enable_on_vim_startup = 0
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
4. MAPPINGS *indent-guides-mappings*
|
||||
|
||||
@@ -153,15 +169,15 @@ preset colors are used depending on whether `background` is set to `dark` or
|
||||
When `set background=dark` is used, the following highlight colors will be
|
||||
defined:
|
||||
>
|
||||
hi IndentGuidesEven ctermbg=darkgrey
|
||||
hi IndentGuidesOdd ctermbg=black
|
||||
hi IndentGuidesEven ctermbg=darkgrey
|
||||
<
|
||||
|
||||
Alternatively, when `set background=light` is used, the following highlight
|
||||
colors will be defined:
|
||||
>
|
||||
hi IndentGuidesEven ctermbg=lightgrey
|
||||
hi IndentGuidesOdd ctermbg=white
|
||||
hi IndentGuidesEven ctermbg=lightgrey
|
||||
<
|
||||
|
||||
If for some reason it's incorrectly defining light highlight colors instead of
|
||||
@@ -203,6 +219,19 @@ Bug reports, feedback, suggestions etc are welcomed.
|
||||
==============================================================================
|
||||
7. CHANGELOG *indent-guides-changelog*
|
||||
|
||||
1.5~
|
||||
* Added highlight support for files with a mixture of tab and space indent
|
||||
styles (thanks graywh).
|
||||
* Added -bar to all the :commands so they can chain with other :commands
|
||||
(thanks to graywh).
|
||||
* No longer overriding pre-defined custom highlight colors (thanks graywh).
|
||||
* Using str2float to work around a float bug in some versions of Vim 7.2
|
||||
(thanks voidus).
|
||||
|
||||
1.4~
|
||||
* Added the new plugin option g:|indent_guides_enable_on_vim_startup|.
|
||||
* Improved Windows support.
|
||||
|
||||
1.3~
|
||||
* Changed the default value of g:|indent_guides_color_change_percent| to 10.
|
||||
* Added support for gVim themes that don't specify a `hi Normal guibg`
|
||||
@@ -250,4 +279,3 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
vim:tw=78:ts=2:ft=help:norl:
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ function! s:IndentGuidesDisable()
|
||||
endfunction
|
||||
|
||||
" Commands
|
||||
command! IndentGuidesToggle call s:IndentGuidesToggle()
|
||||
command! IndentGuidesEnable call s:IndentGuidesEnable()
|
||||
command! IndentGuidesDisable call s:IndentGuidesDisable()
|
||||
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
|
||||
@@ -30,7 +30,7 @@ command! IndentGuidesDisable call s:IndentGuidesDisable()
|
||||
"
|
||||
function s:InitVariable(var, value)
|
||||
if !exists(a:var)
|
||||
if type(a:var) == type("")
|
||||
if type(a:value) == type("")
|
||||
exec 'let ' . a:var . ' = ' . "'" . a:value . "'"
|
||||
else
|
||||
exec 'let ' . a:var . ' = ' . a:value
|
||||
@@ -45,12 +45,13 @@ let g:indent_guides_color_hex_guibg_pattern = 'guibg=\zs' . g:indent_guides_col
|
||||
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_debug', 0 )
|
||||
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 )
|
||||
|
||||
" Default mapping
|
||||
nmap <Leader>ig :IndentGuidesToggle<CR>
|
||||
@@ -58,6 +59,10 @@ nmap <Leader>ig :IndentGuidesToggle<CR>
|
||||
" Auto commands
|
||||
augroup indent_guides
|
||||
autocmd!
|
||||
|
||||
if g:indent_guides_enable_on_vim_startup
|
||||
autocmd VimEnter * :IndentGuidesEnable
|
||||
endif
|
||||
|
||||
autocmd BufEnter,WinEnter * call indent_guides#process_autocmds()
|
||||
augroup END
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
vim:tw=78:ts=2:sw=2:et
|
||||
vim:tw=78:ts=2:sw=2:et:nolist
|
||||
|
||||
test
|
||||
test
|
||||
@@ -23,3 +23,25 @@ test
|
||||
test
|
||||
test
|
||||
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
|
||||
@@ -1,4 +1,27 @@
|
||||
vim:tw=78:ts=2:sw=2:noet
|
||||
vim:tw=78:ts=2:sw=2:noet:nolist
|
||||
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
|
||||
test
|
||||
test
|
||||
@@ -22,4 +45,3 @@ test
|
||||
test
|
||||
test
|
||||
test
|
||||
|
||||
|
||||
24
test-files/test-ts2sw4noet.txt
Normal file
24
test-files/test-ts2sw4noet.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
vim:tw=78:ts=2:sw=4:noet:nolist
|
||||
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
@@ -1,4 +1,4 @@
|
||||
vim:tw=78:ts=4:sw=4:et
|
||||
vim:tw=78:ts=4:sw=4:et:nolist
|
||||
|
||||
test
|
||||
test
|
||||
@@ -23,3 +23,25 @@ test
|
||||
test
|
||||
test
|
||||
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
|
||||
@@ -1,4 +1,27 @@
|
||||
vim:tw=78:ts=4:sw=4:noet
|
||||
vim:tw=78:ts=4:sw=4:noet:nolist
|
||||
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
|
||||
test
|
||||
test
|
||||
@@ -22,4 +45,3 @@ test
|
||||
test
|
||||
test
|
||||
test
|
||||
|
||||
|
||||
24
test-files/test-ts8sw2noet.txt
Normal file
24
test-files/test-ts8sw2noet.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
vim:tw=78:ts=8:sw=2:noet:nolist
|
||||
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
@@ -1,4 +1,4 @@
|
||||
vim:tw=78:ts=8:sw=8:et
|
||||
vim:tw=78:ts=8:sw=8:et:nolist
|
||||
|
||||
test
|
||||
test
|
||||
@@ -23,3 +23,25 @@ test
|
||||
test
|
||||
test
|
||||
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
|
||||
@@ -1,4 +1,27 @@
|
||||
vim:tw=78:ts=8:sw=8:noet
|
||||
vim:tw=78:ts=8:sw=8:noet:nolist
|
||||
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
test
|
||||
|
||||
test
|
||||
test
|
||||
@@ -22,4 +45,3 @@ test
|
||||
test
|
||||
test
|
||||
test
|
||||
|
||||
|
||||
Reference in New Issue
Block a user