(Fix links using VimTipNr where target has been merged) |
(Remove html character entities) |
||
Line 3: | Line 3: | ||
|id=320 |
|id=320 |
||
|previous=319 |
|previous=319 |
||
− | |next= |
+ | |next=322 |
|created=August 26, 2002 |
|created=August 26, 2002 |
||
|complexity=basic |
|complexity=basic |
||
Line 32: | Line 32: | ||
endfunc |
endfunc |
||
− | " noremap |
+ | " noremap <PageUp> 39<C-U>:set scroll=0<CR> |
function! MyPageUp() |
function! MyPageUp() |
||
let visible_lines = GetNumberOfVisibleLines() |
let visible_lines = GetNumberOfVisibleLines() |
||
− | execute "normal " . visible_lines . "\ |
+ | execute "normal " . visible_lines . "\<C-U>:set scroll=0\r" |
endfunction |
endfunction |
||
− | " noremap |
+ | " noremap <PageDown> 39<C-D>:set scroll=0<CR> |
function! MyPageDown() |
function! MyPageDown() |
||
let visible_lines = GetNumberOfVisibleLines() |
let visible_lines = GetNumberOfVisibleLines() |
||
− | execute "normal " . visible_lines . "\ |
+ | execute "normal " . visible_lines . "\<C-D>:set scroll=0\r" |
endfunction |
endfunction |
||
" BorlandPascal pageup/down behaviour! |
" BorlandPascal pageup/down behaviour! |
||
" todo: when hitting top/bottom of file, then restore Y to lastY |
" todo: when hitting top/bottom of file, then restore Y to lastY |
||
− | noremap |
+ | noremap <PageUp> :call MyPageUp()<CR> |
− | noremap |
+ | noremap <PageDown> :call MyPageDown()<CR> |
</pre> |
</pre> |
||
Line 59: | Line 59: | ||
A solution that I use (easier, I would say, but has a small side-effect) is this: |
A solution that I use (easier, I would say, but has a small side-effect) is this: |
||
− | map |
+ | map <PageDown> :set scroll=0<CR>:set scroll^=2<CR>:set scroll-=1<CR><C-D>:set scroll=0<CR> |
− | map |
+ | 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! |
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! |
Revision as of 02:50, 29 September 2008
created August 26, 2002 · complexity basic · author Simon "neoneye" Strandgaard · version 6.0
Borland behaviour = the cursor keeps the same xy position during pageup/down.
I'm 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 . "|" 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 behaviour! " todo: when hitting top/bottom of file, then restore Y to lastY noremap <PageUp> :call MyPageUp()<CR> noremap <PageDown> :call MyPageDown()<CR>
Comments
For maintaining the same x coordinate, :help 'startofline'.
And CTRL-U (up), CTRL-D (down) may also be useful for what you want (half page scrolls)
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!
See Combining move and scroll. You might find it useful to incorporate the improvements into this tip.