Highlight multiple different words at the same time. That's all.
I really loved vim-quickhl.
Wrote this plugin in Lua with a lot of hints from interestingwords.nvim.
Thanks.
- Toggle highlighting of the word under the cursor.
- Toggle current selection highlighting.
- Toggle highlighting of the word from input.
- Remove all highlights by this plugin.
- Neovim >= 0.9.5
- Because it was developed with this version. Since it is simple, I think it will work even in lower versions.
Install the plugin with your preferred package manager. Here is an example in lazy.nvim.
{
'AT-AT/hlwords.nvim',
config = function()
require('hlwords').setup({
-- options...
})
end,
}
Below are the configurable options and their default values.
{
-- Highlight colors.
-- We only provide primitive highlight colors, so change them to match your colorscheme.
-- You can set any number of color definition maps that are compatible with nvim_set_hl(),
-- and can highlight as many items as you set here at the same time.
-- See: https://neovim.io/doc/user/api.html#nvim_set_hl()
colors = {
{ fg = '#000000', bg = '#00ffff' },
{ fg = '#ffffff', bg = '#ff00ff' },
{ fg = '#000000', bg = '#ffff00' },
{ fg = '#ffffff', bg = '#444444' },
},
-- Priority order when highlights overlap.
-- See: https://neovim.io/doc/user/builtin.html#matchadd()
highlight_priority = 10,
-- Order of use of highlight colors.
-- If false, they will be used in the order specified in the "colors" option.
random = true,
-- Handling of words specified in normal mode.
-- When highlighting is executed in normal mode, a pattern including word boundaries
-- ('\\<' .. word .. '\\>') is used in interestingwords.nvim, but not in vim-quickhl.
-- If set to false, the match pattern will no longer represent exact words, so the
-- behavior will be similar to vim-quickhl.
strict_word = false,
}
Note that the behavior of this plugin is affected by the settings of the ignorecase
and smartcase
options.
See the documentation for details.
This plugin does not provide a default keymap. Below is an example.
-- Toggles highlighting of the word (<word>) under the cursor.
vim.keymap.set('n', '<leader>hh', function() require('hlwords').toggle() end)
-- Toggle highlighting current selection.
-- Note that "V-LINE" mode is not applicable, and it's possible to select a range
-- spanning multiple lines in "V-BLOCK" mode but it doesn't make much sense.
vim.keymap.set('x', '<leader>hh', function() require('hlwords').toggle() end)
-- Toggle highlighting of the word from input.
vim.keymap.set('n', '<leader>hw', function() require('hlwords').accept() end)
-- Remove all highlights.
vim.keymap.set('n', '<leader>hc', function() require('hlwords').clear() end)
If you are using Lazy.nvim, you can perform lazy loading at the same time by registering with the "keys" option.
{
keys = {
{
'<leader>hh',
function()
require('hlwords').toggle()
end,
mode = { 'n', 'x' },
},
{
'<leader>hw',
function()
require('hlwords').accept()
end,
},
{
'<leader>hc',
function()
require('hlwords').clear()
end,
},
},
}