Convert Figma logo to code with AI

junegunn logovim-easy-align

:sunflower: A Vim alignment plugin

4,156
121
4,156
27

Top Related Projects

2,630

Vim script for text filtering and alignment

A vim plugin to display the indention levels with thin vertical lines

Switch between single-line and multiline forms of code

VIM Table Mode for instant table creation.

Quick Overview

The vim-easy-align project is a Vim plugin that provides a simple and intuitive way to align text based on a given character or pattern. It allows users to quickly and easily align text in various formats, such as tables, code, and more, making it a valuable tool for developers and writers who work extensively with text.

Pros

  • Intuitive Alignment: The plugin provides a straightforward and user-friendly interface for aligning text, making it easy to use even for those new to Vim.
  • Flexible Alignment Patterns: The plugin supports a wide range of alignment patterns, allowing users to customize the alignment to their specific needs.
  • Efficient Workflow: The plugin can significantly improve the efficiency of text alignment tasks, saving users time and effort.
  • Integrates Well with Vim: The plugin is designed to seamlessly integrate with the Vim editor, providing a consistent and familiar user experience.

Cons

  • Learning Curve: While the plugin is relatively easy to use, it may have a slight learning curve for users who are new to Vim or text alignment tools.
  • Limited Functionality: The plugin is focused on text alignment and may not provide the full range of features found in more comprehensive text manipulation tools.
  • Potential Compatibility Issues: As with any Vim plugin, there is a possibility of compatibility issues with certain Vim configurations or other plugins.
  • Lack of Visual Feedback: The plugin does not provide real-time visual feedback during the alignment process, which may be a drawback for some users.

Code Examples

The vim-easy-align plugin is a Vim plugin, so it does not provide any standalone code examples. However, here are a few examples of how to use the plugin within a Vim environment:

  1. Aligning Text by a Specific Character:
:EasyAlign*<character>

This command will align the text around the specified <character>.

  1. Aligning Text by a Regular Expression:
:EasyAlign/<regular-expression>

This command will align the text based on the provided regular expression.

  1. Aligning Text in a Visual Selection:
vip:EasyAlign*<character>

This command will align the text within the current visual selection based on the specified <character>.

  1. Aligning Text with Interactive Mode:
:EasyAlign

This command will enter the interactive mode, allowing you to specify the alignment character or pattern interactively.

Getting Started

To get started with the vim-easy-align plugin, follow these steps:

  1. Install the plugin using your preferred Vim plugin manager. For example, with vim-plug, add the following line to your Vim configuration file:

    Plug 'junegunn/vim-easy-align'
    
  2. After installing the plugin, you can start using it by invoking the various alignment commands. For example, to align text around a specific character, use the following command:

    :EasyAlign*<character>
    

    Replace <character> with the character you want to align the text around.

  3. You can also use the interactive mode to specify the alignment pattern:

    :EasyAlign
    

    This will prompt you to enter the alignment pattern, and the plugin will then align the text accordingly.

  4. For more advanced usage, you can refer to the plugin's documentation, which provides detailed information on the available commands, options, and customization possibilities.

Competitor Comparisons

2,630

Vim script for text filtering and alignment

Pros of Tabular

  • More established and widely used in the Vim community
  • Offers more complex alignment patterns and options
  • Supports custom alignment patterns using regular expressions

Cons of Tabular

  • Less intuitive syntax for basic alignment tasks
  • Slower performance for large files or complex alignments
  • Lacks interactive mode for real-time alignment preview

Code Comparison

Tabular:

:Tabularize /,/r0c1l1

vim-easy-align:

:EasyAlign *,

Both plugins aim to simplify text alignment in Vim, but they differ in approach and complexity. Tabular offers more advanced features and customization options, making it suitable for complex alignment tasks. However, this comes at the cost of a steeper learning curve and potentially slower performance.

vim-easy-align, on the other hand, provides a more straightforward and intuitive interface for basic alignment needs. It also includes an interactive mode, allowing users to preview alignments in real-time. While it may not offer as many advanced features as Tabular, its simplicity and ease of use make it an attractive option for many users.

Ultimately, the choice between these plugins depends on the user's specific needs and preferences. Those requiring advanced alignment capabilities may prefer Tabular, while users seeking a simpler, more user-friendly solution might lean towards vim-easy-align.

A vim plugin to display the indention levels with thin vertical lines

Pros of indentLine

  • Provides visual guides for indentation levels, improving code readability
  • Supports customization of indent line characters and colors
  • Works automatically without manual intervention

Cons of indentLine

  • Limited to indentation visualization, lacks text alignment features
  • May slightly impact performance in large files with many indentation levels
  • Can interfere with some syntax highlighting in certain file types

Code Comparison

indentLine:

let g:indentLine_char = '┊'
let g:indentLine_color_term = 239
let g:indentLine_enabled = 1

vim-easy-align:

" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)

While indentLine focuses on visualizing indentation levels, vim-easy-align provides powerful text alignment capabilities. indentLine operates passively, enhancing code readability without user input. In contrast, vim-easy-align requires manual activation but offers precise control over text alignment. The code snippets demonstrate the configuration simplicity of indentLine versus the key mapping setup for vim-easy-align's interactive mode.

Switch between single-line and multiline forms of code

Pros of splitjoin.vim

  • Focuses on splitting and joining code structures, which is more specific and potentially useful for certain coding tasks
  • Supports a wide range of programming languages and file types
  • Offers more complex transformations, such as converting single-line function calls to multi-line and vice versa

Cons of splitjoin.vim

  • Less versatile for general text alignment tasks compared to vim-easy-align
  • May require more learning and configuration to use effectively across different languages
  • Limited to splitting and joining operations, while vim-easy-align can handle various alignment scenarios

Code Comparison

splitjoin.vim:

" Split a single-line function call
let result = myFunction(arg1, arg2, arg3)

" After splitting
let result = myFunction(
    arg1,
    arg2,
    arg3
)

vim-easy-align:

" Align text around '='
let x = 1
let foo = 100
let baz = 1000

" After alignment
let x   = 1
let foo = 100
let baz = 1000

VIM Table Mode for instant table creation.

Pros of vim-table-mode

  • Specialized for creating and manipulating tables in Vim
  • Automatic table formatting and alignment
  • Supports various table styles (e.g., markdown, reStructuredText)

Cons of vim-table-mode

  • Limited to table-specific operations
  • May have a steeper learning curve for users unfamiliar with table syntax

Code Comparison

vim-table-mode:

:TableModeEnable
| Header 1 | Header 2 |
| Cell 1   | Cell 2   |

vim-easy-align:

:EasyAlign *|
Header 1 | Header 2
Cell 1 | Cell 2

Key Differences

  • vim-table-mode focuses on table creation and manipulation, while vim-easy-align is a more general-purpose alignment tool
  • vim-easy-align can align various types of content, not just tables
  • vim-table-mode offers more table-specific features like cell navigation and formula calculations

Use Cases

  • vim-table-mode: Ideal for users who frequently work with tables in text documents
  • vim-easy-align: Better suited for general text alignment tasks and occasional table formatting

Community and Maintenance

  • Both plugins are actively maintained and have a significant user base
  • vim-easy-align has more stars and forks on GitHub, indicating wider adoption

Integration

  • vim-table-mode works well with other table-related plugins
  • vim-easy-align can be easily integrated into existing workflows for various alignment tasks

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

vim-easy-align travis-ci

A simple, easy-to-use Vim alignment plugin.

Installation

Use your favorite plugin manager.

Using vim-plug:

Plug 'junegunn/vim-easy-align'

Quick start guide

Add the following mappings to your .vimrc.

" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)

" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)

Then with the following lines of text,

apple   =red
grass+=green
sky-=   blue

try these commands:

  • vipga=
    • visual-select inner paragraph
    • Start EasyAlign command (ga)
    • Align around =
  • gaip=
    • Start EasyAlign command (ga) for inner paragraph
    • Align around =

Demo

Click on each image to see from the beginning.

Using predefined alignment rules

An alignment rule is a predefined set of options for common alignment tasks, which is identified by a single character, such as <Space>, =, :, ., |, &, #, and ,.

=

  • = Around the 1st occurrences
  • 2= Around the 2nd occurrences
  • *= Around all occurrences
  • **= Left/Right alternating alignment around all occurrences
  • <Enter> Switching between left/right/center alignment modes

<Space>

  • <Space> Around the 1st occurrences of whitespaces
  • 2<Space> Around the 2nd occurrences
  • -<Space> Around the last occurrences
  • <Enter><Enter>2<Space> Center-alignment around the 2nd occurrences

,

  • The predefined comma-rule places a comma right next to the preceding token without margin ({'stick_to_left': 1, 'left_margin': 0})
  • You can change it with <Right> arrow

Using regular expression

You can use an arbitrary regular expression by

  • pressing <Ctrl-X> in interactive mode
  • or using :EasyAlign /REGEX/ command in visual mode or in normal mode with a range (e.g. :%)

Different ways to start

This demo shows how you can start interactive mode with visual selection or use non-interactive :EasyAlign command.

Aligning table cells

Check out various alignment options and "live interactive mode".

Syntax-aware alignment

Delimiters in strings and comments are ignored by default.

Using blockwise-visual mode

You can limit the scope with blockwise-visual mode.

Usage

Flow of execution

There are two ways to use easy-align.

1. <Plug> mappings (interactive mode)

The recommended method is to use <Plug>(EasyAlign) mapping in normal and visual mode. They are usually mapped to ga, but you can choose any key sequences.

nmap ga <Plug>(EasyAlign)
xmap ga <Plug>(EasyAlign)
  1. ga key in visual mode, or ga followed by a motion or a text object to start interactive mode
  2. (Optional) Enter keys to cycle between alignment mode (left, right, or center)
  3. (Optional) N-th delimiter (default: 1)
    • 1 Around the 1st occurrences of delimiters
    • 2 Around the 2nd occurrences of delimiters
    • ...
    • * Around all occurrences of delimiters
    • ** Left-right alternating alignment around all delimiters
    • - Around the last occurrences of delimiters (-1)
    • -2 Around the second to last occurrences of delimiters
    • ...
  4. Delimiter key (a single keystroke; <Space>, =, :, ., |, &, #, ,) or an arbitrary regular expression followed by <CTRL-X>

2. Using :EasyAlign command

If you prefer command-line, use :EasyAlign command instead.

" Using predefined rules
:EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]

" Using regular expression
:EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]

Regular expression vs. predefined rules

You can use regular expressions but it's usually much easier to use predefined alignment rules that you can trigger with a single keystroke.

KeyDescription/Use cases
<Space>General alignment around whitespaces
=Operators containing equals sign (=, ==, !=, +=, &&=, ...)
:Suitable for formatting JSON or YAML
.Multi-line method chaining
,Multi-line method arguments
&LaTeX tables (matches & and \\)
#Ruby/Python comments
"Vim comments
<Bar>Table markdown

You can also define your own rules with g:easy_align_delimiters which will be described in the later section.


Interactive mode

Interactive mode is started either with <Plug>(EasyAlign) mapping or with :EasyAlign command with no argument.

Examples using predefined rules

KeystrokesDescriptionEquivalent command
<Space>Around 1st whitespaces:'<,'>EasyAlign\
2<Space>Around 2nd whitespaces:'<,'>EasyAlign2\
-<Space>Around the last whitespaces:'<,'>EasyAlign-\
-2<Space>Around the 2nd to last whitespaces:'<,'>EasyAlign-2\
:Around 1st colon (key: value):'<,'>EasyAlign:
<Right>:Around 1st colon (key : value):'<,'>EasyAlign:>l1
=Around 1st operators with =:'<,'>EasyAlign=
3=Around 3rd operators with =:'<,'>EasyAlign3=
*=Around all operators with =:'<,'>EasyAlign*=
**=Left-right alternating around =:'<,'>EasyAlign**=
<Enter>=Right alignment around 1st =:'<,'>EasyAlign!=
<Enter>**=Right-left alternating around =:'<,'>EasyAlign!**=

Instead of finishing the alignment with a delimiter key, you can type in a regular expression if you press <CTRL-/> or <CTRL-X>.

Alignment options in interactive mode

While in interactive mode, you can set alignment options using special shortcut keys listed below. The meaning of each option will be described in the following sections.

KeyOptionValues
CTRL-FfilterInput string ([gv]/.*/?)
CTRL-Iindentationshallow, deep, none, keep
CTRL-Lleft_marginInput number or string
CTRL-Rright_marginInput number or string
CTRL-Ddelimiter_alignleft, center, right
CTRL-Uignore_unmatched0, 1
CTRL-Gignore_groups[], ['String'], ['Comment'], ['String', 'Comment']
CTRL-AalignInput string (/[lrc]+\*{0,2}/)
<Left>stick_to_left{ 'stick_to_left': 1, 'left_margin': 0 }
<Right>stick_to_left{ 'stick_to_left': 0, 'left_margin': 1 }
<Down>*_margin{ 'left_margin': 0, 'right_margin': 0 }

Live interactive mode

If you're performing a complex alignment where multiple options should be carefully adjusted, try "live interactive mode" where you can preview the result of the alignment on-the-fly as you type in.

Live interactive mode can be started with either <Plug>(LiveEasyAlign) map or :LiveEasyAlign command. Or you can switch to live interactive mode while in ordinary interactive mode by pressing <CTRL-P>. (P for Preview)

In live interactive mode, you have to type in the same delimiter (or <CTRL-X> on regular expression) again to finalize the alignment. This allows you to preview the result of the alignment and freely change the delimiter using backspace key without leaving the interactive mode.

:EasyAlign command

Instead of starting interactive mode, you can use non-interactive :EasyAlign command.

" Using predefined alignment rules
"   :EasyAlign[!] [N-th] DELIMITER_KEY [OPTIONS]
:EasyAlign :
:EasyAlign =
:EasyAlign *=
:EasyAlign 3\

" Using arbitrary regular expressions
"   :EasyAlign[!] [N-th] /REGEXP/ [OPTIONS]
:EasyAlign /[:;]\+/
:EasyAlign 2/[:;]\+/
:EasyAlign */[:;]\+/
:EasyAlign **/[:;]\+/

A command can end with alignment options, each of which will be discussed in detail later, in Vim dictionary format.

  • :EasyAlign * /[:;]\+/ { 'stick_to_left': 1, 'left_margin': 0 }

stick_to_left of 1 means that the matched delimiter should be positioned right next to the preceding token, and left_margin of 0 removes the margin on the left. So we get:

apple;: banana::   cake
data;;  exchange:; format

You don't have to write complete names as long as they're distinguishable.

  • :EasyAlign * /[:;]\+/ { 'stl': 1, 'l': 0 }

You can even omit spaces between the arguments.

  • :EasyAlign*/[:;]\+/{'s':1,'l':0}

Nice. But let's make it even shorter. Option values can be written in shorthand notation.

  • :EasyAlign*/[:;]\+/<l0

The following table summarizes the shorthand notation.

OptionExpression
filter[gv]/.*/
left_marginl[0-9]+
right_marginr[0-9]+
stick_to_left< or >
ignore_unmatchediu[01]
ignore_groupsig\[.*\]
aligna[lrc*]*
delimiter_alignd[lrc]
indentationi[ksdn]

Partial alignment in blockwise-visual mode

In blockwise-visual mode (CTRL-V), EasyAlign command aligns only the selected text in the block, instead of the whole lines in the range.

Consider the following case where you want to align text around => operators.

my_hash = { :a => 1,
            :aa => 2,
            :aaa => 3 }

In non-blockwise visual mode (v / V), <Enter>= won't work since the assignment operator in the first line gets in the way. So we instead enter blockwise-visual mode (CTRL-V), and select the text around => operators, then press <Enter>=.

my_hash = { :a   => 1,
            :aa  => 2,
            :aaa => 3 }

However, in this case, we don't really need blockwise visual mode since the same can be easily done using the negative N-th parameter: <Enter>-=

Alignment options

List of options

OptionTypeDefaultDescription
filterstringLine filtering expression: g/../ or v/../
left_marginnumber1Number of spaces to attach before delimiter
left_marginstring' 'String to attach before delimiter
right_marginnumber1Number of spaces to attach after delimiter
right_marginstring' 'String to attach after delimiter
stick_to_leftboolean0Whether to position delimiter on the left-side
ignore_groupslist['String', 'Comment']Delimiters in these syntax highlight groups are ignored
ignore_unmatchedboolean1Whether to ignore lines without matching delimiter
indentationstringkIndentation method (keep, deep, shallow, none)
delimiter_alignstringrDetermines how to align delimiters of different lengths
alignstringlAlignment modes for multiple occurrences of delimiters

There are 4 ways to set alignment options (from lowest precedence to highest):

  1. Some option values can be set with corresponding global variables
  2. Option values can be specified in the definition of each alignment rule
  3. Option values can be given as arguments to :EasyAlign command
  4. Option values can be set in interactive mode using special shortcut keys
Option nameShortcut keyAbbreviatedGlobal variable
filterCTRL-F[gv]/.*/
left_marginCTRL-Ll[0-9]+
right_marginCTRL-Rr[0-9]+
stick_to_left<Left>, <Right>< or >
ignore_groupsCTRL-Gig\[.*\]g:easy_align_ignore_groups
ignore_unmatchedCTRL-Uiu[01]g:easy_align_ignore_unmatched
indentationCTRL-Ii[ksdn]g:easy_align_indentation
delimiter_alignCTRL-Dd[lrc]g:easy_align_delimiter_align
alignCTRL-Aa[lrc*]*

Filtering lines

With filter option, you can align lines that only match or do not match a given pattern. There are several ways to set the pattern.

  1. Press CTRL-F in interactive mode and type in g/pat/ or v/pat/
  2. In command-line, it can be written in dictionary format: {'filter': 'g/pat/'}
  3. Or in shorthand notation: g/pat/ or v/pat/

(You don't need to escape '/'s in the regular expression)

Examples

" Start interactive mode with filter option set to g/hello/
EasyAlign g/hello/

" Start live interactive mode with filter option set to v/goodbye/
LiveEasyAlign v/goodbye/

" Align the lines with 'hi' around the first colons
EasyAlign:g/hi/

Ignoring delimiters in comments or strings

EasyAlign can be configured to ignore delimiters in certain syntax highlight groups, such as code comments or strings. By default, delimiters that are highlighted as code comments or strings are ignored.

" Default:
"   If a delimiter is in a highlight group whose name matches
"   any of the following regular expressions, it will be ignored.
let g:easy_align_ignore_groups = ['Comment', 'String']

For example, the following paragraph

{
  # Quantity of apples: 1
  apple: 1,
  # Quantity of bananas: 2
  bananas: 2,
  # Quantity of grape:fruits: 3
  'grape:fruits': 3
}

becomes as follows on <Enter>: (or :EasyAlign:)

{
  # Quantity of apples: 1
  apple:          1,
  # Quantity of bananas: 2
  bananas:        2,
  # Quantity of grape:fruits: 3
  'grape:fruits': 3
}

Naturally, this feature only works when syntax highlighting is enabled.

You can change the default rule by using one of these 4 methods.

  1. Press CTRL-G in interactive mode to switch groups
  2. Define global g:easy_align_ignore_groups list
  3. Define a custom rule in g:easy_align_delimiters with ignore_groups option
  4. Provide ignore_groups option to :EasyAlign command. e.g. :EasyAlign:ig[]

For example if you set ignore_groups option to be an empty list, you get

{
  # Quantity of apples:  1
  apple:                 1,
  # Quantity of bananas: 2
  bananas:               2,
  # Quantity of grape:   fruits: 3
  'grape:                fruits': 3
}

If a pattern in ignore_groups is prepended by a !, it will have the opposite meaning. For instance, if ignore_groups is given as ['!Comment'], delimiters that are not highlighted as Comment will be ignored during the alignment.

To make ignore_groups work, and to debug the related issues, it is useful to know which highlight group a certain location in a file belongs to. A special function exists for this purpose, returning exactly the name of the highlight group that is used by the easy align plugin.

" Highlight group name of the cursor position
echo easy_align#get_highlight_group_name()

" Highlight group name of the line 10, column 20
echo easy_align#get_highlight_group_name(10, 20)

Ignoring unmatched lines

ignore_unmatched option determines how EasyAlign command processes lines that do not have N-th delimiter.

  1. In left-alignment mode, they are ignored
  2. In right or center-alignment mode, they are not ignored, and the last tokens from those lines are aligned as well as if there is an invisible trailing delimiter at the end of each line
  3. If ignore_unmatched is 1, they are ignored regardless of the alignment mode
  4. If ignore_unmatched is 0, they are not ignored regardless of the mode

Let's take an example. When we align the following code block around the (1st) colons,

{
  apple: proc {
    this_line_does_not_have_a_colon
  },
  bananas: 2,
  grapefruits: 3
}

this is usually what we want.

{
  apple:       proc {
    this_line_does_not_have_a_colon
  },
  bananas:     2,
  grapefruits: 3
}

However, we can override this default behavior by setting ignore_unmatched option to zero using one of the following methods.

  1. Press CTRL-U in interactive mode to toggle ignore_unmatched option
  2. Set the global g:easy_align_ignore_unmatched variable to 0
  3. Define a custom alignment rule with ignore_unmatched option set to 0
  4. Provide ignore_unmatched option to :EasyAlign command. e.g. :EasyAlign:iu0

Then we get,

{
  apple:                             proc {
    this_line_does_not_have_a_colon
  },
  bananas:                           2,
  grapefruits:                       3
}

Aligning delimiters of different lengths

Global g:easy_align_delimiter_align option and rule-wise/command-wise delimiter_align option determines how matched delimiters of different lengths are aligned.

apple = 1
banana += apple
cake ||= banana

By default, delimiters are right-aligned as follows.

apple    = 1
banana  += apple
cake   ||= banana

However, with :EasyAlign=dl, delimiters are left-aligned.

apple  =   1
banana +=  apple
cake   ||= banana

And on :EasyAlign=dc, center-aligned.

apple   =  1
banana +=  apple
cake   ||= banana

In interactive mode, you can change the option value with CTRL-D key.

Adjusting indentation

By default :EasyAlign command keeps the original indentation of the lines. But then again we have indentation option. See the following example.

# Lines with different indentation
  apple = 1
    banana = 2
      cake = 3
        daisy = 4
     eggplant = 5

# Default: _k_eep the original indentation
#   :EasyAlign=
  apple       = 1
    banana    = 2
      cake    = 3
        daisy = 4
     eggplant = 5

# Use the _s_hallowest indentation among the lines
#   :EasyAlign=is
  apple    = 1
  banana   = 2
  cake     = 3
  daisy    = 4
  eggplant = 5

# Use the _d_eepest indentation among the lines
#   :EasyAlign=id
        apple    = 1
        banana   = 2
        cake     = 3
        daisy    = 4
        eggplant = 5

# Indentation: _n_one
#   :EasyAlign=in
apple    = 1
banana   = 2
cake     = 3
daisy    = 4
eggplant = 5

In interactive mode, you can change the option value with CTRL-I key.

Alignments over multiple occurrences of delimiters

As stated above, "N-th" parameter is used to target specific occurrences of the delimiter when it appears multiple times in each line.

To recap:

" Left-alignment around the FIRST occurrences of delimiters
:EasyAlign =

" Left-alignment around the SECOND occurrences of delimiters
:EasyAlign 2=

" Left-alignment around the LAST occurrences of delimiters
:EasyAlign -=

" Left-alignment around ALL occurrences of delimiters
:EasyAlign *=

" Left-right ALTERNATING alignment around all occurrences of delimiters
:EasyAlign **=

" Right-left ALTERNATING alignment around all occurrences of delimiters
:EasyAlign! **=

In addition to these, you can fine-tune alignments over multiple occurrences of the delimiters with 'align' option. (The option can also be set in interactive mode with the special key CTRL-A)

" Left alignment over the first two occurrences of delimiters
:EasyAlign = { 'align': 'll' }

" Right, left, center alignment over the 1st to 3rd occurrences of delimiters
:EasyAlign = { 'a': 'rlc' }

" Using shorthand notation
:EasyAlign = arlc

" Right, left, center alignment over the 2nd to 4th occurrences of delimiters
:EasyAlign 2=arlc

" (*) Repeating alignments (default: l, r, or c)
"   Right, left, center, center, center, center, ...
:EasyAlign *=arlc

" (**) Alternating alignments (default: lr or rl)
"   Right, left, center, right, left, center, ...
:EasyAlign **=arlc

" Right, left, center, center, center, ... repeating alignment
" over the 3rd to the last occurrences of delimiters
:EasyAlign 3=arlc*

" Right, left, center, right, left, center, ... alternating alignment
" over the 3rd to the last occurrences of delimiters
:EasyAlign 3=arlc**

Extending alignment rules

Although the default rules should cover the most of the use cases, you can extend the rules by setting a dictionary named g:easy_align_delimiters.

You may refer to the definitions of the default alignment rules here.

Examples

let g:easy_align_delimiters = {
\ '>': { 'pattern': '>>\|=>\|>' },
\ '/': {
\     'pattern':         '//\+\|/\*\|\*/',
\     'delimiter_align': 'l',
\     'ignore_groups':   ['!Comment'] },
\ ']': {
\     'pattern':       '[[\]]',
\     'left_margin':   0,
\     'right_margin':  0,
\     'stick_to_left': 0
\   },
\ ')': {
\     'pattern':       '[()]',
\     'left_margin':   0,
\     'right_margin':  0,
\     'stick_to_left': 0
\   },
\ 'd': {
\     'pattern':      ' \(\S\+\s*[;=]\)\@=',
\     'left_margin':  0,
\     'right_margin': 0
\   }
\ }

Other options

Disabling &foldmethod during alignment

It is reported that &foldmethod value of expr or syntax can significantly slow down the alignment when editing a large, complex file with many folds. To alleviate this issue, EasyAlign provides an option to temporarily set &foldmethod to manual during the alignment task. In order to enable this feature, set g:easy_align_bypass_fold switch to 1.

let g:easy_align_bypass_fold = 1

Left/right/center mode switch in interactive mode

In interactive mode, you can choose the alignment mode you want by pressing enter keys. The non-bang command, :EasyAlign starts in left-alignment mode and changes to right and center mode as you press enter keys, while the bang version first starts in right-alignment mode.

  • :EasyAlign
    • Left, Right, Center
  • :EasyAlign!
    • Right, Left, Center

If you do not prefer this default mode transition, you can define your own settings as follows.

let g:easy_align_interactive_modes = ['l', 'r']
let g:easy_align_bang_interactive_modes = ['c', 'r']

Advanced examples and use cases

See EXAMPLES.md for more examples.

Related work

Author

Junegunn Choi

License

MIT