vim-easy-align icon indicating copy to clipboard operation
vim-easy-align copied to clipboard

Improve the support of syntax highlighting groups

Open j-xella opened this issue 1 year ago • 3 comments

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 !!!

j-xella avatar Mar 07 '24 12:03 j-xella

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.

junegunn avatar Mar 07 '24 13:03 junegunn

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 ...

j-xella avatar Mar 07 '24 14:03 j-xella

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)

junegunn avatar Mar 07 '24 15:03 junegunn