The Vim text editor provides instructions that make it easy for us to operate, through which we can open files in a variety of ways.

Before we get started, let’s prepare some test content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
printf '%s\n' \
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nisi tellus,' \
'egestas sed dolor nec, eleifend venenatis mi. Mauris ac ligula' \
'scelerisque libero interdum varius. Aenean nec arcu nec turpis' \
'commodo mollis. Morbi suscipit felis libero, eu sollicitudin justo' \
'condimentum id. Praesent eu metus rutrum, varius leo malesuada,' \
'varius sapien. Vestibulum blandit, dolor bibendum bibendum ultricies,' \
'ipsum velit pretium arcu, eu maximus augue massa vitae justo. Etiam' \
'elit sapien, placerat quis libero a, tincidunt ornare erat. Praesent eu nibh' \
'ac sem mattis tincidunt. Aliquam erat volutpat. Nulla egestas dui ac urna' \
'convallis, vel egestas lectus ultrices. Morbi sit amet quam eget tortor' \
'laoreet laoreet id non libero.' > vim_file
cat vim_file
img

Prepare test content

Locate Cursor to Fifth Line

1
vim +5 vim_file
img

Locate the cursor to the fifth line of the file vim_file's content

Locate Cursor to Last Line

1
vim + vim_file
img

Locate the cursor to the last line of the file vim_file's content

Locate Cursor to the First Matching Pattern

1
vim +/commodo vim_file
img

Locate the cursor to the first matching pattern of the file vim_file's content

Tile the Opening Files Horizontally

For the upcoming demonstrations to continue, we need to create another file, just like the one created before, to change the name:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
printf '%s\n' \
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nisi tellus,' \
'egestas sed dolor nec, eleifend venenatis mi. Mauris ac ligula' \
'scelerisque libero interdum varius. Aenean nec arcu nec turpis' \
'commodo mollis. Morbi suscipit felis libero, eu sollicitudin justo' \
'condimentum id. Praesent eu metus rutrum, varius leo malesuada,' \
'varius sapien. Vestibulum blandit, dolor bibendum bibendum ultricies,' \
'ipsum velit pretium arcu, eu maximus augue massa vitae justo. Etiam' \
'elit sapien, placerat quis libero a, tincidunt ornare erat. Praesent eu nibh' \
'ac sem mattis tincidunt. Aliquam erat volutpat. Nulla egestas dui ac urna' \
'convallis, vel egestas lectus ultrices. Morbi sit amet quam eget tortor' \
'laoreet laoreet id non libero.' > vim_file2
cat vim_file2

Let’s open these two files at the same time horizontally:

1
vim -o vim_file vim_file2
img

Tile two opening files horizontally

Tile the Opening Files Vertically

Let’s open these two files at the same time vertically:

1
vim -O vim_file vim_file2
img

Tile two opening files vertically

Switching Between Tiled Files

1
Ctrl+w, up/down/left/right key    # Press Ctrl+w, release, and then either one of the arrow keys, the arrow key must be pressed after the releasing of the Ctrl+w combination key.
img

Switch to the second file's window with Ctrl+w and press left arrow key after the releasing of the combination key

Open Files in More Windows

Horizontal Window

1
Ctrl+w, s    # Press Ctrl+w, release, and then press the s key, the s key must be pressed after the releasing of the Ctrl+w combination key.
img

Open the file vim_file2 in another window horizontally

Vertical Window

1
Ctrl+w, v    # Press Ctrl+w, release, and then press the v key, the v key must be pressed after the releasing of the Ctrl+w combination key.
img

Open the file vim_file2 in another window vertically

References VIM Documentation

Buy me a coffeeBuy me a coffee