sponsor Vim development Vim logo Vim Book Ad

basic Tip #320: Borland pageup/down behavier

 tip karma   Rating 10/6, Viewed by 2633 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

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)
[email protected], February 2, 2003 12:43
A solution that I use (easier, I would say, but has a small side-effect) is this:

map <PageDown> :set scroll=0<CR>:set scroll^=2<CR>:set scroll-=1<CR><C-D>:set scroll=0<CR>
map <PageUp> :set scroll=0<CR>:set scroll^=2<CR>:set scroll-=1<CR><C-U>:set scroll=0<CR>

I found Vim's normal PgUp/PgDn behaviour weird - I think it's different from every other editor I've used and I was unable to get used to it. The above two lines are godsent! :-)
Andrew Pimlott <[email protected]>, February 3, 2003 14:32
I just entered a refinement of vimtip #105 as vimtim #417.  You might find it useful to incorporate the improvements into this tip.
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 the maillist. Help Bram help Uganda.
   
SourceForge.net Logo