Vim logo vim online Vim Book Ad

basic Tip #320: Borland pageup/down behavier

 tip karma   Rating 11/5, Viewed by 712 

created:   August 26, 2002 14:49      complexity:   basic
author:   Simon "neoneye" Strandgaard      as of Vim:   6.0

borlandbehavier = the cursor keeps the same xy position during pageup/down

Im new to VIM scripting, im sure it can be done smarter?
I read vimtip #105 and it gave me a clue of how BorlandPageUp/Down could be done.


" i could'nt find any get_number_of_visible_lines function, so i made my own.
function GetNumberOfVisibleLines()
    let cur_line = line(".")
    let cur_col = virtcol(".")
    normal H
    let top_line = line(".")
    normal L
    let bot_line = line(".")

    execute "normal " . cur_line . "G"
    execute "normal " . cur_col . "|"
    return bot_line - top_line
endfunc

" noremap <PageUp> 39<C-U>:set scroll=0<CR>
function! MyPageUp()
    let visible_lines = GetNumberOfVisibleLines()
    execute "normal " . visible_lines . "\<C-U>:set scroll=0\r"
endfunction

" noremap <PageDown> 39<C-D>:set scroll=0<CR>
function! MyPageDown()
    let visible_lines = GetNumberOfVisibleLines()
    execute "normal " . visible_lines . "\<C-D>:set scroll=0\r"
endfunction

" BorlandPascal pageup/down behavier!
" todo: when hitting top/bottom of file, then restore Y to lastY
noremap <PageUp> :call MyPageUp()<CR>
noremap <PageDown> :call MyPageDown()<CR>

 rate this tip  Life Changing Helpful Unfulfilling 

<<text formatting (lining up ='s,('s etc)) | Centura swap with upper/lower line behavier >>

Additional Notes

Anonymous, August 27, 2002 2:34
For maintaining the same x coordinate, help startofline
Anonymous, August 27, 2002 4:21
And CTRL-U (up), CTRL-D (down) may also be useful for what you want (half page scrolls)
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo