Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember cursor position when switching buffer #240

Closed
pluskid opened this issue Jul 19, 2012 · 2 comments
Closed

Remember cursor position when switching buffer #240

pluskid opened this issue Jul 19, 2012 · 2 comments
Labels

Comments

@pluskid
Copy link

pluskid commented Jul 19, 2012

Hi, I'm using the following code to remember cursor position when switching buffer:

au BufLeave * let b:winview = winsaveview()
au BufEnter * if(exists('b:winview')) | call winrestview(b:winview) | endif

it works if I use :bn or :bp to switch buffers. But it doesn't work with ctrlp. Is it that ctrlp isn't triggering those events or isn't triggering at the correct moment? I don't know. But I hope I could see my cursor at the original position when switching buffer with ctrlp. Thank you very much!

@kien
Copy link
Owner

kien commented Jul 19, 2012

Those autocmds work fine for me. I also use some autocmds to restore cursor position and folds and never had a problem.

Can you consistently reproduce this? If you can, please provide a test case including the buffers you have open, how you move away and reopen them with ctrlp.

@pluskid
Copy link
Author

pluskid commented Jul 19, 2012

@kien hi, sorry for bothering. After checking and experimenting with clean environment, I found its actually that the two lines of autocmd that is causing my cursor position to jump to the beginning of the buffer sometimes. After commenting out the two lines, everything works fine (though the cursor still jumps to the beginning of line each time when buffer is switched, but I guess this is a problem of vim itself). It looks strange but at least now it works. Thank you very much for your help and for creating such a beautiful plugin.

@pluskid pluskid closed this as completed Jul 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants