I have the following vimrc
setup. It only adds new jumps when CursorHold
triggers in a paragraph that is not either 1) the location of the most recent m'
set by CursorHold
jump or 2) the location of the currently selected location in the jump history (e.g. when scrolling with <C-o>
/<C-i>
).
function! s:reset_jumps() abort
let [line1, line2] = [line("'{"), line("'}")]
let [items, pos] = getjumplist()
let pos = min([pos, len(items) - 1]) " returns length if outside of list
let [prev, curr] = [line("''"), items[pos]['lnum']]
if (line1 > curr || line2 < curr) && (line1 > prev || line2 < prev)
call feedkeys("m'", 'n') " update mark to current position
endif
endfunction
augroup jumplist_setup
au!
au CursorHold * call s:reset_jumps()
augroup END
I also disable conventional jump setting behavior as follows:
noremap n <Cmd>keepjumps normal! n<CR>
noremap N <Cmd>keepjumps normal! N<CR>
noremap ( <Cmd>keepjumps normal! (<CR>
noremap ) <Cmd>keepjumps normal! )<CR>
noremap { <Cmd>keepjumps normal! {<CR>
noremap } <Cmd>keepjumps normal! }<CR>