This article explains multiple ways of opening files.
How to open files in Vim Editor.
There are multiple ways we can open files. One way, from a terminal, You can open the VIM editor with a filename using the below command
vim filename
It opens the vim editor and the file is opened by default.
Another way, Let’s see How to open files from within Vim Editor
The following are the steps required
- Opened Vim editor
- Ctrl + V to change to visual mode
- type
:e
and space followed by a filename
:e main.js
It opens the main.js file in the Vim editor.
if you want to open a file in a new window, You have to use the below commands
run below command to open the file below(horizontal split) the current file
:new main.js
It opens the file in horizontal split mode
run the below command to open the file inside by side(vertical split)
:vert new main.js
How to open files in readonly mode in Vim editor
With the command line, You can use -R option with the filename.
Type below command
vim -R main.js
It opens the vim editor and the main.js file is opened in it.
Another way, Let’s see How to open files in read-only mode from within Vim Editor
type the below command in the already opened Vim editor
:view main.js
main.js file is opened in the VIM editor with read-only mode and does not allow to modification and saving of the file.