I have some Vim functions that make changes to the document format. When I call this function, I currently use something like the following to save and restore my cursor positio
you can use getline() to save the current buffer line and winline() to save the current window line.
So it would go something like this:
There might be a few special cases you will have to take care of such as if the position is near the end or beginning of the file or if the file is smaller then the window size.