user861746
user861746

Reputation: 581

Shortcut for switching back to last window in Vim?

Ctrlw1w switches to the first window.

If currently I frequently edit in two of several windows, a shortcut for switching back to the last active window would be perfect.

Is there such a shortcut?

Upvotes: 28

Views: 12071

Answers (3)

Ingo Karkat
Ingo Karkat

Reputation: 172520

You can build your own short mapping; Vim is infinitely flexible in this regard. For example, many find these useful:

:noremap <C-j> <C-w>j
:noremap <C-k> <C-w>k
:noremap <C-h> <C-w>h
:noremap <C-l> <C-w>l

Also, learn how to look up commands and navigate the built-in :help; it is comprehensive and offers many tips. You won't learn Vim as fast as other editors, but if you commit to continuous learning, it'll prove a very powerful and efficient editor.

Upvotes: 5

JupiterP5
JupiterP5

Reputation: 328

As Kent said <c-w><c-p> will go to previous

You can also navigate between windows using the directions h, j, k, and l

<c-w><c-h>
<c-w><c-j>
<c-w><c-k>
<c-w><c-l>

<number><c-w><c-w> will navigate to a specific window

Upvotes: 9

Kent
Kent

Reputation: 195029

did you try

<c-w><c-p>

?

from help:

CTRL-W p                    *CTRL-W_p* *CTRL-W_CTRL-P*
CTRL-W CTRL-P   Go to previous (last accessed) window.

                        *CTRL-W_P* *E441*
CTRL-W P    Go to preview window.  When there is no preview window this is
        an error.
        {not available when compiled without the |+quickfix| feature}

Upvotes: 61

Related Questions