Different methods to split the vim screen

User Rating: 5.0 (1 votes)
Sending

Split the windows under vim effectively
When I wrote my first article on Basic commands for vim editor, then also I pointed out about it but with minimal points.
Here, I have tried to learn and share the splitting of vim screens using different methods. Thanks to internet and various resources that I came across while posting this simple article. Special thanks to StackOverflow :D
It will surely help when you are using on multiple files or you need to compare two files or you need to edit one file at two different place and wish to see both changes blah blah!

Here are the different methods that may help you to do so:
Method 1 (using command line in Linux)

I'm assuming you are using the command line. From vim –help, we got :

-o[N]                Open N windows (default: one for each file)
-O[N]                Like -o but split vertically
So type this to open files split horizontally, for example:
vim -o3 file1.txt file2.txt file3.txt
 
Method 2 (inside vim editor)
 
Ctrl-W s for horizontal splitting
Ctrl-W v for vertical splitting
Ctrl-w q to close one

Method 3 (inside vim editor)

  1. :sp filename (horizontal)
  2. :vsp filename (vertical)

Method 4 (inside vim editor)

  • vsplit and :vs splits the vim viewport
    :30vs splits the viewport and creates the current window to be 30 characters wide
  • For vertical screens: CTRL+W+ > or  CTRL+W +< (don’t type + while using it. It’s just to tell you that you need to press ctrl key, W (case-insensitive) and > altogether :D ) to make wider or narrower respectively.
  • And Ctrl+W+ = will make them equals
  • For  horizontal windows : Ctrl+W + increases the number of lines by one
  • :h for the list of all window commands (help command)

CTRL-W H           move current window to the far left
CTRL-W J           move current window to the very bottom
CTRL-W K           move current window to the very top
CTRL-W L           move current window to the far right

I hope it will help the developer in using vim screen effectively. Comments and critics are most welcome \m/

Follow Me

Sanjeev Jaiswal

Co-Founder at Alien Coders
He loves web programming and security and co-founder of Alien Coders. He usually shares and helps engineering students and IT professionals in academics and jobs.

An avid reader and quick learner.
Follow Me

FB Comments

comments

4 Comments

  1. Howard Collier September 19, 2012
  2. Anonymous September 19, 2012
  3. Shawn Dyer November 12, 2012
  4. sanjeev November 12, 2012

Leave a Reply


− 4 = one

  Home