Skip to content

feat(links)!: allow granular highlighting of links #965

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

Merged
merged 1 commit into from
Apr 15, 2025

Conversation

kristijanhusak
Copy link
Member

@kristijanhusak kristijanhusak commented Apr 15, 2025

Summary

Previously, both link with and without description were highlighted only with @org.hyperlink hl group, which was linked to @markup.link.url by default.
Since Neovim also has @markup.link and @markup.link.label in addition to @markup.link.url, use those hl groups accordingly.

  1. @org.hyperlink for the non-important parts of link (square brackets), and this hl group is now linked to @markup.link
  2. @org.hyperlink.url for the actual url in the link. Hl group linked to @markup.link.url by default
  3. @org.hyperlink.desc for the link description. Hl group linked to @markup.link.label by default

To return to the previous behavior, override @org.hyperlink.url and @org.hyperlink.desc as suggested in the docs:

vim.api.nvim_create_autocmd('ColorScheme', {
  pattern = '*',
  callback = function()
    vim.api.nvim_set_hl(0, '@org.hyperlink', { link = '@markup.link.url' })
    vim.api.nvim_set_hl(0, '@org.hyperlink.url', { link = '@org.hyperlink' })
    vim.api.nvim_set_hl(0, '@org.hyperlink.desc', { link = '@org.hyperlink' })
  end
})

Related Issues

Closes #961

Checklist

I confirm that I have:

  • Followed the
    Conventional Commits
    specification
    (e.g., feat: add new feature, fix: correct bug,
    docs: update documentation).
  • My PR title also follows the conventional commits specification.
  • Updated relevant documentation, if necessary.
  • Thoroughly tested my changes.
  • Added tests (if applicable) and verified existing tests pass with
    make test.
  • Checked for breaking changes and documented them, if any.

Previously, both link with and without description were highlighted only
with `@org.hyperlink` hl group, which was linked to `@markup.link.url`
by default.
Since Neovim also has `@markup.link` and `@markup.link.label` in
addition to `@markup.link.url`, use those hl groups accordingly.
1. `@org.hyperlink` for the non-important parts of link (square
brackets), and this hl group is now linked to `@markup.link`
2. `@org.hyperlink.url` for the actual url in the link. Hl group linked
to `@markup.link.url` by default
3. `@org.hyperlink.desc` for the link description. Hl group linked to
`@markup.link.label` by default

To return to the previous behavior, override `@org.hyperlink.url` and
`@org.hyperlink.desc` as suggested in the docs:

```
vim.api.nvim_create_autocmd('ColorScheme', {
  pattern = '*',
  callback = function()
    -- Define own colors
    vim.api.nvim_set_hl(0, '@org.hyperlink.url', { link = '@org.hyperlink' })
    vim.api.nvim_set_hl(0, '@org.hyperlink.desc', { link = '@org.hyperlink' })
  end
})
```
@kristijanhusak kristijanhusak merged commit b371b9e into master Apr 15, 2025
38 of 39 checks passed
@kristijanhusak kristijanhusak deleted the feat/link-highlights branch April 15, 2025 19:13
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

Successfully merging this pull request may close these issues.

Add more evident difference between link URL and link description.
1 participant