Moving Around Windows (Getting Your Cursor from Here to There)
It’s easy to move from window to window with a mouse in
both gvim and Vim.
gvim supports clicking with the
mouse by default, whereas in Vim you can enable the behavior with the mouse
option. A good default setting for Vim
is :set mouse=a
, to activate the
mouse for all uses: command line, input, and navigation.
If you don’t have a mouse, or prefer to control your session
from the keyboard, Vim provides a full set of navigation commands to
move quickly and accurately among session windows. Happily, Vim uses
the mnemonic prefix keystroke ^W
consistently for window navigation. The keystroke that follows defines the
motion or other action, and should be familiar to experienced vi and Vim users because they map closely to
the same motion commands for editing.
Rather than describe each command and its behavior, we will consider an example. The command-synopsis table should then be self-explanatory.
To move from the current Vim window to the next one, type
CTRL-W j (or CTRL-W
<down> or CTRL-W CTRL-J). The CTRL-W is the mnemonic for “window” command, and the
j
is analogous to Vim’s j
command, which
moves the cursor to the next line.
Table 11-2 summarizes the window navigation commands.
Note
As with many Vim and vi
commands, these can be multiply executed by prefixing them with a
count. For example, 3^Wj
tells Vim to jump to the third
window down from the current window.
Get Learning the vi and Vim Editors, 7th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.