Gangmax Blog

Tabs and split screens in vim

Split Screen

  1. Open/close multiple files in split screens:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Open from start.
vi -o file1 file2 # Open split screens horizontally.
vi -O file1 file2 # Open split screens vertically.
vim -d file1 file2 # OPen split screens vertically and compare.
vimdiff file1 file2 # As above.

# Open while in vim.
Ctrl-w s split the current file horizontally
Ctrl-w v split the current file vertically
:sp file open a new file screen horizontally
:vsp file open a new file screen vertically

# Close.
Ctrl-w c close current screen
Ctrl-w q close current screen and if it's the last one exist vim
  1. Cursor movements:
1
2
3
4
5
Ctrl-w h      jump to the left screen
Ctrl-w j jump to the below screen
Ctrl-w k jump to the above screen
Ctrl-w l jump to the right screen
Ctrl-w w jump to the next screen
  1. Change current screen position:
1
2
3
4
Ctrl-w H      move the current screen to left
Ctrl-w J move the current screen to below
Ctrl-w K move the current screen to above
Ctrl-w L move the current screen to right
  1. Change screen size:
1
2
3
Ctrl-w =      make size equal
Ctrl-w + increase size
Ctrl-w - decrease size

tabs

1
2
3
4
5
6
7
vim -p file1 file2  # Open files in tabs
:tabnew file open file in new tab
:tabc close the current tab
:tabo close all tabs but the current one
:tabs view all opened tabs
:tabp move cursor to the previous tab
:tabn move cursor to the next tab

vi & shell

1
2
:shell    open shell without leaving vi
exit exit shell and go back to vi

tab

1
2
3
4
5
6
:set smarttab        # decide smartly how many spaces for a tab from the content of the file.
:set tabstop=4 # How many spaces is displayed for a tab.
:set softtabstop=4 # ???
:set shiftwidth=4 # How many spaces is inserted for each tab key strike.
:set expandtab # expandtab/noexpandtab: make tab to space or not.
:retab # make all tabs to spaces

Refer here, here, here, here, here and here.

Comments