Vim function to switch between splits

I am trying to find a function that will return to the original window as split for vim. I know about the shortcut, and I also know about the function: call cursor. But is there a function that can allow me to return to the previous split window so that I can insert it into my vim function?

+5
source share
1 answer

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.

+6
source

Source: https://habr.com/ru/post/1232370/


All Articles