From e165276763f52bc1f8a30d892651b1725aef7017 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 5 Aug 2024 00:22:29 +0200 Subject: [PATCH] fix error when there is no cursor word --- lua/config/hlslens.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/config/hlslens.lua b/lua/config/hlslens.lua index 430bd23..3632347 100644 --- a/lua/config/hlslens.lua +++ b/lua/config/hlslens.lua @@ -35,14 +35,28 @@ keymap.set("n", "N", "", { end, }) +local no_word_under_cursor = function() + local word_under_cursor = vim.fn.expand("") + + local msg = "E348: No string under cursor" + api.nvim_err_writeln(msg) + return word_under_cursor == "" +end + keymap.set("n", "*", "", { callback = function() + if no_word_under_cursor() then + return + end vim.fn.execute("normal! *N") hlslens.start() end, }) keymap.set("n", "#", "", { callback = function() + if no_word_under_cursor() then + return + end vim.fn.execute("normal! #N") hlslens.start() end,