In vimscript you can use:
" Save the window where you are currently let l:currentWindow=winnr() " Do stuff where you change of window " Go back to the original window exe l:currentWindow . "wincmd w"
For more information, doc always reads perfectly:
Edit Another way to do this is to use wincmd p :
wincmd is the vimscript equivalent for Ctrl w in normal mode.
In normal mode, when you change the window, you can use Ctrl w + p to return to the previous window. So in vimscript you just use:
wincmd p
Returns to the previous window.
Of course, if the rest of your function uses more than two sections, you will not return to the original window, but if you have only two splits, it may be easier than using a variable to save your window number.
source share