From 4195ef571e28869e25427cd09700d2691fd0bd9f Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Thu, 10 Apr 2025 19:14:10 +0000 Subject: Change how clearing highlighting works after InsertLeave. When using feedkeys(), it was causing problems with Ctrl-O in insert. Now it disables hlsearch, and reenables it when searching or using n/N. --- init.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/init.vim b/init.vim index bca3c9d..1445e6e 100644 --- a/init.vim +++ b/init.vim @@ -166,10 +166,8 @@ augroup InitVim au! " Automatically stop highligting things when leaving insert mode. If I want " the highlight back, I can just hit 'n' and it will come back. - " - " I don't know why it can't just be 'noh' and why I have to do this feedkeys - " nonsense, but there appears to be a bug of some kind. - autocmd InsertLeave * call feedkeys("\noh\") + autocmd InsertLeave * set nohlsearch | redraw + autocmd CmdlineEnter /,\? set hlsearch autocmd TextYankPost * \ lua require'vim.hl'.on_yank( @@ -178,6 +176,8 @@ augroup InitVim " autocmd CursorHoldI * lua vim.lsp.buf.document_highlight() " autocmd CursorMoved * lua vim.lsp.buf.clear_references() augroup END +nnoremap n set hlsearchn +nnoremap N set hlsearchN " Local configuration that can be set by hostname or just a local configuration. " Local files are ignored by .gitignore so they won't be added to the repo, -- cgit