Skip to content

Instantly share code, notes, and snippets.

@mhinz
Created October 22, 2013 11:20
Show Gist options
  • Save mhinz/7098910 to your computer and use it in GitHub Desktop.
Save mhinz/7098910 to your computer and use it in GitHub Desktop.
function! s:set_cursor() abort
let s:oldline = exists('s:newline') ? s:newline : 5
let s:newline = line('.')
let headoff = s:headoff + 2 + s:secoff
" going down
if s:newline > s:oldline
while index(s:section_header_lines, s:newline) != -1
let s:newline += 1
endwhile
if empty(getline(s:newline)) | let s:newline += 1 | endif
if s:newline > s:lastline | let s:newline = s:lastline | endif
" going up
elseif s:newline < s:oldline
while index(s:section_header_lines, s:newline) != -1
let s:newline -= 1
endwhile
if empty(getline(s:newline)) | let s:newline -= 1 | endif
if s:newline < headoff | let s:newline = headoff | endif
endif
call cursor(s:newline, 5)
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment