junegunn / vim-easy-align

:sunflower: A Vim alignment plugin
4.12k stars 120 forks source link

how to create an alignment rule for the "--" comment symbol in lua? #155

Closed hopezh closed 1 year ago

hopezh commented 1 year ago

I tried the following in my keymap.lua file, based on the settings for ":". However, it's not working...

vim.cmd([[
    let g:easy_align_delimiters = {
    \  ':': { 'pattern': ':',  'left_margin': 0, 'right_margin': 1, 'stick_to_left': 1 },
    \  '--': { 'pattern': '--',  'left_margin': 1, 'right_margin': 1, 'stick_to_left': 1 },
    \ }
]])
junegunn commented 1 year ago

An alignment rule is identified by a single-character key, so you can't use --. You can't use - either, because it is used for other purpose (counting from backwards). This one uses l (for lua).

let g:easy_align_delimiters = {
\ 'l': { 'pattern': '--\+', 'delimiter_align': 'l', 'ignore_groups': ['!Comment'] }
\ }
print(1) -- foo
print(2)       ----- bar
print(3)    --- baz

becomes

print(1) --    foo
print(2) ----- bar
print(3) ---   baz

on gaipl