From a0d68f92657ef15875ea2d2f6dd9056b2a0dcf5c Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Mon, 21 Nov 2022 16:31:58 +0100 Subject: [PATCH] vim:autocmd: Highlight old cursor position Highlight old cursor position as if the cursor was still there when switching window focus. This way I keep an overview of the cursor positions. --- .config/vim/vimrc.d/80-autocommands.vim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.config/vim/vimrc.d/80-autocommands.vim b/.config/vim/vimrc.d/80-autocommands.vim index be89cc5..676a0fd 100644 --- a/.config/vim/vimrc.d/80-autocommands.vim +++ b/.config/vim/vimrc.d/80-autocommands.vim @@ -70,6 +70,25 @@ augroup highlight_current_word au CursorMovedI * call HighlightCurrentWord() augroup END +" When switching focus to another window, keep the cursor location highlighted. +function! HighlightOldCursorPos() + let w:cursor_pos_match_id = matchaddpos( + \ 'TermCursor', + \ [getcurpos()[1:2]]) +endfunction +function! ClearOldCursorPos() + if exists('w:cursor_pos_match_id') + echo 'foo' + call matchdelete(w:cursor_pos_match_id) + unlet w:cursor_pos_match_id + endif +endfunction +augroup highlight_old_cursor_pos + au! + au WinLeave * call HighlightOldCursorPos() + au WinEnter * call ClearOldCursorPos() +augroup END + " Do not mark input from stdin as modified augroup stdin_not_modified au!