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
Locate Cursor to Fifth Line
1
vim +5 vim_file
Locate Cursor to Last Line
1
vim + vim_file
Locate Cursor to the First Matching Pattern
1
vim +/commodo vim_file
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
Tile the Opening Files Vertically
Let’s open these two files at the same time vertically:
1
vim -O vim_file vim_file2
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.
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.
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.