ayamir / nvimdots

A well configured and structured Neovim.
BSD 3-Clause "New" or "Revised" License
2.84k stars 455 forks source link

save previous cursor position when i switch between tabA and tabB #1090

Closed asaning closed 7 months ago

asaning commented 7 months ago

Feature description

1 , i use the zz command to get the current line to relocate the middle of screen , 2, i switch to another tab, when i return back the previous one, the cursor doesn't locate in the right position

it's common in the coding process, when the code extend the one screen. each time i should relocate the cursor, it's annoying

Additional information

No response

ayamir commented 7 months ago

Could you provide a video with visible key press (by using software like carnac) to describe your problem?

asaning commented 7 months ago

Uploading 01.mp4…

我回到第一个tab的时候, 鼠标回到了最后一行, 我想光标回到那个之前的位置

asaning commented 7 months ago

https://github.com/ayamir/nvimdots/assets/99789353/886a1e43-7766-478e-8596-24db805e9e0a

视频看这个

Jint-lzxy commented 7 months ago

AFAIK this is currently impossible bc all registers can only store positions that actually exist in the file (that is, before \<EOF>). In other words, it can't preserve extra window scrolls beyond \<EOF>. But in other cases, nvim should work as expected since we've set up the corresponding option and autocmd:

               *'startofline'* *'sol'* *'nostartofline'* *'nosol'*
'startofline' 'sol' boolean (default off)
            global
    When "on" the commands listed below move the cursor to the first
    non-blank of the line.  When off the cursor is kept in the same column
    (if possible).  This applies to the commands: CTRL-D, CTRL-U, CTRL-B,
    CTRL-F, "G", "H", "M", "L", gg, and to the commands "d", "<<" and ">>"
    with a linewise operator, with "%" with a count and to buffer changing
    commands (CTRL-^, :bnext, :bNext, etc.).  Also for an Ex command that
    only has a line number, e.g., ":25" or ":+".
    In case of buffer changing commands the cursor is placed at the column
    where it was the last time the buffer was edited.

https://github.com/ayamir/nvimdots/blob/a2974b26d7dc6fa69b5c7bae5a840ebc2d5fffc1/lua/core/event.lua#L96-L101

CharlesChiuGit commented 7 months ago

actually the cursor is at the same position, it's at line 83 all the time. ... and @Jint-lzxy had said the rest loool, he typed tooo fast!

the main reason is the you scroll beyond the end of file, aka \<EOF>. it's more like a visual effect, rather than actual cursor position.