easy_align.txt 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. *easy-align.txt* easy-align Last change: December 14 2014
  2. EASY-ALIGN - TABLE OF CONTENTS *easyalign* *easy-align* *easy-align-toc*
  3. ==============================================================================
  4. vim-easy-align
  5. Demo |easy-align-1|
  6. Features |easy-align-2|
  7. Installation |easy-align-3|
  8. TLDR - One-minute guide |easy-align-4|
  9. Usage |easy-align-5|
  10. Concept of alignment rule |easy-align-5-1|
  11. Execution models |easy-align-5-2|
  12. 1. Using <Plug> mappings |easy-align-5-2-1|
  13. 2. Using :EasyAlign command |easy-align-5-2-2|
  14. Interactive mode |easy-align-5-3|
  15. Predefined alignment rules |easy-align-5-3-1|
  16. Examples |easy-align-5-3-2|
  17. Using regular expressions |easy-align-5-3-3|
  18. Alignment options in interactive mode |easy-align-5-3-4|
  19. Live interactive mode |easy-align-5-4|
  20. Non-interactive mode |easy-align-5-5|
  21. Partial alignment in blockwise-visual mode |easy-align-5-6|
  22. Alignment options |easy-align-6|
  23. List of options |easy-align-6-1|
  24. Filtering lines |easy-align-6-2|
  25. Examples |easy-align-6-2-1|
  26. Ignoring delimiters in comments or strings |easy-align-6-3|
  27. Ignoring unmatched lines |easy-align-6-4|
  28. Aligning delimiters of different lengths |easy-align-6-5|
  29. Adjusting indentation |easy-align-6-6|
  30. Alignments over multiple occurrences of delimiters |easy-align-6-7|
  31. Extending alignment rules |easy-align-6-8|
  32. Examples |easy-align-6-8-1|
  33. Other options |easy-align-7|
  34. Disabling &foldmethod during alignment |easy-align-7-1|
  35. Left/right/center mode switch in interactive mode |easy-align-7-2|
  36. Advanced examples and use cases |easy-align-8|
  37. Related work |easy-align-9|
  38. Author |easy-align-10|
  39. License |easy-align-11|
  40. VIM-EASY-ALIGN *vim-easy-align*
  41. ==============================================================================
  42. A simple, easy-to-use Vim alignment plugin.
  43. *easy-align-1*
  44. DEMO *easy-align-demo*
  45. ==============================================================================
  46. Screencast:
  47. https://raw.githubusercontent.com/junegunn/i/master/vim-easy-align.gif
  48. (Too fast? Slower GIF is {here}{1})
  49. {1} https://raw.githubusercontent.com/junegunn/i/master/vim-easy-align-slow.gif
  50. *easy-align-2*
  51. FEATURES *easy-align-features*
  52. ==============================================================================
  53. - Easy to use
  54. - Comes with a predefined set of alignment rules
  55. - Provides a fast and intuitive interface
  56. - Extensible
  57. - You can define your own rules
  58. - Supports arbitrary regular expressions
  59. - Optimized for code editing
  60. - Takes advantage of syntax highlighting feature to avoid unwanted
  61. alignments
  62. *easy-align-3*
  63. INSTALLATION *easy-align-installation*
  64. ==============================================================================
  65. Use your favorite plugin manager.
  66. Using {vim-plug}{2}:
  67. >
  68. Plug 'junegunn/vim-easy-align'
  69. <
  70. {2} https://github.com/junegunn/vim-plug
  71. *easy-align-4*
  72. TLDR - ONE-MINUTE GUIDE *easy-align-tldr-one-minute-guide*
  73. ==============================================================================
  74. Add the following mappings to your .vimrc.
  75. *<Plug>(EasyAlign)*
  76. >
  77. " Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
  78. vmap <Enter> <Plug>(EasyAlign)
  79. " Start interactive EasyAlign for a motion/text object (e.g. gaip)
  80. nmap ga <Plug>(EasyAlign)
  81. <
  82. And with the following lines of text,
  83. >
  84. apple =red
  85. grass+=green
  86. sky-= blue
  87. <
  88. try these commands:
  89. - vip<Enter>=
  90. - `v`isual-select `i`nner `p`aragraph
  91. - Start EasyAlign command (<Enter>)
  92. - Align around `=`
  93. - `gaip=`
  94. - Start EasyAlign command (`ga`) for `i`nner `p`aragraph
  95. - Align around `=`
  96. Notice that the commands are repeatable with `.` key if you have installed
  97. {repeat.vim}{3}. Install {visualrepeat}{4} as well if you want to repeat in
  98. visual mode.
  99. {3} https://github.com/tpope/vim-repeat
  100. {4} https://github.com/vim-scripts/visualrepeat
  101. *easy-align-5*
  102. USAGE *easy-align-usage*
  103. ==============================================================================
  104. < Concept of alignment rule >_________________________________________________~
  105. *easy-align-concept-of-alignment-rule*
  106. *easy-align-5-1*
  107. Though easy-align can align lines of text around any delimiter, it provides
  108. shortcuts for the most common use cases with the concept of "alignment rule".
  109. An alignment rule is a predefined set of options for common alignment tasks,
  110. which is identified by a single character, DELIMITER KEY, such as <Space>,
  111. `=`, `:`, `.`, `|`, `&`, `#`, and `,`.
  112. Think of it as a shortcut. Instead of writing regular expression and setting
  113. several options, you can just type in a single character.
  114. < Execution models >__________________________________________________________~
  115. *easy-align-execution-models*
  116. *easy-align-5-2*
  117. There are two ways to use easy-align.
  118. 1. Using <Plug> mappings~
  119. *easy-align-1-using-plug-mappings*
  120. *easy-align-5-2-1*
  121. The recommended method is to use <Plug> mappings as described earlier.
  122. *<Plug>(LiveEasyAlign)*
  123. ----------------------+--------+-----------------------------------------------------
  124. Mapping | Mode | Description ~
  125. ----------------------+--------+-----------------------------------------------------
  126. <Plug>(EasyAlign) | normal | Start interactive mode for a motion/text object
  127. <Plug>(EasyAlign) | visual | Start interactive mode for the selection
  128. <Plug>(LiveEasyAlign) | normal | Start live-interactive mode for a motion/text object
  129. <Plug>(LiveEasyAlign) | visual | Start live-interactive mode for the selection
  130. ----------------------+--------+-----------------------------------------------------
  131. 2. Using :EasyAlign command~
  132. *easy-align-2-using-easyalign-command*
  133. *easy-align-5-2-2*
  134. *:EasyAlign*
  135. If you prefer command-line or do not want to start interactive mode, you can
  136. use `:EasyAlign` command instead.
  137. *:LiveEasyAlign*
  138. -------------------------------------------+-----------------------------------------------
  139. Mode | Command ~
  140. -------------------------------------------+-----------------------------------------------
  141. Interactive mode | `:EasyAlign[!] [OPTIONS]`
  142. Live interactive mode | `:LiveEasyAlign[!] [...]`
  143. Non-interactive mode (predefined rules) | `:EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]`
  144. Non-interactive mode (regular expressions) | `:EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]`
  145. -------------------------------------------+-----------------------------------------------
  146. < Interactive mode >__________________________________________________________~
  147. *easy-align-interactive-mode*
  148. *easy-align-5-3*
  149. The following sections will assume that you have <Plug>(EasyAlign) mappings in
  150. your .vimrc as below:
  151. >
  152. " Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
  153. vmap <Enter> <Plug>(EasyAlign)
  154. " Start interactive EasyAlign for a motion/text object (e.g. gaip)
  155. nmap ga <Plug>(EasyAlign)
  156. <
  157. With these mappings, you can align text with only a few keystrokes.
  158. 1. <Enter> key in visual mode, or `ga` followed by a motion or a text object to
  159. start interactive mode
  160. 2. Optional: Enter keys to select alignment mode (left, right, or center)
  161. 3. Optional: N-th delimiter (default: 1)
  162. - `1` Around the 1st occurrences of delimiters
  163. - `2` Around the 2nd occurrences of delimiters
  164. - ...
  165. - `*` Around all occurrences of delimiters
  166. - `**` Left-right alternating alignment around all delimiters
  167. - `-` Around the last occurrences of delimiters (`-1`)
  168. - `-2` Around the second to last occurrences of delimiters
  169. - ...
  170. 4. Delimiter key (a single keystroke; <Space>, `=`, `:`, `.`, `|`, `&`, `#`, `,`)
  171. Predefined alignment rules~
  172. *easy-align-predefined-alignment-rules*
  173. *easy-align-5-3-1*
  174. --------------+--------------------------------------------------------------------
  175. Delimiter key | Description/Use cases ~
  176. --------------+--------------------------------------------------------------------
  177. <Space> | General alignment around whitespaces
  178. `=` | Operators containing equals sign ( `=` , `==,` `!=` , `+=` , `&&=` , ...)
  179. `:` | Suitable for formatting JSON or YAML
  180. `.` | Multi-line method chaining
  181. `,` | Multi-line method arguments
  182. `&` | LaTeX tables (matches `&` and `\\` )
  183. `#` | Ruby/Python comments
  184. `"` | Vim comments
  185. <Bar> | Table markdown
  186. --------------+--------------------------------------------------------------------
  187. *g:easy_align_delimiters*
  188. You can override these default rules or define your own rules with
  189. `g:easy_align_delimiters`, which will be described in {the later section}{5}.
  190. {5} https://github.com/junegunn/vim-easy-align#extending-alignment-rules
  191. Examples~
  192. *easy-align-examples*
  193. *easy-align-5-3-2*
  194. ------------------+------------------------------------+--------------------
  195. With visual map | Description | Equivalent command ~
  196. ------------------+------------------------------------+--------------------
  197. <Enter><Space> | Around 1st whitespaces | :'<,'>EasyAlign\
  198. <Enter>2<Space> | Around 2nd whitespaces | :'<,'>EasyAlign2\
  199. <Enter>-<Space> | Around the last whitespaces | :'<,'>EasyAlign-\
  200. <Enter>-2<Space> | Around the 2nd to last whitespaces | :'<,'>EasyAlign-2\
  201. <Enter>: | Around 1st colon ( `key: value` ) | :'<,'>EasyAlign:
  202. <Enter><Right>: | Around 1st colon ( `key : value` ) | :'<,'>EasyAlign:<l1
  203. <Enter>= | Around 1st operators with = | :'<,'>EasyAlign=
  204. <Enter>3= | Around 3rd operators with = | :'<,'>EasyAlign3=
  205. <Enter>*= | Around all operators with = | :'<,'>EasyAlign*=
  206. <Enter>**= | Left-right alternating around = | :'<,'>EasyAlign**=
  207. <Enter><Enter>= | Right alignment around 1st = | :'<,'>EasyAlign!=
  208. <Enter><Enter>**= | Right-left alternating around = | :'<,'>EasyAlign!**=
  209. ------------------+------------------------------------+--------------------
  210. Using regular expressions~
  211. *easy-align-using-regular-expressions*
  212. *easy-align-5-3-3*
  213. Instead of finishing the command with a predefined delimiter key, you can type
  214. in a regular expression after CTRL-/ or CTRL-X key. For example, if you want
  215. to align text around all occurrences of numbers:
  216. - <Enter>
  217. - `*`
  218. - CTRL-X
  219. - `[0-9]\+`
  220. Alignment options in interactive mode~
  221. *easy-align-alignment-options-in-interactive-mode*
  222. *easy-align-5-3-4*
  223. While in interactive mode, you can set alignment options using special
  224. shortcut keys listed below. The meaning of each option will be described in
  225. {the following sections}{6}.
  226. --------+--------------------+---------------------------------------------------
  227. Key | Option | Values ~
  228. --------+--------------------+---------------------------------------------------
  229. CTRL-F | `filter` | Input string ( `[gv]/.*/?` )
  230. CTRL-I | `indentation` | shallow, deep, none, keep
  231. CTRL-L | `left_margin` | Input number or string
  232. CTRL-R | `right_margin` | Input number or string
  233. CTRL-D | `delimiter_align` | left, center, right
  234. CTRL-U | `ignore_unmatched` | 0, 1
  235. CTRL-G | `ignore_groups` | [], ["String'], ["Comment'], ["String', "Comment']
  236. CTRL-A | `align` | Input string ( `/[lrc]+\*{0,2}/` )
  237. <Left> | `stick_to_left` | `{ 'stick_to_left': 1, 'left_margin': 0 }`
  238. <Right> | `stick_to_left` | `{ 'stick_to_left': 0, 'left_margin': 1 }`
  239. <Down> | `*_margin` | `{ 'left_margin': 0, 'right_margin': 0 }`
  240. --------+--------------------+---------------------------------------------------
  241. {6} https://github.com/junegunn/vim-easy-align#alignment-options
  242. < Live interactive mode >_____________________________________________________~
  243. *easy-align-live-interactive-mode*
  244. *easy-align-5-4*
  245. If you're performing a complex alignment where multiple options should be
  246. carefully adjusted, try "live interactive mode" where you can preview the
  247. result of the alignment on-the-fly as you type in.
  248. Live interactive mode can be started with either <Plug>(LiveEasyAlign) map or
  249. `:LiveEasyAlign` command. Or you can switch to live interactive mode while in
  250. ordinary interactive mode by pressing CTRL-P. (P for Preview)
  251. In live interactive mode, you have to type in the same delimiter (or CTRL-X on
  252. regular expression) again to finalize the alignment. This allows you to
  253. preview the result of the alignment and freely change the delimiter using
  254. backspace key without leaving the interactive mode.
  255. < Non-interactive mode >______________________________________________________~
  256. *easy-align-non-interactive-mode*
  257. *easy-align-5-5*
  258. Instead of starting interactive mode, you can use declarative, non-interactive
  259. `:EasyAlign` command.
  260. >
  261. " Using predefined alignment rules
  262. " :EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]
  263. :EasyAlign :
  264. :EasyAlign =
  265. :EasyAlign *=
  266. :EasyAlign 3\
  267. " Using arbitrary regular expressions
  268. " :EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]
  269. :EasyAlign /[:;]\+/
  270. :EasyAlign 2/[:;]\+/
  271. :EasyAlign */[:;]\+/
  272. :EasyAlign **/[:;]\+/
  273. <
  274. A command can end with alignment options, {each of which will be discussed in
  275. detail later}{6}, in Vim dictionary format.
  276. - `:EasyAlign * /[:;]\+/ { 'stick_to_left': 1, 'left_margin': 0 }`
  277. `stick_to_left` of 1 means that the matched delimiter should be positioned
  278. right next to the preceding token, and `left_margin` of 0 removes the margin
  279. on the left. So we get:
  280. >
  281. apple;: banana:: cake
  282. data;; exchange:; format
  283. <
  284. Option names are fuzzy-matched, so you can write as follows:
  285. - `:EasyAlign * /[:;]\+/ { 'stl': 1, 'l': 0 }`
  286. You can even omit spaces between the arguments, so concisely (or cryptically):
  287. - `:EasyAlign*/[:;]\+/{'s':1,'l':0}`
  288. Nice. But let's make it even shorter. Option values can be written in
  289. shorthand notation.
  290. - `:EasyAlign*/[:;]\+/<l0`
  291. The following table summarizes the shorthand notation.
  292. -------------------+-----------
  293. Option | Expression~
  294. -------------------+-----------
  295. `filter` | `[gv]/.*/`
  296. `left_margin` | `l[0-9]+`
  297. `right_margin` | `r[0-9]+`
  298. `stick_to_left` | `<` or `>`
  299. `ignore_unmatched` | `iu[01]`
  300. `ignore_groups` | `ig\[.*\]`
  301. `align` | `a[lrc*]*`
  302. `delimiter_align` | `d[lrc]`
  303. `indentation` | `i[ksdn]`
  304. -------------------+-----------
  305. For your information, the same operation can be done in interactive mode as
  306. follows:
  307. - <Enter>
  308. - `*`
  309. - <Left>
  310. - CTRL-X
  311. - `[:;]\+`
  312. {6} https://github.com/junegunn/vim-easy-align#alignment-options
  313. < Partial alignment in blockwise-visual mode >________________________________~
  314. *easy-align-partial-alignment-in-blockwise-visual-mode*
  315. *easy-align-5-6*
  316. In blockwise-visual mode (CTRL-V), EasyAlign command aligns only the selected
  317. text in the block, instead of the whole lines in the range.
  318. Consider the following case where you want to align text around `=>`
  319. operators.
  320. >
  321. my_hash = { :a => 1,
  322. :aa => 2,
  323. :aaa => 3 }
  324. <
  325. In non-blockwise visual mode (`v` / `V`), <Enter>= won't work since the
  326. assignment operator in the first line gets in the way. So we instead enter
  327. blockwise-visual mode (CTRL-V), and select the text around`=>` operators, then
  328. press <Enter>=.
  329. >
  330. my_hash = { :a => 1,
  331. :aa => 2,
  332. :aaa => 3 }
  333. <
  334. However, in this case, we don't really need blockwise visual mode since the
  335. same can be easily done using the negative N-th parameter: <Enter>-=
  336. *easy-align-6*
  337. ALIGNMENT OPTIONS *easy-align-alignment-options*
  338. ==============================================================================
  339. < List of options >___________________________________________________________~
  340. *easy-align-list-of-options*
  341. *easy-align-6-1*
  342. -------------------+---------+-----------------------+--------------------------------------------------------
  343. Option | Type | Default | Description ~
  344. -------------------+---------+-----------------------+--------------------------------------------------------
  345. `filter` | string | | Line filtering expression: `g/../` or `v/../`
  346. `left_margin` | number | 1 | Number of spaces to attach before delimiter
  347. `left_margin` | string | `' '` | String to attach before delimiter
  348. `right_margin` | number | 1 | Number of spaces to attach after delimiter
  349. `right_margin` | string | `' '` | String to attach after delimiter
  350. `stick_to_left` | boolean | 0 | Whether to position delimiter on the left-side
  351. `ignore_groups` | list | ["String', "Comment'] | Delimiters in these syntax highlight groups are ignored
  352. `ignore_unmatched` | boolean | 1 | Whether to ignore lines without matching delimiter
  353. `indentation` | string | `k` | Indentation method (keep, deep, shallow, none)
  354. `delimiter_align` | string | `r` | Determines how to align delimiters of different lengths
  355. `align` | string | `l` | Alignment modes for multiple occurrences of delimiters
  356. -------------------+---------+-----------------------+--------------------------------------------------------
  357. There are 4 ways to set alignment options (from lowest precedence to highest):
  358. 1. Some option values can be set with corresponding global variables
  359. 2. Option values can be specified in the definition of each alignment rule
  360. 3. Option values can be given as arguments to `:EasyAlign` command
  361. 4. Option values can be set in interactive mode using special shortcut keys
  362. *g:easy_align_ignore_groups* *g:easy_align_ignore_unmatched*
  363. *g:easy_align_indentation* *g:easy_align_delimiter_align*
  364. -------------------+-----------------+-------------+--------------------------------
  365. Option name | Shortcut key | Abbreviated | Global variable ~
  366. -------------------+-----------------+-------------+--------------------------------
  367. `filter` | CTRL-F | `[gv]/.*/` |
  368. `left_margin` | CTRL-L | `l[0-9]+` |
  369. `right_margin` | CTRL-R | `r[0-9]+` |
  370. `stick_to_left` | <Left>, <Right> | `<` or `>` |
  371. `ignore_groups` | CTRL-G | `ig\[.*\]` | `g:easy_align_ignore_groups`
  372. `ignore_unmatched` | CTRL-U | `iu[01]` | `g:easy_align_ignore_unmatched`
  373. `indentation` | CTRL-I | `i[ksdn]` | `g:easy_align_indentation`
  374. `delimiter_align` | CTRL-D | `d[lrc]` | `g:easy_align_delimiter_align`
  375. `align` | CTRL-A | `a[lrc*]*` |
  376. -------------------+-----------------+-------------+--------------------------------
  377. < Filtering lines >___________________________________________________________~
  378. *easy-align-filtering-lines*
  379. *easy-align-6-2*
  380. With `filter` option, you can align lines that only match or do not match a
  381. given pattern. There are several ways to set the pattern.
  382. 1. Press CTRL-F in interactive mode and type in `g/pat/` or `v/pat/`
  383. 2. In command-line, it can be written in dictionary format: `{'filter':
  384. 'g/pat/'}`
  385. 3. Or in shorthand notation: `g/pat/` or `v/pat/`
  386. (You don't need to escape "/'s in the regular expression)
  387. Examples~
  388. *easy-align-6-2-1*
  389. >
  390. " Start interactive mode with filter option set to g/hello/
  391. EasyAlign g/hello/
  392. " Start live interactive mode with filter option set to v/goodbye/
  393. LiveEasyAlign v/goodbye/
  394. " Align the lines with 'hi' around the first colons
  395. EasyAlign:g/hi/
  396. <
  397. < Ignoring delimiters in comments or strings >________________________________~
  398. *easy-align-ignoring-delimiters-in-comments-or-strings*
  399. *easy-align-6-3*
  400. EasyAlign can be configured to ignore delimiters in certain syntax highlight
  401. groups, such as code comments or strings. By default, delimiters that are
  402. highlighted as code comments or strings are ignored.
  403. >
  404. " Default:
  405. " If a delimiter is in a highlight group whose name matches
  406. " any of the following regular expressions, it will be ignored.
  407. let g:easy_align_ignore_groups = ['Comment', 'String']
  408. <
  409. For example, the following paragraph
  410. >
  411. {
  412. # Quantity of apples: 1
  413. apple: 1,
  414. # Quantity of bananas: 2
  415. bananas: 2,
  416. # Quantity of grape:fruits: 3
  417. 'grape:fruits': 3
  418. }
  419. <
  420. becomes as follows on <Enter>: (or `:EasyAlign:`)
  421. >
  422. {
  423. # Quantity of apples: 1
  424. apple: 1,
  425. # Quantity of bananas: 2
  426. bananas: 2,
  427. # Quantity of grape:fruits: 3
  428. 'grape:fruits': 3
  429. }
  430. <
  431. Naturally, this feature only works when syntax highlighting is enabled.
  432. You can change the default rule by using one of these 4 methods.
  433. 1. Press CTRL-G in interactive mode to switch groups
  434. 2. Define global `g:easy_align_ignore_groups` list
  435. 3. Define a custom rule in `g:easy_align_delimiters` with `ignore_groups` option
  436. 4. Provide `ignore_groups` option to `:EasyAlign` command. e.g. `:EasyAlign:ig[]`
  437. For example if you set `ignore_groups` option to be an empty list, you get
  438. >
  439. {
  440. # Quantity of apples: 1
  441. apple: 1,
  442. # Quantity of bananas: 2
  443. bananas: 2,
  444. # Quantity of grape: fruits: 3
  445. 'grape: fruits': 3
  446. }
  447. <
  448. If a pattern in `ignore_groups` is prepended by a `!`, it will have the
  449. opposite meaning. For instance, if `ignore_groups` is given as `['!Comment']`,
  450. delimiters that are not highlighted as Comment will be ignored during the
  451. alignment.
  452. To make `ignore_groups` work, and to debug the related issues, it is useful to
  453. know which highlight group a certain location in a file belongs to. A special
  454. function exists for this purpose, returning exactly the name of the highlight
  455. group that is used by the easy align plugin.
  456. >
  457. " Highlight group name of the cursor position
  458. echo easy_align#get_highlight_group_name()
  459. " Highlight group name of the line 10, column 20
  460. echo easy_align#get_highlight_group_name(10, 20)
  461. <
  462. < Ignoring unmatched lines >__________________________________________________~
  463. *easy-align-ignoring-unmatched-lines*
  464. *easy-align-6-4*
  465. `ignore_unmatched` option determines how EasyAlign command processes lines
  466. that do not have N-th delimiter.
  467. 1. In left-alignment mode, they are ignored
  468. 2. In right or center-alignment mode, they are not ignored, and the last tokens
  469. from those lines are aligned as well as if there is an invisible trailing
  470. delimiter at the end of each line
  471. 3. If `ignore_unmatched` is 1, they are ignored regardless of the alignment mode
  472. 4. If `ignore_unmatched` is 0, they are not ignored regardless of the mode
  473. Let's take an example. When we align the following code block around the (1st)
  474. colons,
  475. >
  476. {
  477. apple: proc {
  478. this_line_does_not_have_a_colon
  479. },
  480. bananas: 2,
  481. grapefruits: 3
  482. }
  483. <
  484. this is usually what we want.
  485. >
  486. {
  487. apple: proc {
  488. this_line_does_not_have_a_colon
  489. },
  490. bananas: 2,
  491. grapefruits: 3
  492. }
  493. <
  494. However, we can override this default behavior by setting `ignore_unmatched`
  495. option to zero using one of the following methods.
  496. 1. Press CTRL-U in interactive mode to toggle `ignore_unmatched` option
  497. 2. Set the global `g:easy_align_ignore_unmatched` variable to 0
  498. 3. Define a custom alignment rule with `ignore_unmatched` option set to 0
  499. 4. Provide `ignore_unmatched` option to `:EasyAlign` command. e.g.
  500. `:EasyAlign:iu0`
  501. Then we get,
  502. >
  503. {
  504. apple: proc {
  505. this_line_does_not_have_a_colon
  506. },
  507. bananas: 2,
  508. grapefruits: 3
  509. }
  510. <
  511. < Aligning delimiters of different lengths >__________________________________~
  512. *easy-align-aligning-delimiters-of-different-lengths*
  513. *easy-align-6-5*
  514. Global `g:easy_align_delimiter_align` option and rule-wise/command-wise
  515. `delimiter_align` option determines how matched delimiters of different
  516. lengths are aligned.
  517. >
  518. apple = 1
  519. banana += apple
  520. cake ||= banana
  521. <
  522. By default, delimiters are right-aligned as follows.
  523. >
  524. apple = 1
  525. banana += apple
  526. cake ||= banana
  527. <
  528. However, with `:EasyAlign=dl`, delimiters are left-aligned.
  529. >
  530. apple = 1
  531. banana += apple
  532. cake ||= banana
  533. <
  534. And on `:EasyAlign=dc`, center-aligned.
  535. >
  536. apple = 1
  537. banana += apple
  538. cake ||= banana
  539. <
  540. In interactive mode, you can change the option value with CTRL-D key.
  541. < Adjusting indentation >_____________________________________________________~
  542. *easy-align-adjusting-indentation*
  543. *easy-align-6-6*
  544. By default :EasyAlign command keeps the original indentation of the lines. But
  545. then again we have `indentation` option. See the following example.
  546. >
  547. # Lines with different indentation
  548. apple = 1
  549. banana = 2
  550. cake = 3
  551. daisy = 4
  552. eggplant = 5
  553. # Default: _k_eep the original indentation
  554. # :EasyAlign=
  555. apple = 1
  556. banana = 2
  557. cake = 3
  558. daisy = 4
  559. eggplant = 5
  560. # Use the _s_hallowest indentation among the lines
  561. # :EasyAlign=is
  562. apple = 1
  563. banana = 2
  564. cake = 3
  565. daisy = 4
  566. eggplant = 5
  567. # Use the _d_eepest indentation among the lines
  568. # :EasyAlign=id
  569. apple = 1
  570. banana = 2
  571. cake = 3
  572. daisy = 4
  573. eggplant = 5
  574. # Indentation: _n_one
  575. # :EasyAlign=in
  576. apple = 1
  577. banana = 2
  578. cake = 3
  579. daisy = 4
  580. eggplant = 5
  581. <
  582. In interactive mode, you can change the option value with CTRL-I key.
  583. < Alignments over multiple occurrences of delimiters >________________________~
  584. *easy-align-alignments-over-multiple-occurrences-of-delimiters*
  585. *easy-align-6-7*
  586. As stated above, "N-th" parameter is used to target specific occurrences of
  587. the delimiter when it appears multiple times in each line.
  588. To recap:
  589. >
  590. " Left-alignment around the FIRST occurrences of delimiters
  591. :EasyAlign =
  592. " Left-alignment around the SECOND occurrences of delimiters
  593. :EasyAlign 2=
  594. " Left-alignment around the LAST occurrences of delimiters
  595. :EasyAlign -=
  596. " Left-alignment around ALL occurrences of delimiters
  597. :EasyAlign *=
  598. " Left-right ALTERNATING alignment around all occurrences of delimiters
  599. :EasyAlign **=
  600. " Right-left ALTERNATING alignment around all occurrences of delimiters
  601. :EasyAlign! **=
  602. <
  603. In addition to these, you can fine-tune alignments over multiple occurrences
  604. of the delimiters with "align' option. (The option can also be set in
  605. interactive mode with the special key CTRL-A)
  606. >
  607. " Left alignment over the first two occurrences of delimiters
  608. :EasyAlign = { 'align': 'll' }
  609. " Right, left, center alignment over the 1st to 3rd occurrences of delimiters
  610. :EasyAlign = { 'a': 'rlc' }
  611. " Using shorthand notation
  612. :EasyAlign = arlc
  613. " Right, left, center alignment over the 2nd to 4th occurrences of delimiters
  614. :EasyAlign 2=arlc
  615. " (*) Repeating alignments (default: l, r, or c)
  616. " Right, left, center, center, center, center, ...
  617. :EasyAlign *=arlc
  618. " (**) Alternating alignments (default: lr or rl)
  619. " Right, left, center, right, left, center, ...
  620. :EasyAlign **=arlc
  621. " Right, left, center, center, center, ... repeating alignment
  622. " over the 3rd to the last occurrences of delimiters
  623. :EasyAlign 3=arlc*
  624. " Right, left, center, right, left, center, ... alternating alignment
  625. " over the 3rd to the last occurrences of delimiters
  626. :EasyAlign 3=arlc**
  627. <
  628. < Extending alignment rules >_________________________________________________~
  629. *easy-align-extending-alignment-rules*
  630. *easy-align-6-8*
  631. Although the default rules should cover the most of the use cases, you can
  632. extend the rules by setting a dictionary named `g:easy_align_delimiters`.
  633. You may refer to the definitions of the default alignment rules {here}{7}.
  634. {7} https://github.com/junegunn/vim-easy-align/blob/2.9.6/autoload/easy_align.vim#L32-L46
  635. Examples~
  636. *easy-align-6-8-1*
  637. >
  638. let g:easy_align_delimiters = {
  639. \ '>': { 'pattern': '>>\|=>\|>' },
  640. \ '/': {
  641. \ 'pattern': '//\+\|/\*\|\*/',
  642. \ 'delimiter_align': 'l',
  643. \ 'ignore_groups': ['!Comment'] },
  644. \ ']': {
  645. \ 'pattern': '[[\]]',
  646. \ 'left_margin': 0,
  647. \ 'right_margin': 0,
  648. \ 'stick_to_left': 0
  649. \ },
  650. \ ')': {
  651. \ 'pattern': '[()]',
  652. \ 'left_margin': 0,
  653. \ 'right_margin': 0,
  654. \ 'stick_to_left': 0
  655. \ },
  656. \ 'd': {
  657. \ 'pattern': ' \(\S\+\s*[;=]\)\@=',
  658. \ 'left_margin': 0,
  659. \ 'right_margin': 0
  660. \ }
  661. \ }
  662. <
  663. *easy-align-7*
  664. OTHER OPTIONS *easy-align-other-options*
  665. ==============================================================================
  666. < Disabling &foldmethod during alignment >____________________________________~
  667. *easy-align-disabling-foldmethod-during-alignment*
  668. *easy-align-7-1*
  669. *g:easy_align_bypass_fold*
  670. {It is reported}{8} that 'foldmethod' value of `expr` or `syntax` can
  671. significantly slow down the alignment when editing a large, complex file with
  672. many folds. To alleviate this issue, EasyAlign provides an option to
  673. temporarily set 'foldmethod' to `manual` during the alignment task. In order
  674. to enable this feature, set `g:easy_align_bypass_fold` switch to 1.
  675. >
  676. let g:easy_align_bypass_fold = 1
  677. <
  678. {8} https://github.com/junegunn/vim-easy-align/issues/14
  679. < Left/right/center mode switch in interactive mode >_________________________~
  680. *easy-align-left-right-center-mode-switch-in-interactive-mode*
  681. *easy-align-7-2*
  682. In interactive mode, you can choose the alignment mode you want by pressing
  683. enter keys. The non-bang command, `:EasyAlign` starts in left-alignment mode
  684. and changes to right and center mode as you press enter keys, while the bang
  685. version first starts in right-alignment mode.
  686. - `:EasyAlign`
  687. - Left, Right, Center
  688. - `:EasyAlign!`
  689. - Right, Left, Center
  690. If you do not prefer this default mode transition, you can define your own
  691. settings as follows.
  692. *g:easy_align_interactive_modes* *g:easy_align_bang_interactive_modes*
  693. >
  694. let g:easy_align_interactive_modes = ['l', 'r']
  695. let g:easy_align_bang_interactive_modes = ['c', 'r']
  696. <
  697. *easy-align-8*
  698. ADVANCED EXAMPLES AND USE CASES *easy-align-advanced-examples-and-use-cases*
  699. ==============================================================================
  700. See {EXAMPLES.md}{9} for more examples.
  701. {9} https://github.com/junegunn/vim-easy-align/blob/master/EXAMPLES.md
  702. *easy-align-9*
  703. RELATED WORK *easy-align-related-work*
  704. ==============================================================================
  705. - {DrChip's Alignment Tool for Vim}{10}
  706. - {Tabular}{11}
  707. {10} http://www.drchip.org/astronaut/vim/align.html
  708. {11} https://github.com/godlygeek/tabular
  709. *easy-align-10*
  710. AUTHOR *easy-align-author*
  711. ==============================================================================
  712. {Junegunn Choi}{12}
  713. {12} https://github.com/junegunn
  714. *easy-align-11*
  715. LICENSE *easy-align-license*
  716. ==============================================================================
  717. MIT
  718. ==============================================================================
  719. vim:tw=78:sw=2:ts=2:ft=help:norl:nowrap: