Improve the support of syntax highlighting groups
The implementation of syntax group support in EasyAlign is not very advanced and does not work in some cases.
Here I must digress for a moment and recommend the SynGroup function, which may be very useful in debugging this issue.
One thing that is not supported is syntax group linking (synIDtrans vim function would help here). For example, in zsh syntax highlighting, the comments belong to a syntax group zshComment which is linked to the Comment group. So, while the group is coloured as comments, it has a different name and hence the default EasyAlign # rules do not match it. I suspect this is the reason for most problems when using the # shortcut, such as #96.
And don't get me started on the case when the syntax highlighting is done by treesitter in neovim :) I don't thing that synID* functions work correctly at all in such case. OK, I understand that this is a vim plugin, but hey, it is year 2024 now !!!
it has a different name and hence the default EasyAlign
#rules do not match it.
The rule works well because zshComment includes the substring Comment, I think you're somehow confused.
Unfortunately, -<space> trick (around the last space) I mentioned in #96 doesn't work in zsh files while it works well in other types of files such as Ruby, Python, Perl, etc, because in the zsh syntax of Vim, the space before # are also recognized as zshComment.
And don't get me started on the case when the syntax highlighting is done by treesitter in neovim :) I don't thing that synID* functions work correctly at all in such case.
I'm not a Neovim user, and I don't know if it works or not. Please send a pull request if it doesn't work and you're interested in making it work. Thanks.
The rule works well because zshComment includes the substring Comment
Hm ... well, not in my case. For example, I have a file with zsh syntax highlighting, and the following block of code in it (note the different number of spaces in the beginning):
# aaa
# bbb
# ccc
The SynGroup function returns the following when the cursor is on # character above: zshComment -> Comment
I select those lines in visual mode, and then ga# (ga being the EasyAlign mapping) does nothing. ga<C-G># does the trick - all # characters become aligned.
But then, again, I use neovim. Maybe there are some other differences at play here ...
Added the lines to my .zshrc, and ga# in Neovim worked.
Like I said, I'm not a Neovim user and this is all I have in my init.vim.
call plug#begin()
Plug 'junegunn/vim-easy-align'
call plug#end()
" Start interactive EasyAlign in visual mode
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign with a Vim movement
nmap ga <Plug>(EasyAlign)