how to tell vim not to change cursor position on the screen after PageDown/PageUp

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to tell vim not to change cursor position on the screen after PageDown/PageUp

Egor Starostin
Hello,

In every other editor (except vim/emacs) when I press PageUp/PageDown
cursor position on the screen remains the same.

When I press C-F/PageDown in vim then cursor jumps to the first screen
line. After PageUp cursor jumps to the last line of the screen.

How can I tell vim to not to change cursor position on the screen
after PageUp/PageDow?

--
Egor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Edward WIJAYA
On Mon, 23 May 2005 13:12:21 +0800, Egor Starostin <[hidden email]>  
wrote:

> Hello,
Hi,

> How can I tell vim to not to change cursor position on the screen
> after PageUp/PageDow?
>

use "z"

z [RET] Move current line to top of screen and scroll
z.      Move current line to center of screen and scroll
z-      Move current line to bottom of screen and scroll

10z [RET] moves line 10 to top of screen

--
Regards,
Edward WIJAYA
SINGAPORE
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Egor Starostin
> > How can I tell vim to not to change cursor position on the screen
> > after PageUp/PageDow?
> >
>
> use "z"
>
> z [RET] Move current line to top of screen and scroll
> z.      Move current line to center of screen and scroll
> z-      Move current line to bottom of screen and scroll
>
> 10z [RET] moves line 10 to top of screen
Do you know how to obtain the current screen position of cursor?
Maybe it's possible to remap PageUp to preliminary save cursor's
screen position; move current line to the bottom of screen ;do a page
up; return to saved position with z

Ugly, but should work.

--
Egor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Edward WIJAYA
On Mon, 23 May 2005 14:12:41 +0800, Egor Starostin <[hidden email]>  
wrote:

> Do you know how to obtain the current screen position of cursor?

Yes, perhaps 'mark'-ing is what you need.

ma (mark current position with 'a']
'a (go to mark a in current)

Otherwise try:

CTRL-O
Go to [count] Older cursor position in jump list

or

CTRL-I
Go to [count] newer cursor position in jump list


--
Regards,
Edward WIJAYA
SINGAPORE
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Egor Starostin
> > Do you know how to obtain the current screen position of cursor?
>
> Yes, perhaps 'mark'-ing is what you need.
No, I'm asking about cursor position relative to screen, not to text.
Marking works for text, not for screen.

--
Egor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Mathias Michaelis
>>> Do you know how to obtain the current screen position of
>>> cursor?
>>>
>> Yes, perhaps 'mark'-ing is what you need.
>>
> No, I'm asking about cursor position relative to screen, not to
> text. Marking works for text, not for screen.
>
You may use the functions

winline() and wincol()

to get the cursor position relative to the current window,

line(".") and col(".")

to get the line and column number relative to the text and

winheight(0), winwidth(0)

to get the windows hight and width. Probably, you will use only the
latter two pairs:

1) Get the cursor position relative to text and add or subtract the
   windows height to the value of line("."). This will give you the
   new position x, y where you want to put the cursor to.

2) Do <PgDown> or <PgUp>

3) Put the cursor to the position x, y you have got from step 1).
   Use the function cursor(x, y) for that.

I hope that will help.
Sincerely
Mathias
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Egor Starostin
> > No, I'm asking about cursor position relative to screen, not to
> > text. Marking works for text, not for screen.

> 3) Put the cursor to the position x, y you have got from step 1).
>   Use the function cursor(x, y) for that.
WIth cursor() I can set cursor position relative to text (i.e. jump to
1st line of text) but cannot set cursor position relative to screen
(i.e. jump to 1st line on screen)

Am I wrong?

Everyone, how come ther is no option/switch for such intuitive
behaviour (don't change screen position of cursor during
pageup/pagedown)? Is it really so?

When I edit programs I sometimes want to see a code some lines below
(off the screen). I press PageDown, look at the code and return back
with PageUp. But there is a catch -- now my cursor is not on the same
line as before PageUp+PageDown.
I just don't understand why my cursor should be not on the same line
after PageUp+PageDown (or vice versa).

--
Egor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

A.J.Mechelynck
Egor Starostin wrote:

>>>No, I'm asking about cursor position relative to screen, not to
>>>text. Marking works for text, not for screen.
>
>
>>3) Put the cursor to the position x, y you have got from step 1).
>>  Use the function cursor(x, y) for that.
>
> WIth cursor() I can set cursor position relative to text (i.e. jump to
> 1st line of text) but cannot set cursor position relative to screen
> (i.e. jump to 1st line on screen)
>
> Am I wrong?
>
> Everyone, how come ther is no option/switch for such intuitive
> behaviour (don't change screen position of cursor during
> pageup/pagedown)? Is it really so?
>
> When I edit programs I sometimes want to see a code some lines below
> (off the screen). I press PageDown, look at the code and return back
> with PageUp. But there is a catch -- now my cursor is not on the same
> line as before PageUp+PageDown.
> I just don't understand why my cursor should be not on the same line
> after PageUp+PageDown (or vice versa).
>

Vim always keeps the cursor onscreen. When you hit PageUp, the part of
the file you were viewing goes off the screen, and Vim adjusts the
cursor to the nearest on-screen line (the bottom one of the new
screenful). When you hit PageDown, your current screenful goes offscreen
again, and Vim adjusts the cursor again (this time to the top line of
the new screenful).

To go back to the same text line after <PageUp><PageDown> (or
vice-versa), remember your text position [by marking or by saving
line(".") and col(".")] then later go back to it [by jumping to the mark
or by calling cursor()]. If, in addition, you want the text to be
positioned identically in the window, it can be done (e.g., in some
ad-hoc function) but it takes more fancy footwork, using for instance
winline(), z<CR> and [count]<Ctrl-Y>.

For longer jumps (e.g., going to the top of the file with gg or to the
bottom using G) the jumps are memorised by Vim and can be undone with
Ctrl-O or redone with Ctrl-I.


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re[2]: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Altukhou Yury
In reply to this post by Egor Starostin
Hello Egor,
      try followin mappings:
      :nmap <PageUp> :exec 'normal <C-B>'.winline().'H'<CR>
      :nmap <PageDown> :exec 'normal <C-D>'.winline().'H'<CR>

      and yet maybe you wish to see
      :h 'scrolloff'


Monday, May 23, 2005, 1:12:49 PM, you wrote:

>> > No, I'm asking about cursor position relative to screen, not to
>> > text. Marking works for text, not for screen.

>> 3) Put the cursor to the position x, y you have got from step 1).
>>   Use the function cursor(x, y) for that.
ES> WIth cursor() I can set cursor position relative to text (i.e. jump to
ES> 1st line of text) but cannot set cursor position relative to screen
ES> (i.e. jump to 1st line on screen)

ES> Am I wrong?

ES> Everyone, how come ther is no option/switch for such intuitive
ES> behaviour (don't change screen position of cursor during
ES> pageup/pagedown)? Is it really so?

ES> When I edit programs I sometimes want to see a code some lines below
ES> (off the screen). I press PageDown, look at the code and return back
ES> with PageUp. But there is a catch -- now my cursor is not on the same
ES> line as before PageUp+PageDown.
ES> I just don't understand why my cursor should be not on the same line
ES> after PageUp+PageDown (or vice versa).




--
Best regards,
 Wind                            mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Egor Starostin
In reply to this post by A.J.Mechelynck
> Vim always keeps the cursor onscreen. When you hit PageUp, the part of
> the file you were viewing goes off the screen, and Vim adjusts the
> cursor to the nearest on-screen line
Why? When I press <PageDown> text shifts for 24 (for example) lines
and cursor shifts for some other lines (depends on it's previous
place). For what reason? Why cursor doesn't shift for the same 24
lines? Am I the only person who gets confused from such vim behaviour?

> winline(), z<CR> and [count]<Ctrl-Y>.
This one probably should work. Thank you!

--
Egor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Re[2]: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Egor Starostin
In reply to this post by Altukhou Yury
>      try followin mappings:
>      :nmap <PageUp> :exec 'normal <C-B>'.winline().'H'<CR>
>      :nmap <PageDown> :exec 'normal <C-D>'.winline().'H'<CR>
Thank you!
PageDown works well (in normal mode).
But when I press PageUp, vim complains: E20: Mark not set.

>      and yet maybe you wish to see
>      :h 'scrolloff'
I tried it before (set scrolloff to large values). It doesn't help.

--
Egor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Mathias Michaelis
In reply to this post by Egor Starostin
Hallo Egor Starostin,

>>> No, I'm asking about cursor position relative to screen, not to
>>> text. Marking works for text, not for screen.
>>>
>> 3) Put the cursor to the position x, y you have got from step 1).
>>   Use the function cursor(x, y) for that.
>>
> WIth cursor() I can set cursor position relative to text (i.e. jump to
> 1st line of text) but cannot set cursor position relative to screen
> (i.e. jump to 1st line on screen)
>
> Am I wrong?
>
No, you aren't. But the coordinates you got from step 1 of my
description are also relative to text, not relative to screen. This
is why you have to use cursor() if you want to put the cursor at the
place you want it to have.

Sincerely
Mathias
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

A.J.Mechelynck
In reply to this post by Egor Starostin
Egor Starostin wrote:
>>Vim always keeps the cursor onscreen. When you hit PageUp, the part of
>>the file you were viewing goes off the screen, and Vim adjusts the
>>cursor to the nearest on-screen line
>
> Why? When I press <PageDown> text shifts for 24 (for example) lines
> and cursor shifts for some other lines (depends on it's previous
> place). For what reason? Why cursor doesn't shift for the same 24
> lines? Am I the only person who gets confused from such vim behaviour?

You mean, keep the cursor in the same place relative to the screen while
scrolling the text "behind" it? I don't know. Vi compatibility maybe
(ask Bram about that). Cursor keys are a late addition to Vim anyway.
You may want to use Ctrl-U and Ctrl-D, which (by default) scroll by half
a screen while keeping the cursor on the same screen line.

Try the following mappings:

        :map <PageUp> <C-U><C-U>
        :map <PageDown> <C-D><C-D>


Best regards,
Tony.

>
>
>>winline(), z<CR> and [count]<Ctrl-Y>.
>
> This one probably should work. Thank you!
>


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Charles E Campbell Jr
In reply to this post by Egor Starostin
Quoting Egor Starostin <[hidden email]>:

> > > No, I'm asking about cursor position relative to screen, not to
> > > text. Marking works for text, not for screen.
>...
>
> When I edit programs I sometimes want to see a code some lines below
> (off the screen). I press PageDown, look at the code and return back
> with PageUp. But there is a catch -- now my cursor is not on the same
> line as before PageUp+PageDown.
> I just don't understand why my cursor should be not on the same line
> after PageUp+PageDown (or vice versa).

Some suggestions:

        set nosol   (keeps cursor column)
        set ve      (allows cursor to wander off the line)

To save/restore screen positioning as well as text positioning, as in your
example with moving to code elsewhere, try

        :SWP  (save window position)
        :RWP  (restore window position)

which are commands available with cecutil.vim, a plugin available at:

        http://vim.sourceforge.net/scripts/script.php?script_id=1066

That said, what I usually do to accomplish something similar to your
example:

        ctrl-w s    (split the screen horizontally; use ctrl-w v for vertical)
        move wherever
        :q

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

David J. Weller-Fahy
In reply to this post by A.J.Mechelynck
* A. J. Mechelynck <[hidden email]> [2005-05-23 13:57 +0200]:
> Try the following mappings:
>
> :map <PageUp> <C-U><C-U>
> :map <PageDown> <C-D><C-D>

Thanks! I've been irritated by the default behavior of PageUp and
PageDown for years now, but never enough to search for a solution. While
catching up on the vim list, I found an answer waiting.

Again, thanks!

Regards,
--
dave [ please don't CC me ]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Eric Arnold
In reply to this post by Egor Starostin

If you want the cursor to *really* stay put, add   :set virtualedit=all
though you then have to deal with the strangeness of virtualedit.
It keeps the cursor at the window/virtual column regardless of line
length.  Otherwise, you don't get the full effect of seeing the cursor
not move when you scroll.


--- "David J. Weller-Fahy" <[hidden email]> wrote:

> * A. J. Mechelynck <[hidden email]> [2005-05-23 13:57 +0200]:
> > Try the following mappings:
> >
> > :map <PageUp> <C-U><C-U>
> > :map <PageDown> <C-D><C-D>
>
> Thanks! I've been irritated by the default behavior of PageUp and
> PageDown for years now, but never enough to search for a solution. While
> catching up on the vim list, I found an answer waiting.
>
> Again, thanks!
>
> Regards,
> --
> dave [ please don't CC me ]
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

David J. Weller-Fahy
* Eric Arnold <[hidden email]> [2005-05-23 22:25 +0200]:
> If you want the cursor to *really* stay put, add   :set virtualedit=all
> though you then have to deal with the strangeness of virtualedit.
> It keeps the cursor at the window/virtual column regardless of line
> length.  Otherwise, you don't get the full effect of seeing the cursor
> not move when you scroll.

Thanks, but I just tested out the non-virtualedit version, and that's
exactly the behavior that I want. I'll tuck the virtualedit information
into my hidey-hole for future use. ;]

Regards,
--
dave [ please don't CC me ]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to tell vim not to change cursor position on the screen after PageDown/PageUp

A.J.Mechelynck
In reply to this post by David J. Weller-Fahy
David J. Weller-Fahy wrote:

> * A. J. Mechelynck <[hidden email]> [2005-05-23 13:57 +0200]:
>
>>Try the following mappings:
>>
>> :map <PageUp> <C-U><C-U>
>> :map <PageDown> <C-D><C-D>
>
>
> Thanks! I've been irritated by the default behavior of PageUp and
> PageDown for years now, but never enough to search for a solution. While
> catching up on the vim list, I found an answer waiting.
>
> Again, thanks!
>
> Regards,

If you want to use them also in Insert mode, you can use in addition

        :imap <PageUp>   <C-O><C-U><C-O><C-U>
        :imap <PageDown> <C-O><C-D><C-O><C-D>

see ":help i_CTRL-O"

Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re[4]: how to tell vim not to change cursor position on the screen after PageDown/PageUp

Altukhou Yury
In reply to this post by Egor Starostin
Hello Egor,

Monday, May 23, 2005, 2:35:48 PM, you wrote:

>>      try followin mappings:
>>      :nmap <PageUp> :exec 'normal <C-B>'.winline().'H'<CR>
>>      :nmap <PageDown> :exec 'normal <C-D>'.winline().'H'<CR>
ES> Thank you!
ES> PageDown works well (in normal mode).
ES> But when I press PageUp, vim complains: E20: Mark not set.
    Yes you're right it does. (How did I do that?)
    Try this
    :nmap <PageUp> :exec 'normal <C-V><C-B>'.winline().'H'<CR>

    The reason was that CTRL-B was a command line editing command. and
    the result ex command was
    :'.winline().'H'nmap <PageUp> :exec 'normal
    because <C-B> move cursor to the beginning of the cmdline.
   

>>      and yet maybe you wish to see
>>      :h 'scrolloff'
ES> I tried it before (set scrolloff to large values). It doesn't help.




--
Best regards,
 Wind                            mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Re[4]: how to tell vim not to change cursor position on the screen after PageDown/PageUp

David Fishburn
Thanks for the suggestion Tony.

I had something else that didn't quite do it.

I think in your last post you didn't have the vmaps:

nmap <silent> <PageDown>      <C-D><C-D>
nmap <silent> <PageUp>        <C-U><C-U>
imap <silent> <PageDown> <C-O><C-D><C-O><C-D>
imap <silent> <PageUp>   <C-O><C-U><C-O><C-U>
vmap <silent> <PageDown>      <C-D><C-D>
vmap <silent> <PageUp>        <C-U><C-U>

Dave

12
Loading...