Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut for switching back to last window in Vim?

Tags:

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?

like image 422
user861746 Avatar asked Apr 02 '13 16:04

user861746


People also ask

How do I quickly switch between windows in Vim?

To move from the current Vim window to the next one, type CTRL-W j (or CTRL-W <down> or CTRL-W CTRL-J).

What does Ctrl w do in Vim?

Ctrl-w = tells Vim to assign an equal number of lines to each viewport. To move between the viewports while working, use Ctrl-w j to move down, and Ctrl-w k to move up. This should prove easy to remember — Ctrl-w for “window” commands, and the normal vi movement commands j for down and k for up.

How do I revert back to old Gvim?

Like a web browser, you can go back, then forward: Press Ctrl-O to jump back to the previous (older) location. Press Ctrl-I (same as Tab) to jump forward to the next (newer) location.


3 Answers

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}
like image 183
Kent Avatar answered Oct 24 '22 07:10

Kent


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

like image 7
JupiterP5 Avatar answered Oct 24 '22 07:10

JupiterP5


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.

like image 6
Ingo Karkat Avatar answered Oct 24 '22 06:10

Ingo Karkat