diff --git a/README.md b/README.md index 5308496..ebc8ca9 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,33 @@ git clone git://github.com/tommcdo/vim-lion.git Once help tags have been generated, you can view the manual with `:help lion`. + +Options +------- + +Option | Description | Default +--- | --- | --- +`g:lion_create_maps` | Whether to create mappings | `1` +`b:lion_squeeze_spaces`
`g:lion_squeeze_spaces` | Squeeze extra spaces | `0` +`g:lion_map_right` | Mapping for right-align operator | `gl` +`g:lion_map_left` | Mapping for left-align operator | `gL` + +If you set: `let b:lion_squeeze_spaces = 1`, and hit `glip=`, you will turn + +```php +$i = 5; +$user = 'tommcdo'; +$stuff = array(1, 2, 3); +``` +into: +```php +$i = 5; +$user = 'tommcdo'; +$stuff = array(1, 2, 3); +``` +instead of (`b:lion_squeeze_spaces = 0`): +```php +$i = 5; +$user = 'tommcdo'; +$stuff = array(1, 2, 3); +``` diff --git a/doc/lion.txt b/doc/lion.txt index 1d57fc1..30d0822 100644 --- a/doc/lion.txt +++ b/doc/lion.txt @@ -9,7 +9,7 @@ INTRODUCTION *lion* This plugin provides operators for aligning text to a specific character. The operators are designed to work as closely as possible to the built-in -Vim |operators|. +Vim |operators|. MAPPINGS *lion-mappings* @@ -50,11 +50,13 @@ CONFIGURATION *lion-configuration* Mappings can be configured with the following options: - Option Description Default ~ + Option Description Default ~ - g:lion_create_maps Whether to create mappings 1 - g:lion_map_right Mapping for right-align operator gl - g:lion_map_left Mapping for left-align operator gL + g:lion_create_maps Whether to create mappings 1 + b:lion_squeeze_spaces, + g:lion_squeeze_spaces Whether to squeeze extra spaces 0 + g:lion_map_right Mapping for right-align operator gl + g:lion_map_left Mapping for left-align operator gL ISSUES AND TODO *lion-issues* *lion-todo* diff --git a/plugin/lion.vim b/plugin/lion.vim index ab90f38..22a4c9d 100644 --- a/plugin/lion.vim +++ b/plugin/lion.vim @@ -62,6 +62,22 @@ function! s:align(mode, type, vis, align_char) endif let [start_line, end_line, start_col, end_col, middle_start_col, middle_end_col] = pos + " Check for 'lion_squeeze_spaces' options + if exists('b:lion_squeeze_spaces') + let s:lion_squeeze_spaces = get(b:, 'lion_squeeze_spaces') + elseif exists('g:lion_squeeze_spaces') + let s:lion_squeeze_spaces = get(g:, 'lion_squeeze_spaces') + else + let s:lion_squeeze_spaces = 0 + endif + + " Squeeze extra spaces before aligning + if s:lion_squeeze_spaces + for lnum in range(start_line, end_line) + call setline(lnum, substitute(getline(lnum), '\(^\s*\)\@