From 15fca46f502c541041788f96512f8a1a92b7fd57 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 4 Feb 2020 22:00:32 +0100 Subject: Search(): Use `feedkeys` instead of `normal!` to advance search Because of `:h function-search-undo`, using `normal! n` at the end of the function doesn't highlight the matches with 'hlsearch' (though it does advance to the next match). I've seen other mappings that add a `/` or `n` to the end of the mapping, but that doesn't work here because it's an operator, so `g@` needs to be the last thing in the mapping. And I was reluctant to work out how to make it an `` mapping. Fortunately, search highlighting works when `n` is used with `feedkeys()`. --- plugin/searchop.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/searchop.vim b/plugin/searchop.vim index 6757dcf..41f0f6d 100644 --- a/plugin/searchop.vim +++ b/plugin/searchop.vim @@ -7,5 +7,6 @@ function! Search(type, ...) let @/ = escape(@@, '\') call histadd('/', @/) - normal! n + + call feedkeys('n', 't') endfunction -- cgit v1.2.3