Start the hello world on the virtual machine (command line and text mode)

I’m using vmware Ubuntu 20.04 to
start our virtual life here: Hello World
I used vi at the beginning, but I haven’t used it to understand. Finally, I chose vim that is applicable to the operating system and installed the instructions for wim.

sudo apt install vim

I did not change the source here. If it is the company's intranet, it may be downloaded, just change to 4G.

The difference between vi and vim

1) In the vi editor, you can only undo the last command by pressing u, and you can undo unlimited in vim.
2) The vi editor runs in UNIX-like, and vim can not only run UNIX, but can also be used on multiple operating platforms such as windows, mac, etc., and vim can be used as vi.
3) Vim can use different colors to highlight your code.
4) Both vi and vim are editors in Linux. The difference is that vim is more advanced and can be regarded as an upgraded version of vi. vi is used for text editing, but vim is more suitable for code

begin

You can create a .c source file in the desktop path:

touch hello.c

If you want to delete, you can use:

rm hello.c

Use vim to enter the editor:

vim hello.c

As shown in the figure:
Insert picture description here
Press the i key to edit the code. After the editing is completed, press esc, then shift+: input wq, press Enter to
Insert picture description here
continue compiling :

gcc -o hello hello.c

Explanation: Compile an executable file named hello to
execute the executable file

./hello

Run the executable file, the output on the terminal is:
Insert picture description here

Or: (the second method)

gcc hello.c

Executable file
If the name is not specified, the executable file of a.out will be generated by default

./a.out

Run the executable file, the output on the terminal is:
Insert picture description here

The command line mode (normal mode) is
definitely not the case when you first entered the interface. When you first entered, it was in the command line mode. After starting vim, it is in the normal mode (ie, command line mode) by default. No matter what mode you are in, pressing the key (sometimes you need to press it twice) will enter the normal mode.
Insert mode
If you want to edit the code, you can press the i, a, o, I, A, O keys in the normal mode to enter the insert mode. In insert mode, the corresponding character will be written when the key is pressed.
Command mode
In the normal mode, press the: (colon) key to enter the command mode. In the command mode, you can execute some input and execute some commands provided by vim or plug-ins, just like in a shell. These instructions include setting up the environment, file operations, calling a certain function, and so on.
Visual mode
Press v, V, +v in the normal mode to enter the visual mode. The operation in the visual mode is a bit like operating with a mouse. When selecting text, there is a visual sense of mouse selection, which is sometimes very convenient

Close file

:q exit;
:q! exit without saving;
:w save;
:w! force save;
:wq save and exit
:wq! force save and exit

Mode conversion

Normal -> Input: The functions implemented by the following parameters are all converted to input mode, but the position of the cursor after conversion is different (if you are interested, you can try it, although it does not make much sense!)
i: At the current cursor position In front of the character, switch to input mode;
a: After the character where the current cursor is located, switch to input mode;
o: Create a new line below the line where the current cursor is located, and switch to input mode;
I: At the line where the current cursor is located At the beginning of the line, switch to input mode;
A: At the end of the line where the current cursor is located, switch to input mode;
O: Create a new line above the line where the current cursor is located, and switch to input mode;

Input -> normal:
ESC
normal -> last line::
(colon)
last line -> normal:
ESC, ESC
Note: It is not possible to switch directly between input mode and last line mode.

Text editor to achieve code editing, no need to be in command line mode

Insert picture description here
Save contrl+s, and then follow the compilation method, the compilation method is the same as above, according to your own needs.

Guess you like

Origin blog.csdn.net/weixin_42271802/article/details/106410281