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 position:
func! Foo()
:norm mz
...
:norm `z
endf
This properly saves the cursor position, but it sometimes changes the window position, so that the current line moves from being near the top of the screen to being near the bottom or vice versa. Is there a way to preserve both cursor position and the on-screen position of the line?