Execute Code in vi Editor: Linux Guide
To run the code in the vi editor, you can follow these steps:
- Open the terminal and type the command “vi” to open the file you want to edit.
vi filename
- Edit code in the vi editor, press the Esc key to enter command mode, and then enter :wq to save and exit the file.
- To run the code in vi, you can enter the terminal and use the following command:
vi -c 'wq' -c 'exec "!./filename"' filename
In vi editor, -c ‘wq’ saves and exits the file, while -c ‘exec “!./filename”‘ executes the code in the file.
- After executing the above command, the vi editor will save and exit the file, and execute the code within the file.
This way, you can run the code in the vi editor.