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.
This commit is contained in:
2022-11-21 16:31:58 +01:00
parent 93ef5afaba
commit a0d68f9265

View File

@@ -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!