" jump to the previous paragraph in the document
func! PrevParagraph()
" if current line is not empty, search for the prev empty one
if(getline('.') != '')
let curr_ln = search('^$', 'bW')
else
let curr_ln = line(".")
endif
while(1)
let old_ln = curr_ln
let curr_ln = search('^$', 'bW')
" if begin of buffer, jump to first line
if(curr_ln <= 0)
exe 1
break
endif
let diff = old_ln - curr_ln
" jump over n empty lines, if diff is greater 1 there was a line with
" text between the jumps
if(diff > 1)
let curr_ln += 1
exe curr_ln
break
endif
endwhile
endfunc
" jump to the beginning of the current paragraph
func! StartOfCurrentParagraph()
if(getline('.') != '')
let ln = search('^$', 'bW')
if(ln > 0)
let ln += 1
exe ln
else
exe 1
endif
endif
endfunc
" jump to the next paragraph
func! NextParagraph()
" find the next empty line
if(getline('.') != '')
let ln = search('^$', 'W')
" if a empty line exists, jump to it
if(ln > 0)
exe ln
else
return
endif
endif
" walk line by line through the document until there is a non empty line or
" you reach the end of the document
while(1)
:+
if(getline('.') != '')
break
endif
if(line('.') == line('$'))
break
endif
endwhile
endfunc