diff --git a/README.md b/README.md index fbcd3de..91a85c4 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,17 @@ All operations are easily reversible and correctly preserve the indentation of t ## Configuration ## -You can customize the behavior of this extension by setting values for any of the following optional buffer and global -variables in your `.vimrc` file: +You can customize the behavior of this extension by setting values for any of the following optional *buffer* and +*global* configuration variables in your `.vimrc` file. Buffer variables (prefixed with `b:`) take precedence over +global variables (prefixed with `g:`), making them ideal for configuring the behavior of this extension on a file by +file basis using `ftplugin` or `autocmd`. For example, the `argwrap_tail_comma` variable has two variants declared as +`b:argwrap_tail_comma` and `g:argwrap_tail_comma`, for buffer and global scopes respectively. -* `g:argwrap_wrap_closing_brace` or `b:argwrap_wrap_closing_brace` +* **argwrap_line_prefix** - *Specifies if the closing brace should be wrapped to a new line.* + Specifies a line prefix to be added and removed when working with languages that require newlines to be escaped. - Brace wrapping enabled (default) + *Line prefix disabled (default)* ``` Foo( @@ -44,7 +47,75 @@ variables in your `.vimrc` file: ) ``` - Brace wrapping disabled (`let g:argwrap_wrap_closing_brace = 0`) + *Line prefix enabled for Vimscript (`let g:argwrap_line_prefix = '\'`)* + + ``` + Foo( + \wibble, + \wobble, + \wubble + \) + ``` + +* **argwrap_padded_braces** + + Specifies which brace types should be padded on the inside with spaces. + + *Brace padding disabled (default)* + + ``` + [1, 2, 3] + {1, 2, 3} + ``` + + *Brace padding enabled for square brackets only (`let g:argwrap_padded_braces = '['`)* + + ``` + [ 1, 2, 3 ] + {1, 2, 3} + ``` + + *Padding can be specified for multiple brace types (`let g:argwrap_padded_braces = '[{'`)* + +* **argwrap_tail_comma** + + Specifies if the closing brace should be preceded with a comma when wrapping lines. + + *Tail comma disabled (default)* + + ``` + Foo( + wibble, + wobble, + wubble + ) + ``` + + *Tail comma enabled (`let g:argwrap_tail_comma = 1`)* + + ``` + Foo( + wibble, + wobble, + wubble, + ) + ``` + +* **argwrap_wrap_closing_brace** + + Specifies if the closing brace should be wrapped to a new line. + + *Brace wrapping enabled (default)* + + ``` + Foo( + wibble, + wobble, + wubble + ) + ``` + + *Brace wrapping disabled (`let g:argwrap_wrap_closing_brace = 0`)* ``` Foo( @@ -53,35 +124,10 @@ variables in your `.vimrc` file: wubble) ``` -* `g:argwrap_padded_braces` or `b:argwrap_wrap_closing_brace` - - *Specifies which brace types should be padded on the inside with spaces.* - - `''`: do not add padding for any braces (empty string): - - ``` - [1, 2, 3] - {1, 2, 3} - ``` - - `'['`: padding for square braces only (curly braces are not padded): - - ``` - [ 1, 2, 3 ] - {1, 2, 3} - ``` - - Padding can be specified for multiple brace types as follows: - - ``` - let g:argwrap_padded_braces = '[{' - ``` - ## Usage ## 1. Position the cursor *inside* of the scope of the parenthesis, brackets or curly braces you wish to wrap/unwrap (not on top, before or after them). - 2. Execute the keyboard binding you defined above to *toggle* the wrapping and unwrapping of arguments. ## License ## diff --git a/autoload/argwrap.vim b/autoload/argwrap.vim index 252e08d..ad80727 100644 --- a/autoload/argwrap.vim +++ b/autoload/argwrap.vim @@ -209,10 +209,10 @@ endfunction function! argwrap#toggle() let l:cursor = getpos('.') + let l:linePrefix = argwrap#getSetting('line_prefix', '') + let l:padded = argwrap#getSetting('padded_braces', '') let l:tailComma = argwrap#getSetting('tail_comma', 0) let l:wrapBrace = argwrap#getSetting('wrap_closing_brace', 1) - let l:padded = argwrap#getSetting('padded_braces', '') - let l:linePrefix = argwrap#getSetting('line_prefix', '') let l:range = argwrap#findClosestRange() if !argwrap#validateRange(l:range) diff --git a/doc/argwrap.txt b/doc/argwrap.txt index 42243c7..24eb818 100644 --- a/doc/argwrap.txt +++ b/doc/argwrap.txt @@ -5,8 +5,9 @@ CONTENTS 1. ArgWrap...............................................................................................|argwrap-argwrap| 1.1. Installation...............................................................................|argwrap-installation| - 1.2. Usage.............................................................................................|argwrap-usage| - 1.3. Configuration.............................................................................|argwrap-configuration| + 1.2. Configuration.............................................................................|argwrap-configuration| + 1.3. Usage.............................................................................................|argwrap-usage| + 1.4. License.........................................................................................|argwrap-license| ======================================================================================================================== ARGWRAP *argwrap-argwrap* @@ -32,20 +33,65 @@ INSTALLATION nnoremap a :ArgWrap < ------------------------------------------------------------------------------------------------------------------------- -USAGE *argwrap-usage* - -1. Position the cursor inside of the scope of the parenthesis, brackets or curly braces you wish to wrap/unwrap (not - on top, before or after them). -2. Execute the keyboard binding you defined above to toggle the wrapping and unwrapping of arguments. - ------------------------------------------------------------------------------------------------------------------------ CONFIGURATION *argwrap-configuration* -You can customize the behavior of this extension by setting values for any of the following optional buffer and global -variables in your `.vimrc` file: +You can customize the behavior of this extension by setting values for any of the following optional buffer and +global configuration variables in your `.vimrc` file. Buffer variables (prefixed with `b:`) take precedence over +global variables (prefixed with `g:`), making them ideal for configuring the behavior of this extension on a file by +file basis using `ftplugin` or `autocmd`. For example, the `argwrap_tail_comma` variable has two variants declared as +`b:argwrap_tail_comma` and `g:argwrap_tail_comma`, for buffer and global scopes respectively. -* `g:argwrap_wrap_closing_brace` or `b:argwrap_wrap_closing_brace` +* argwrap_line_prefix + Specifies a line prefix to be added and removed when working with languages that require newlines to be escaped. + Line prefix disabled (default) +> + Foo( + wibble, + wobble, + wubble + ) +< + Line prefix enabled for Vimscript () +> + Foo( + \wibble, + \wobble, + \wubble + \) +< +* argwrap_padded_braces + Specifies which brace types should be padded on the inside with spaces. + Brace padding disabled (default) +> + [1, 2, 3] + {1, 2, 3} +< + Brace padding enabled for square brackets only () +> + [ 1, 2, 3 ] + {1, 2, 3} +< + Padding can be specified for multiple brace types () +* argwrap_tail_comma + Specifies if the closing brace should be preceded with a comma when wrapping lines. + Tail comma disabled (default) +> + Foo( + wibble, + wobble, + wubble + ) +< + Tail comma enabled () +> + Foo( + wibble, + wobble, + wubble, + ) +< +* argwrap_wrap_closing_brace Specifies if the closing brace should be wrapped to a new line. Brace wrapping enabled (default) > @@ -62,19 +108,15 @@ variables in your `.vimrc` file: wobble, wubble) < -* `g:argwrap_padded_braces` or `b:argwrap_wrap_closing_brace` - Specifies which brace types should be padded on the inside with spaces. - `''`: do not add padding for any braces (empty string): -> - [1, 2, 3] - {1, 2, 3} -< - `'['`: padding for square braces only (curly braces are not padded): -> - [ 1, 2, 3 ] - {1, 2, 3} -< - Padding can be specified for multiple brace types as follows: -> - let g:argwrap_padded_braces = '[{' -< + +------------------------------------------------------------------------------------------------------------------------ +USAGE *argwrap-usage* + +1. Position the cursor inside of the scope of the parenthesis, brackets or curly braces you wish to wrap/unwrap (not + on top, before or after them). +2. Execute the keyboard binding you defined above to toggle the wrapping and unwrapping of arguments. + +------------------------------------------------------------------------------------------------------------------------ +LICENSE *argwrap-license* + +MIT