norcalli / nvim-colorizer.lua

The fastest Neovim colorizer.
Other
2.25k stars 117 forks source link

Vim command to toggle highlighting #27

Closed jcrd closed 4 years ago

jcrd commented 4 years ago

I want to toggle highlighting on-demand, like :HexokinaseToggle. Is this possible?

norcalli commented 4 years ago

There's no command for that right now, but I could add one. In the meantime, the functionality is already available via Lua, so you can do:

local colorizer = require'colorizer'
if colorizer.is_buffer_attached() then
  colorizer.detach_from_buffer()
else
  colorizer.attach_to_buffer()
end

or as a one line command:

command! ColorizerToggle lua local colorizer = require'colorizer' if colorizer.is_buffer_attached() then colorizer.detach_from_buffer() else colorizer.attach_to_buffer() end
jcrd commented 4 years ago

Hi, I can't find any reference to is_buffer_attached in the code or API docs. Nonetheless, this is the functionality I was seeking and would appreciate the addition of a ColorizerToggle command.

norcalli commented 4 years ago

Wow you're right. That's my bad. Thanks for pointing that out!