Summing up the comments of the question:
-- I'm trying to write a function to rotate window splits to vertical if
current layout it's horizontal and vice versa when there're just two
-- Why not simply use ctrl-W_L? (or ctrl-W_R)
-- I want it to be convenient toggle function, it will automatically
detect the current layout and do the correct rotation for me instead
that I need to think it in my brain and choose the right command to
use. All I need to do is always hit the same key mapping.
For the layouts containing just two windows the following function should work:
" save the original position, jump to the first window
let initial = winnr()
exe 1 . "wincmd w"
if winnr() != 1
" succeeded moving to the right window
wincmd J " make it the bot window
" cannot move to the right, so we are at the top
wincmd H " make it the left window
" restore cursor to the initial window
exe initial . "wincmd w"
nnoremap <F3> :call Rotate()<CR>