I opened two files using -O

vim file1 file2 -O

it opens the files horizontally aligned but I dont know how switch between them ?


Ctrl + 'w' + 'r' to switch to the left side
Ctrl + 'w' + 'l' to switch to the right side
Generally, Ctrl + 'w' + 'r' works to get to either side.
See https://linuxhint.com/how-to-use-vim-split-screen/ for further commands.

  • This answer is incorrect. Ctrl+W r will rotate the buffers on the existing windows, actually swapping them. The command to switch the cursor to the left window is actually Ctrl+W h, but a more useful command is Ctrl+W w which will cycle through the windows right/down and then back to the top/left one. – filbranden Aug 20 '19 at 0:34

Use the Ctrlw + w command to move the cursor to the next window. (Also possible: Ctrlw + Ctrlw, pressing it twice.)

This command will cycle through windows to the right, then towards the bottom (in the same order you'd read the letters on a line, then the lines on a page), finally going back to the top-left window when done traversing them.

If you only have two windows, it will simply switch between them.

The fact that you can access this command by pressing the same key twice (even while holding down the Ctrl key) makes it the most convenient way to navigate through windows in Vim.

See :help CTRL-W_w for more details.

There are also many other window commands that use Ctrlw as a prefix. For example, you can use the typical movement commands (h, j, k and l) to move the cursor to a window in that specific direction (left, down, up and right, resp.) See :help windows for a full list of commands and options related to windows in Vim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.