Tip: #320 - Page up/down and keep cursor position
Created: August 26, 2002 14:49 Complexity: basic Author: Simon "neoneye" Strandgaard Version: 6.0 Karma: 10/6 Imported from: Tip#320
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 VimTip105 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 . "
Comments
For maintaining the same x coordinate, help startofline
Anonymous , August 27, 2002 2:34
And CTRL-U (up), CTRL-D (down) may also be useful for what you want (half page scrolls)
Anonymous , August 27, 2002 4:21
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! :-)
vdvo--AT--seznam.cz , February 2, 2003 12:43
I just entered a refinement of VimTip105 as vimtim #417. You might find it useful to incorporate the improvements into this tip.
Andrew Pimlott <andrew--AT--pimlott.net> , February 3, 2003 14:32