In my vimscripts I sometimes have to use the windo
command to execute an action on each open split.
The problem with this command is that it cycles through all the open splits and ends on a different split than the one I was on when I started the command.
I understand the causes of this behavior, but I need to find a workaround to get back on my original split after using windo
. A solution I found is to do that:
let l:currentWindow=winnr()
windo [whatever I want to apply to all the splits]
exe l:currentWindow . "wincmd w"
Basically before using windo
I get the number of my current window in the variable l:currentWindow
. After using window I use exe
to execute wincmd w
which is the equivalent to Ctrl-w+w which allows to go to a window according to its number.
So far I haven't had a problem with this solution but I was wondering if there is another way to execute an action on each split without changing the cursor position?
I'm sure I'm not the first one to encounter this problem and other vimmers probably found different/better workaround.