mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-14 12:53:48 -05:00
Add alignment rule for LaTeX tables (#13)
This commit is contained in:
@@ -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 `<space>`,
|
||||
`=`, `:`, `.`, `|`, 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; `<space>`, `=`, `:`, `.`, `|`, `,`)
|
||||
1. Delimiter key (a single keystroke; `<space>`, `=`, `:`, `.`, `|`, `&`, `,`)
|
||||
|
||||
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
|
||||
|
||||
@@ -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': '\\\@<!&\|\\\\',
|
||||
\ 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 },
|
||||
\ '{': { 'pattern': '(\@<!{',
|
||||
\ 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 },
|
||||
\ '}': { 'pattern': '}', 'left_margin': 1, 'right_margin': 0, 'stick_to_left': 0 }
|
||||
|
||||
@@ -50,6 +50,7 @@ With this mapping, you can align selected lines of text with a few keystrokes.
|
||||
: Suitable for formatting JSON or YAML
|
||||
. Multi-line method chaining
|
||||
, Multi-line method arguments. CSV.
|
||||
& LaTeX tables (matches & and \\)
|
||||
| Table markdown
|
||||
|
||||
(You can override these default rules or define your own rules with
|
||||
|
||||
98
test/tex.vader
Normal file
98
test/tex.vader
Normal file
@@ -0,0 +1,98 @@
|
||||
# http://en.wikibooks.org/wiki/LaTeX/Tables
|
||||
Execute:
|
||||
let g:easy_align_delimiters = {}
|
||||
|
||||
Given tex (table with escaped &):
|
||||
\begin{tabular}{ l c r }
|
||||
1&2&3\\
|
||||
44&55&66\\
|
||||
777&8\&8&999\\
|
||||
\end{tabular}
|
||||
|
||||
Do (Align around all &s and \\s):
|
||||
vip\<Enter>*&
|
||||
|
||||
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\<Enter>\<Enter>\<C-U>\<C-U>*&
|
||||
|
||||
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\<Enter>\<Enter>\<Enter>\<C-U>\<C-U>*&
|
||||
|
||||
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\<Enter>*&
|
||||
|
||||
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\<Enter>*&
|
||||
|
||||
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\<Enter>*&
|
||||
gv\<Enter>\<Enter>2&
|
||||
|
||||
Expect tex:
|
||||
\begin{tabular}{|r|l|}
|
||||
\hline
|
||||
7C0 & hexadecimal \\
|
||||
3700 & octal \\ \cline{2-2}
|
||||
1111100000 & binary \\
|
||||
\hline \hline
|
||||
1984 & decimal \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
|
||||
Reference in New Issue
Block a user