Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the support of syntax highlighting groups #159

Open
j-xella opened this issue Mar 7, 2024 · 3 comments
Open

Improve the support of syntax highlighting groups #159

j-xella opened this issue Mar 7, 2024 · 3 comments

Comments

@j-xella
Copy link
Contributor

j-xella commented Mar 7, 2024

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

@junegunn
Copy link
Owner

junegunn commented Mar 7, 2024

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.

@j-xella
Copy link
Contributor Author

j-xella commented Mar 7, 2024

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

@junegunn
Copy link
Owner

junegunn commented Mar 7, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants