harpoon icon indicating copy to clipboard operation
harpoon copied to clipboard

Keep viewport when switching files

Open lars-vc opened this issue 1 year ago • 8 comments

What issue are you having that you need harpoon to solve? I would like to keep the viewport after switching files, currently the line is always centered on the screen. Keeping the viewport would only be necessary in the same session (after nvim reboot this is not required)

Why doesn't the current config help? No options are provided for this

What proposed api changes are you suggesting? Vim already has some options to keep the viewport with winsaveview() and winrestview(view), these could be used to save the viewport.

lars-vc avatar Dec 13 '23 07:12 lars-vc

you want the same position the viewport was in before you left the file? is that what you are asking?

ThePrimeagen avatar Dec 15 '23 03:12 ThePrimeagen

Yes, when using harpoon I like to switch between files quickly, to for instance just take a glance at some code and hop back. When this centers the line every time, this gets disorienting. Example: I am working here image

Then quickly check another file with harpoon keybind and go back with harpoon keybind and now the line is centered image

lars-vc avatar Dec 15 '23 07:12 lars-vc

I also would like that.

lpanebr avatar Dec 16 '23 20:12 lpanebr

Okay, it seems like an okay feature. I don't really use it nor notices, so if someone would like to take a swing at saving the additional information required in the list items, context and using that on select I'd be just fine merging it in

ThePrimeagen avatar Dec 16 '23 22:12 ThePrimeagen

Okay, I tried some stuff but got a lil confused, so here https://github.com/ThePrimeagen/harpoon/blob/9031087ff1b18d0a34bd664719ec66cc8be1efd8/lua/harpoon/config.lua#L194 you save where you are at in the file when leaving a buffer correct? But when testing, it seems this code is never triggered (the logger line right before doesn't show up). So is this not working? Or am I doing something wrong.

lars-vc avatar Dec 18 '23 12:12 lars-vc

This wiki is related to the problem viewport problem @lpanebr . Might just use this for consistency everywhere https://vim.fandom.com/wiki/Avoid_scrolling_when_switch_buffers

lars-vc avatar Mar 05 '24 11:03 lars-vc

@lars-vc Thank you! This is just AWESOME and works like magic! ❤🎉

This wiki is related to the problem viewport problem @lpanebr . Might just use this for consistency everywhere https://vim.fandom.com/wiki/Avoid_scrolling_when_switch_buffers

lpanebr avatar Mar 05 '24 12:03 lpanebr

I am back, I'll review this today and merge/give feedback

ThePrimeagen avatar Apr 04 '24 11:04 ThePrimeagen