-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
You can't. Use the get_hl API to get the current properties, modify them, and then set these. |
Beta Was this translation helpful? Give feedback.
-
Thanks for help. Could you share some example ? |
Beta Was this translation helpful? Give feedback.
-
You can create a utility function, especially if you want to do this a lot: function modify_hl(ns, name, changes)
local def = vim.api.nvim_get_hl(ns, { name = name, link = false })
vim.api.nvim_set_hl(ns, name, vim.tbl_deep_extend("force", def, changes))
end Then in your case: Note: |
Beta Was this translation helpful? Give feedback.
-
@seandewar thanks for your answer. Is calling |
Beta Was this translation helpful? Give feedback.
-
Depends what you mean by "better". For example, as in my previous answer, the API is easily able to resolve the effective definition of a linked group and modify its attributes (rather than just setting fall-back attributes in case it's unlinked later, which is what There are also other cases where the API is clearly preferable. E.g: when manipulating highlights in a specific namespace or when using group IDs. If performance is your concern, then you're likely over-thinking; there's unlikely any significant difference for just a few groups. |
Beta Was this translation helpful? Give feedback.
You can create a utility function, especially if you want to do this a lot:
Then in your case:
modify_hl(0, "TSFunction", { bold = true, italic = true })
Note:
modify_hl
assumes that if the group is linked, that you want to resolve the "effective" definition and modify that.If you instead want to set fallback attributes in case the group is unlinked later (unlikely), remove
link = false
.