How does Linux execute programs edited with vim?
To run a program that requires editing in vim on Linux, you need to follow these steps:
- Open the terminal: press the Ctrl+Alt+T key combination, or find the terminal application in the application menu and open it.
- To access the vim editor: enter the vim command in the terminal and press Enter. This will open a new vim editor window.
- Write the program: In the vim editor, you can use a variety of commands and editing techniques to write programs. For example, you can input code, edit text, save, and exit, etc.
- Save file: Enter command mode by pressing the Esc key, then type :w command and press Enter to save your file.
- To exit the vim editor: simply enter the command :q while in command mode and press Enter, to exit the vim editor.
Now that you have successfully edited and saved a program file, you can choose one of the two following methods to execute the program.
- Compile and execute the program in the terminal: If your program needs to be compiled, use the appropriate compiler to compile it into an executable file. For example, use gcc to compile C programs or g++ to compile C++ programs. Then navigate to the directory where the program is located in the terminal and execute the program using the following command:
- ./program name
- The program name is the name of the executable file generated after you compile it.
- To run a script in the terminal using an interpreter: If your program is a script file, you can use the appropriate interpreter to execute it. For example, for a Python script, you can execute the program using the following command:
- The name of the Python script file
- The script file name should be the same as the name of your Python script file.
Please note that in order to run the program, you need to ensure that the program file has execute permissions. If it doesn’t have execute permissions, you can use the chmod command to grant it permission to execute, for example:
chmod +x 程序文件名称