function! CustomJump(motion) range
let cnt = v:count1
let save = @/
mark '
while cnt > 0
silent! execute a:motion
let cnt = cnt - 1
endwhile
call histdel('/', -1)
let @/ = save
endfunction
While I prefer the current s:JumpToHeader(), I feel it could be improved to avoid modifying search history:
function! s:JumpToHeader(forward, visual)
let save = @/
let pattern = '\v^#{1,6}.*$|^.+\n%(\-+|\=+)$'
" snip
execute 'silent normal! ' . direction . pattern . "\n"
call histdel('/', -1)
let @/ = save
endfunction
Another useful bit would the while loop, which lets @romainl's mapping respect a count.
In a Vi and Vim Stack Exchange post, @romainl posted a function to jump to headers (for mapping to
[[
,]]
, etc.):While I prefer the current
s:JumpToHeader()
, I feel it could be improved to avoid modifying search history:Another useful bit would the
while
loop, which lets @romainl's mapping respect a count.