Using split is a way that user can open multiple documents in one vim session, but all the documents will be displayed in one display, split across the screen.
For example, we want to copy some content from /etc/passwd, into a file called /tmp/mylist
1. open /etc/passwd
$ vim /etc/passwd
2. To create splits
- to create vertical split and divide vim into 2 panels side by side, with the new panel opening /tmp/mylist
:vsp /tmp/mylist
- To create a horizontal split and divide vim into 2 parts, bottom and up, with the new panel opening a file called /tmp/mylist, use this command
:sp /tmp/mylist
- You can also create an empty buffer on the new horizontally split panel
:new
- And to create an empty buffer on the new vertically split panel
:vnew
3. To move between panels
- ctrl-w h or ctrl-w left arrow to move left
- ctrl-w j or ctrl-w down arrow to move down
- ctrl-w k or ctrl-w up arrow to move up
- ctrl-w l or ctrl-w right arrow to move right
4. To close, use below commands
- :q to close current panel
- :only to close other panels except the current one
- :qa to close all panels
- :qa! to force close all panels without saving
5. To resize the panels
- ctrl-w + or ctrl-w - to increase or decrease the current panel's height
- ctrl-w > or ctrl-w < to increase or decrease the current panel's width
- ctrl-w _ to maximize the current panel's height
- ctrl-w | to maximize the current panel's width
- ctrl-w = to make the panels' width and height uniform
6. To open multiple files in split mode
- vim -o file1 file2 to open file1 and file2 in horizontal split
- vim -O file1 file2 to open file1 and file2 in vertical split
No comments:
Post a Comment