2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
The i.MX8MM processor uses the advanced 14L PCFinFET process, providing faster speed and higher power efficiency; quad-core Cortex-A53, single-core Cortex-M4, up to five cores, main frequency up to 1.8GHz, 2G DDR4 memory, 8G EMMC storage. Gigabit industrial-grade Ethernet, MIPI-DSI, USB HOST, WIFI/BT, 4G module, CAN, RS485 and other interfaces are all available. H264, VP8 video hard encoding, H.264, H.265, VP8, VP9 video hard decoding, and provide related processes, support 8-way PDM interface, 5-way SAI interface, 2-way Speaker. The system supports Android 9.0 (supports root access) Linux 4.14.78+Qt 5.10.1, Yocto, Ubuntu 20, Debian 9 systems. Suitable for smart charging piles, Internet of Things, industrial control, medical, intelligent transportation, etc., can be used for any general industrial and Internet of Things applications,
【Official Account】Xunwei Electronics
【Fan Group】258811263 (join the group to get driver documentation + routines)
The corresponding video explanation link for this chapter (watch online):
Using Vim Editor → https://www.bilibili.com/video/BV1M7411m7wT?p=6
The vi editor is the original editor for Unix systems. It uses a console graphics mode to emulate a text editing window, allowing you to view lines in a file, move around in a file, insert, edit, and replace text. Although it may be the most complex editor in the world, its large number of features has made it a mainstay tool for Unix system administrators for many years. When the GNU project ported the vi editor to the open source world, they decided to make some improvements to it. Since it is no longer the original vi editor that was part of Unix, the developers renamed it to vim, or vim.
Not only on Windows, there are WPS and Office, but also on Ubuntu, there are many editors. Because almost any distribution has vi/vim editor, and on embedded Linux, vim editor is usually integrated, so most versions of vim editor are supported, so we have to learn vim.
vim is an enhanced version of vi. Almost all vi commands can be used on vim, and it is easier to use than vi. Because the two are the same, we will not distinguish between vim and vi in the following study.
We can double-click the icon on Windows, but the vi editor has no menu and is operated through commands. We open the console, which is in the home/topeet path. We directly enter vi filename, which is test.c, and the text editor will open. If the file I open does not exist, it will create a new file. If the file exists, it will open it directly. As shown below
You can start the vim editor by typing the vim command and the name of the file to be edited in the terminal (if no file name is specified when starting vim, or the file does not exist, vim will open a new buffer area for editing).
The vim editor has three operating modes:
The first mode is the general mode.Let's take a look. After we open the vim editor, the mode we are in is the general mode.
The second mode is edit mode.From the literal meaning, we can enter some text in the edit mode. To switch to the edit mode, just press i on the keyboard, and INSERT will appear, as shown in the figure below. The current mode is the edit mode. We can enter text content in the edit mode, either words or letters.
We return from edit mode to normal mode by pressing the ESC key on the keyboard. Now there is no word INSERT in the lower left corner.
The third is the command line mode, I am currently in the normal mode, we switch to the command line mode and directly enter the ":" on the keyboard. As shown in the figure below, there is a ":", which means the current state is the command line mode.
For example, enter the command "set number" in the command line mode to display the line number.
As shown below:
We can press the ESC key in command line mode to return to normal mode. For example, if I switch from normal mode to edit mode, I press i on the keyboard, and then I return and press ESC. We use ESC to return to these three modes, and we switch by pressing the ":" or "i" key on the keyboard. These are the three modes of the vim editor. In addition to the i key on the keyboard, we can press the a or o key to enter the edit mode.
In normal mode, if vim can correctly identify the terminal type (which it should be able to do under normal circumstances), you can directly use the arrow keys to move the cursor in the text area.
vim also has unique commands for moving the cursor.
K: Move up
J: Move down
H: Move left
L: Move right
Ctrl+F (PageDown): scroll down one screen
Ctrl+B (PageUp): Go up one screen
We can double-click g on the keyboard in normal mode. The function of double-clicking g is to position the cursor to the first line; if we want to position the cursor to the last line, we click G, so that the cursor will be at the last line; if we want to position to the number of lines we want, we can use ngg. For example, if I want to move the cursor to the third line, I will enter 3gg. This is vim's quick positioning.
gg: position the cursor to the first line
G: Position the cursor to the last line
ngg: Position the cursor to line n
Using a text editor on Windows, copying and pasting is very convenient. Let me introduce you to a method similar to that on Windows, which is much more convenient than using commands directly.
First, place the cursor at the beginning of the line where we want to copy the content, use the up, down, left, and right keys to select the text, press Y on the keyboard after selecting, then press the esc key to return to normal mode, move the cursor to where we want to paste, and then press p on the keyboard.
If I want to copy the letters from 1 to 4, I first move the cursor to the beginning of the line, that is, the beginning of the line I want to copy, and then press v on the keyboard. A word VISUAL appears in the lower left corner. Then we use the up, down, left, and right keys on the keyboard to select the text we want to copy. After selecting, we press Y on the keyboard, as shown below
Then paste our text, we first press ESC on the keyboard to return to normal mode. Then move the cursor to the position where we want to paste, I paste it from the fifth line, just press p on the keyboard, this will copy all of them.
If I just want to copy one line and don't want to copy so many lines, then this operation will be too troublesome. There is also a simple way. For example, if I want to copy the 4th line, just double-click y on the keyboard, then move the cursor to the 9th line, and press p, so we copy a line.
If I want to copy multiple lines, I can also use this command to complete it. The author directly uses the nyy command. This command copies n lines below the current line. We use yy to copy the current line. Here I want to copy lines 3 to 6, which is a total of 4 lines. I enter 4yy here, and then I move the cursor to line 11. I directly press p on the keyboard, so that we can copy all 4 lines.
This is vi's copy command, which we often use.
yy: copy the current line
nyy: copy n lines below the current line
Method 1: Go directly into edit mode and use delete to delete
Method 2: Use dd command
dd: delete the line where the cursor is
ndd: delete n lines
n1,n2d: Delete the specified range of lines. This needs to be done in command line mode.
Method 1: I directly enter the edit mode and then press delete on the keyboard to delete the text. If this is too troublesome, you can also use the dd command directly. This command deletes the line where the cursor is. I am now in line 8, because it is INSERT. I first switch the mode to normal mode, and then I double-click d, and line 8 is deleted. As shown in the figure below.
Similarly, we can use ndd, which is used to delete n lines. For example, to delete lines 9 to 11, just enter 3dd, and all three lines will be deleted, as shown in the following figure.
In daily use, we sometimes need to delete many lines. It is too troublesome to delete them one by one using these commands. We can also delete a specified range of lines. Its format is n1,n2d. This command needs to be entered in command line mode.
I want to delete all the contents from line 1 to line 6. Press the colon on the keyboard to enter the command line mode and enter 1,6d, as shown below, and then press Enter, so that lines 1-6 are all deleted.
We use ctrl+z to undo on Windows. In the vim editor, undo is in normal mode. Enter the letter u to undo. Note that this is normal mode, and we cannot undo the text file we have closed. This is the same as on Windows. I want to undo the deleted content. The first step is to return to normal mode. If you are not sure which mode you are in, you can directly use the ESC key to return to normal mode, and then press u on the keyboard, so that the deleted content will be back. If we don't want to undo, how can we undo it? Undo is ctrl+r. As shown in the figure below.
We use ctrl+f to search on Windows, and in Ubuntu's vim editor, we search by entering "/" or "?" in command line mode. For example, if I want to search for the two letters da, I just press "/" on the keyboard. Now I enter the command line mode, enter da, and press Enter, and the letters da will be found. That is, enter /da,As shown below.
To search downward, click "n" on the keyboard, it will search downward, press ESC to return to normal mode, then enter "?", then enter da, press Enter, and then press n, it will search upward, so if we want to search upward, we use "?" to enter the command line mode. As shown in the figure below.
We first enter the command line mode and enter: "%s /xunwei/dianzi/g". We press Enter, and we replace Xunwei with Dianzi, as shown in the figure below. Its command format is: "%s /old/new/g".
:q! Force quit
:wq save and exit
:q quit without editing the text
Directly enter a colon to enter the command line mode. If you want to save and exit, directly enter wq and press Enter to save and exit. As shown in the figure below.
If we open the test.c file again, we can see that the modified content is still there. If we want to modify it without saving, we can delete this line and then enter a colon:. Enter q! to exit. Then open this text file and we can see that the deleted content is not saved, which means that our previous operation is not saved. As shown in the figure below.
If we want to exit directly, that is, we just opened the file and looked at the contents without editing the file, we can directly enter :qYou can exit. As shown in the figure below.
After saving, the vim editor will automatically save the test.c file for us, as shown in the figure below. We did not have a test.c file before.
So there is no need to create a file here. You can directly run vi plus the name of the file we want to create, then open and save it. It will automatically create a file for us. I will create a file named test4.c here and directly enter vi test4.c, there is no such file in our path, so the vim editor will create this file for us first, then open it, and then save it, and check it with ls, so that test4.c will appear in our path. As shown in the figure below.
vimdiff file1 file2 file3
Then vim editing also has a function of file comparison. We use vimdiff, followed by the files we want to compare. Let's compare test.c and test4.c. Let's take a look. This will produce a comparison result, as shown in the figure below.
vimdiff test.c test4.c
Most of the time we compare two files. Of course, this command can also compare more than two files. Here I am comparing it with test3.c, as shown in the figure below.
vimdiff test.c test4.c test3.c
This is the end of our introduction to the vim editor.