diff --git a/README.md b/README.md index b4a8a20..2069af6 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ variant `:EasyAlign!`) for visual mode. An *alignment rule* is a predefined set of options for common alignment tasks, which is identified by a single character, *DELIMITER KEY*, such as ``, -`=`, `:`, `.`, `|`, and `,`. +`=`, `:`, `.`, `|`, `&`, and `,`. Think of it as a shortcut. Instead of writing regular expression and setting several options, you can just type in a single character. @@ -95,7 +95,7 @@ With the mapping, you can align selected lines of text with only a few keystroke - `-` Around the last occurrences of delimiters (`-1`) - `-2` Around the second to last occurrences of delimiters - ... -1. Delimiter key (a single keystroke; ``, `=`, `:`, `.`, `|`, `,`) +1. Delimiter key (a single keystroke; ``, `=`, `:`, `.`, `|`, `&`, `,`) Alignment rules for the following delimiters have been defined to meet the most needs. @@ -106,6 +106,7 @@ Alignment rules for the following delimiters have been defined to meet the most | `:` | Suitable for formatting JSON or YAML | | `.` | Multi-line method chaining | | `,` | Multi-line method arguments | +| `&` | LaTeX tables (matches `&` and `\\`) | | | | Table markdown | You can override these default rules or define your own rules with diff --git a/autoload/easy_align.vim b/autoload/easy_align.vim index dacc1e3..7bf4ae9 100644 --- a/autoload/easy_align.vim +++ b/autoload/easy_align.vim @@ -34,6 +34,8 @@ let s:easy_align_delimiters_default = { \ ',': { 'pattern': ',', 'left_margin': 0, 'right_margin': 1, 'stick_to_left': 1 }, \ '|': { 'pattern': '|', 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 }, \ '.': { 'pattern': '\.', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0 }, +\ '&': { 'pattern': '\\\@*& + +Expect tex: + \begin{tabular}{ l c r } + 1 & 2 & 3 \\ + 44 & 55 & 66 \\ + 777 & 8\&8 & 999 \\ + \end{tabular} + +Do (right-align with explicit ignore_unmatched): + vip\\\\*& + +Expect tex: + \begin{tabular}{ l c r } + 1 & 2 & 3 \\ + 44 & 55 & 66 \\ + 777 & 8\&8 & 999 \\ + \end{tabular} + +Do (center-align with explicit ignore_unmatched): + vip\\\\\*& + +Expect tex: + \begin{tabular}{ l c r } + 1 & 2 & 3 \\ + 44 & 55 & 66 \\ + 777 & 8\&8 & 999 \\ + \end{tabular} + +Given tex (simple table with \hline): + \begin{tabular}{ l c r } + 1&2&3\\ \hline + 44&55&66\\ \hline + 777&8\&&999\\ \hline + \end{tabular} + +Do: + vip\*& + +Expect tex: + \begin{tabular}{ l c r } + 1 & 2 & 3 \\ \hline + 44 & 55 & 66 \\ \hline + 777 & 8\& & 999 \\ \hline + \end{tabular} + +Given tex (table with lines w/o &s): + \begin{tabular}{|r|l|} + \hline + 7C0 & hexadecimal \\ + 3700&octal \\ \cline{2-2} + 1111100000 & binary \\ + \hline \hline + 1984 & decimal \\ + \hline + \end{tabular} + +Do (left-align*): + vip\*& + +Expect tex: + \begin{tabular}{|r|l|} + \hline + 7C0 & hexadecimal \\ + 3700 & octal \\ \cline{2-2} + 1111100000 & binary \\ + \hline \hline + 1984 & decimal \\ + \hline + \end{tabular} + +Do(left-align* and right-align around 2nd): + vip\*& + gv\\2& + +Expect tex: + \begin{tabular}{|r|l|} + \hline + 7C0 & hexadecimal \\ + 3700 & octal \\ \cline{2-2} + 1111100000 & binary \\ + \hline \hline + 1984 & decimal \\ + \hline + \end{tabular} +