Created
September 23, 2017 13:50
-
-
Save romainl/ac63e108c3d11084be62b3c04156c263 to your computer and use it in GitHub Desktop.
Markdown : jump to next heading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" markdown : jump to next heading | |
function! s:JumpToNextHeading(direction, count) | |
let col = col(".") | |
silent execute a:direction == "up" ? '?^#' : '/^#' | |
if a:count > 1 | |
silent execute "normal! " . repeat("n", a:direction == "up" && col != 1 ? a:count : a:count - 1) | |
endif | |
silent execute "normal! " . col . "|" | |
unlet col | |
endfunction | |
nnoremap <buffer> <silent> ]] :<C-u>call <SID>JumpToNextHeading("down", v:count1)<CR> | |
nnoremap <buffer> <silent> [[ :<C-u>call <SID>JumpToNextHeading("up", v:count1)<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty nice, you can avoid the
repeat
call byusing the(nope, I'm being silly, but it's a similar idea):global
command :)