Default and very famous editor comes along with Linux-Unix operating system is Vi (VIsual Editor). You can learn basic operations about the VI editor in this article. However along with the basic commands, we can Open multiple files and switch between them in vi editor.
How to Open multiple files and switch between them in vi editor
Basically you are aware that, in order to open file in VI editor you need to use command vi followed by name of the file. Now to Open multiple files and switch between them in vi editor use below syntax.
#vi file1 file2 fileN
Let’s take an example , You have two files under folder “/tmp/mann”
[root@ip-172-31-15-60 mann]# pwd
[root@ip-172-31-15-60 mann]# ls -lrt
-rw-r--r--. 1 root root 25 Jun 26 22:50 1.txt
-rw-r--r--. 1 root root 27 Jun 26 22:50 2.txt
Now lets try open these files using below command:
# vi 1.txt 2.txt
In case you want to open files in tab pages try the same command with -p option:
# vi -p 1.txt 2.txt
This will open the files “1.txt”& “2.txt” in tabs as below:
How to Switch Between files:
Now to switch to next file use below option in the command mode.
Now in order to go back to previous file or switch it back to previous file use below option in command mode of vi.
How to Open multiple files in Split window:
There is also one more way to Open multiple files and switch between them in vi editor. You can also open multiple files in splitted window with below command.
# vi -o 1.txt 2.txt
Splitted window after opening files look like this.
How to Switch between them
Now to switch between them follow below command in vi:
To learn more about VI editor options download cheat sheet eBook.
This book will teach you about all the necessary option to handle the files in efficient way.