How to use multiple windows in Vim

This article provides some tips on how to use multiple windows in Vim.

vim-windows

Start Vim with n multiple windows

  1. n verticals windows.
    vim -On filenames
  2. n horizontal windows.
    vim -on filenames

Note: n is the number of windows.

Close a window

  1. Close the current window.
    Ctrl+W c
  2. Close the current window. If it is the only window left, quit Vim.
    Ctrl+W q

Split a window

  1. Split horizontally the current file.
    Ctrl+W s
  2. Split horizontally and open a file.
    :sp filename
  3. Split vertically the current file.
    Ctrl+W v
  4. Split vertically and open a file.
    :vsp filename

Move the cursor between windows

  1. Move to the right window from the current windows.
    Ctrl+W l
  2. Move to the left window from the current windows.
    Ctrl+W h
  3. Move to the top window from the current windows.
    Ctrl+W k
  4. Move to the bottom window from the current windows.
    Ctrl+W j
  5. Move to the next window below the current one. If no below window exist, move to the top window.
    Ctrl+W w

Rotate windows location

  1. Move the current window to the right.
    Ctrl+W L
  2. Move the current window to the left.
    Ctrl+W H
  3. Move the current window to the top.
    Ctrl+W K
  4. Move the current window to the bottom.
    Ctrl+W J

Window resizing

Resizing windows can be made by using the mouse as well as the following commands.

  1. Make all windows equal in height.
    Ctrl+W =
  2. Increase height.
    Ctrl+W +
  3. Decrease height.
    Ctrl+W -

Note: Thanks to Ferd T-H, resizing could also be done by using

Ctrl+W < or >

Conclusion

I hope that these commands are enough for you to start using windows in Vim. However, if you know some good command(s) to please don’t hesitate to leave a comment.

If you are new here, you might want to subscribe to the RSS feed or newsletter.

Enter your email address:

Related

This entry was posted in Linux, Windows and tagged , . Bookmark the permalink.

12 Responses to How to use multiple windows in Vim

  1. Waseem says:

    Everything is fine here except for the term “window”. Those are tabs buddy. I did not know about Ctrl+W thingy. Thanks a lot. :)

  2. Ferd T-H says:

    note that :sp and :vsp are the same as Ctrl+W s and Ctrl+W v and that using Ctrl+W q is the same as :q.

    You can also increase/decrease windows’ width with Ctrl+w .

    • Selinap says:

      @Ferd T-H: But, with “:sp filename” and “:vsp filename”, you can open a new window with other file, instead of opening the same file splits in a new window.

  3. Ferd T-H says:

    The comment system ate my characters!

    “You can also increase/decrease windows’ width with Ctrl+w < and Ctrl+w >.”

  4. Daniel Ziegler says:

    Minor correction:

    “4. Split horizontally and open a file.” should be “4. Split vertically and open a file.”

  5. petur says:

    “Make all windows equal in height.
    Ctrl+W s”

    Does not work. This is the same command as split window horizontally. Ctrl+W = seems to make all windows the same height.

    Thanks.

  6. Pingback: Beginners Tips and Tricks for Better Data Processing at The Data Scientist

  7. Pingback: Beginners Vim Tips for Better Data Processing

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>