1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00
jdhao e92362041c fix hlslens issue when no pattern is found
The captured error message is not correct before.
2023-09-01 21:22:22 +02:00

50 lines
987 B
Lua

local api = vim.api
local keymap = vim.keymap
local hlslens = require("hlslens")
hlslens.setup {
calm_down = true,
nearest_only = true,
}
local activate_hlslens = function(direction)
local cmd = string.format("normal! %s%szzzv", vim.v.count1, direction)
local status, msg = pcall(vim.cmd, cmd)
-- Deal with the case that there is no such pattern in current buffer.
if not status then
local start_idx, _ = string.find(msg, 'E486', 1, true)
local msg_part = string.sub(msg, start_idx)
api.nvim_err_writeln(msg_part)
return
end
hlslens.start()
end
keymap.set("n", "n", "", {
callback = function()
activate_hlslens("n")
end,
})
keymap.set("n", "N", "", {
callback = function()
activate_hlslens("N")
end,
})
keymap.set("n", "*", "", {
callback = function()
vim.fn.execute("normal! *N")
hlslens.start()
end,
})
keymap.set("n", "#", "", {
callback = function()
vim.fn.execute("normal! #N")
hlslens.start()
end,
})