18 Commits
1.0 ... 1.1

Author SHA1 Message Date
Nate Kane
23211a3b4f Oops, went over the textwidth in the help file 2010-12-29 21:53:05 +10:00
Nate Kane
8365779904 Added Windows support info to the readme and help file 2010-12-29 21:50:42 +10:00
Nate Kane
38a4501224 Couple more tweaks to the readme 2010-12-29 21:34:18 +10:00
Nate Kane
a7d8f3dce7 Updated the readme and help file (again) 2010-12-29 21:29:13 +10:00
Nate Kane
9712a19ba9 Updated the readme 2010-12-29 21:23:35 +10:00
Nate Kane
b9266fb158 Updated the readme and help file 2010-12-29 21:15:52 +10:00
Nate Kane
32b9f52837 Added more explicit variable scopes 2010-12-29 20:31:49 +10:00
Nate Kane
046104c2f0 Tweaked the indent_guides#cterm_highlight_colors() function a bit 2010-12-29 20:17:34 +10:00
Nate Kane
9b43f5c84c Refactored the color_helper#color_name_to_hex() function to use hex codes directly instead of calculating them (shoutout to godlygeek for the codes) 2010-12-29 20:12:10 +10:00
Nate Kane
b4b4ce9c76 Tweaked the indent_guides#cterm_highlight_colors() function so it works a bit more consistently 2010-12-29 14:43:42 +10:00
Nate Kane
51436e3677 Tweaked the indent_guides#cterm_highlight_colors() function 2010-12-22 21:44:46 +10:00
Joshua Hogendorn
b3656708cb Terminal colours are now based on the Normal BG
Instead of using the foreground and background of a search result, which
is usually designed to stand right out, the indents for terminal are now
colored according to the normal text background.
2010-12-22 10:31:06 +10:00
Joshua Hogendorn
0ebc1eb93d Fixes an error setting default colours to NONE
It needs to be NONE, not none.
2010-12-22 09:30:50 +10:00
Nate Kane
78f60359c8 Updated the readme file 2010-12-20 22:32:35 +10:00
Nate Kane
5d01603b9a Updated the help file 2010-12-20 22:30:18 +10:00
Nate Kane
14aae71298 Improved support for terminal vim 2010-12-20 22:26:45 +10:00
Nate Kane
6d903df6e7 Added early support for terminal vim 2010-12-20 21:51:02 +10:00
Nate Kane
0c0ac44889 Updated the help file and readme 2010-12-12 19:33:16 +10:00
5 changed files with 941 additions and 822 deletions

View File

@@ -3,13 +3,18 @@ Indent Guides is a plugin for visually displaying indent levels in vim.
## Features:
* Can detect both tab and space indent styles.
* Automatically inspects your colorscheme and picks appropriate colors.
* Automatically inspects your colorscheme and picks appropriate colors (gvim only).
* 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).
## Requirements
* vim 7.2+
## Installation
To install the plugin just copy `autoload`, `plugin`, `doc` directories into your .vim directory.
To install the plugin just copy `autoload`, `plugin`, `doc` directories into your `.vim` directory.
Alternatively if you have [Pathogen](http://www.vim.org/scripts/script.php?script_id=2332) installed, just clone this repo into a subdirectory of your .vim/bundle directory like so:
Alternatively if you have [Pathogen](http://www.vim.org/scripts/script.php?script_id=2332) installed, just clone this repo into a subdirectory of your `.vim/bundle` directory like so:
cd ~/.vim/bundle
git clone git://github.com/nathanaelkane/vim-indent-guides.git
@@ -17,6 +22,33 @@ Alternatively if you have [Pathogen](http://www.vim.org/scripts/script.php?scrip
## Usage
The default mapping to toggle the plugin is `<Leader>ig`
### Setting custom indent colors
Here's an example of how to define custom colors instead using of the ones the plugin automatically generates for you. Add this to your `.vimrc` file:
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=3
autocmd VimEnter,Colorscheme * :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
Alternatively, when `set background=light` is used, the following highlight colors will be defined:
hi IndentGuidesEven ctermbg=lightgrey
hi IndentGuidesOdd ctermbg=white
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:
colorscheme desert256
set background=dark
Alternatively you can manually setup the highlight colors yourself, see `:help indent_guides_auto_colors` for an example.
## Help
`:help indent-guides`

File diff suppressed because it is too large Load Diff

View File

@@ -32,23 +32,20 @@ endfunction
"
function! indent_guides#enable()
let g:indent_guides_autocmds_enabled = 1
call indent_guides#highlight_colors()
call indent_guides#clear_matches()
if g:indent_guides_auto_colors
call indent_guides#highlight_colors()
endif
" loop through each indent level and define a highlight pattern
" will automagically figure out whether to use tabs or spaces
for level in range(1, g:indent_guides_indent_levels)
let group = 'IndentGuides' . ((level % 2 == 0) ? 'Even' : 'Odd')
let multiplier = (&l:expandtab == 1) ? &l:shiftwidth : 1
let pattern = '^\s\{' . (level * multiplier - multiplier) . '\}\zs'
let pattern .= '\s\{' . multiplier . '\}'
let pattern .= '\ze'
for l:level in range(1, g:indent_guides_indent_levels)
let l:group = 'IndentGuides' . ((l:level % 2 == 0) ? 'Even' : 'Odd')
let l:multiplier = (&l:expandtab == 1) ? &l:shiftwidth : 1
let l:pattern = '^\s\{' . (l:level * l:multiplier - l:multiplier) . '\}\zs'
let l:pattern .= '\s\{' . l:multiplier . '\}'
let l:pattern .= '\ze'
" define the higlight pattern and add to list
call add(w:indent_guides_matches, matchadd(group, pattern))
call add(w:indent_guides_matches, matchadd(l:group, l:pattern))
endfor
endfunction
@@ -67,11 +64,11 @@ endfunction
function! indent_guides#clear_matches()
call indent_guides#init_matches()
if !empty(w:indent_guides_matches)
let index = 0
for match_id in w:indent_guides_matches
call matchdelete(match_id)
call remove(w:indent_guides_matches, index)
let index += index
let l:index = 0
for l:match_id in w:indent_guides_matches
call matchdelete(l:match_id)
call remove(w:indent_guides_matches, l:index)
let l:index += l:index
endfor
endif
endfunction
@@ -81,45 +78,71 @@ endfunction
"
function! indent_guides#highlight_colors()
if g:indent_guides_auto_colors
let hi_normal = indent_guides#capture_highlight('normal')
let hex_pattern = 'guibg=\zs'. g:indent_guides_hex_color_pattern . '\ze'
let name_pattern = "guibg='\\?\\zs[0-9A-Za-z ]\\+\\ze'\\?"
let hi_normal_guibg = ''
" capture the backgroud color from the normal highlight
if hi_normal =~ hex_pattern
" hex color code is being used, eg. '#FFFFFF'
let hi_normal_guibg = matchstr(hi_normal, hex_pattern)
elseif hi_normal =~ name_pattern
" color name is being used, eg. 'white'
let color_name = matchstr(hi_normal, name_pattern)
let hi_normal_guibg = color_helper#color_name_to_hex(color_name)
if has('gui_running')
call indent_guides#gui_highlight_colors()
else
call indent_guides#cterm_highlight_colors()
endif
if hi_normal_guibg =~ g:indent_guides_hex_color_pattern
" calculate the highlight background colors
let hi_odd_bg = indent_guides#lighten_or_darken_color(hi_normal_guibg)
let hi_even_bg = indent_guides#lighten_or_darken_color(hi_odd_bg)
" define the new highlights
exe 'hi IndentGuidesOdd guibg=' . hi_odd_bg
exe 'hi IndentGuidesEven guibg=' . hi_even_bg
end
endif
endfunction
"
" Defines the indent highlight colors for terminal vim.
"
" NOTE: This function contains no magic at the moment, it will simply use some
" light or dark preset colors depending on the `set background=` value.
"
function! indent_guides#cterm_highlight_colors()
let l:colors = (&g:background == 'dark') ?
\ ['darkgrey', 'black'] : ['lightgrey', 'white']
exe 'hi IndentGuidesEven ctermbg=' . l:colors[0]
exe 'hi IndentGuidesOdd ctermbg=' . l:colors[1]
endfunction
"
" Automagically calculates and defines the indent highlight colors for gui
" vim.
"
function! indent_guides#gui_highlight_colors()
let l:hi_normal = indent_guides#capture_highlight('Normal')
let l:hex_pattern = 'guibg=\zs'. g:indent_guides_hex_color_pattern . '\ze'
let l:name_pattern = "guibg='\\?\\zs[0-9A-Za-z ]\\+\\ze'\\?"
let l:hi_normal_guibg = ''
" capture the backgroud color from the normal highlight
if l:hi_normal =~ l:hex_pattern
" hex color code is being used, eg. '#FFFFFF'
let l:hi_normal_guibg = matchstr(l:hi_normal, l:hex_pattern)
elseif l:hi_normal =~ l:name_pattern
" color name is being used, eg. 'white'
let l:color_name = matchstr(l:hi_normal, l:name_pattern)
let l:hi_normal_guibg = color_helper#color_name_to_hex(l:color_name)
endif
if l:hi_normal_guibg =~ g:indent_guides_hex_color_pattern
" calculate the highlight background colors
let l:hi_odd_bg = indent_guides#lighten_or_darken_color(l:hi_normal_guibg)
let l:hi_even_bg = indent_guides#lighten_or_darken_color(l:hi_odd_bg)
" define the new highlights
exe 'hi IndentGuidesOdd guibg=' . l:hi_odd_bg
exe 'hi IndentGuidesEven guibg=' . l:hi_even_bg
end
endfunction
"
" Takes a color and darkens or lightens it depending on whether a dark or light
" colorscheme is being used.
"
function! indent_guides#lighten_or_darken_color(color)
let percent = g:indent_guides_color_change_percent
let l:percent = g:indent_guides_color_change_percent
let new_color = (&g:background == 'dark') ?
\ color_helper#hex_color_lighten(a:color, percent) :
\ color_helper#hex_color_darken (a:color, percent)
let l:new_color = (&g:background == 'dark') ?
\ color_helper#hex_color_lighten(a:color, l:percent) :
\ color_helper#hex_color_darken (a:color, l:percent)
return new_color
return l:new_color
endfunction
"
@@ -129,11 +152,11 @@ endfunction
" Returns: 'Normal xxx guifg=#323232 guibg=#ffffff
"
function! indent_guides#capture_highlight(group_name)
redir => output
redir => l:output
exe "silent hi " . a:group_name
redir END
return output
return l:output
endfunction
"
@@ -144,3 +167,11 @@ function! indent_guides#init_matches()
\ exists('w:indent_guides_matches') ? w:indent_guides_matches : []
endfunction
"
" Define default highlights.
"
function! indent_guides#define_default_highlights()
exe 'hi IndentGuidesOdd guibg=NONE ctermbg=NONE'
exe 'hi IndentGuidesEven guibg=NONE ctermbg=NONE'
endfunction

View File

@@ -9,19 +9,20 @@
Author: Nate Kane <nathanaelkane AT gmail DOT com>
Version: 1.0
Last Change: 12 Dec 2010
Version: 1.1
Last Change: 29 Dec 2010
==============================================================================
CONTENTS *indent-guides-contents*
1. Introduction.............................. |indent-guides-introduction|
2. Commands.................................. |indent-guides-commands|
3. Options................................... |indent-guides-options|
4. Mappings.................................. |indent-guides-mappings|
5. About..................................... |indent-guides-about|
6. Changelog................................. |indent-guides-changelog|
7. License................................... |indent-guides-license|
1. Introduction.......................... |indent-guides-introduction|
2. Commands.............................. |indent-guides-commands|
3. Options............................... |indent-guides-options|
4. Mappings.............................. |indent-guides-mappings|
5. Terminal Vim.......................... |indent-guides-terminal-vim|
6. About................................. |indent-guides-about|
7. Changelog............................. |indent-guides-changelog|
8. License............................... |indent-guides-license|
==============================================================================
1. INTRODUCTION *indent-guides-introduction*
@@ -30,8 +31,12 @@ Indent Guides is a plugin for visually displaying indent levels in vim.
Features:~
* Can detect both tab and space indent styles.
* Automatically inspects your colorscheme and picks appropriate colors.
* Automatically inspects your colorscheme and picks appropriate colors (gvim
only).
* 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).
==============================================================================
2. COMMANDS *indent-guides-commands*
@@ -71,10 +76,12 @@ Default: 1. Values: 0 or 1.
let g:indent_guides_auto_colors = 1
<
If you set this option to 0, be sure to manually define some highlight colors.
If you set this option to 0, be sure to manually define some highlight colors
in an autocmd.
>
hi IndentGuidesOdd guibg=#EEEEEE
hi IndentGuidesEven guibg=#CCCCCC
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=3
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=4
<
------------------------------------------------------------------------------
@@ -103,7 +110,41 @@ example:
<
==============================================================================
5. ABOUT *indent-guides-about*
5. TERMINAL VIM *indent-guides-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
<
Alternatively, when `set background=light` is used, the following highlight
colors will be defined:
>
hi IndentGuidesEven ctermbg=lightgrey
hi IndentGuidesOdd ctermbg=white
<
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:
>
colorscheme desert256
set background=dark
<
Alternatively you can manually setup the highlight colors yourself, see
|indent_guides_auto_colors| for an example.
==============================================================================
6. ABOUT *indent-guides-about*
Why did I build this plugin?~
* I believe indent guides make nested code easier to read and understand.
@@ -115,6 +156,10 @@ Links:~
* Github: https://github.com/nathanaelkane/vim-indent-guides
* Bugs & Issues: https://github.com/nathanaelkane/vim-indent-guides/issues
Credits:~
* Matt Wozniski (godlygeek) for letting me use the list of color names and
hex codes from his CSApprox plugin.
Contact:~
* Twitter: @nathanaelkane
* Email: <nathanaelkane AT gmail DOT com>
@@ -123,13 +168,20 @@ Contact:~
Bug reports, feedback, suggestions etc are welcomed.
==============================================================================
6. CHANGELOG *indent-guides-changelog*
7. CHANGELOG *indent-guides-changelog*
1.1~
* Added basic support for terminal vim. See |indent-guides-terminal-vim| for
more information.
* Cut down on rgb to hex color conversions by adding a big dictionary of
color names and hex codes.
* Various bug fixes.
1.0~
* First public version.
==============================================================================
7. LICENSE *indent-guides-license*
8. LICENSE *indent-guides-license*
The MIT Licence
http://www.opensource.org/licenses/mit-license.php

View File

@@ -1,11 +1,11 @@
" Author: Nate Kane <nathanaelkane AT gmail DOT com>
" Homepage: http://github.com/nathanaelkane/vim-indent-guides
if exists('g:loaded_indent_guides') || &cp || !has('gui_running')
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()