Excerpt from Zhu Youpeng Teacher's public lesson video
3, the use of the Editor VI (VI and VIM contact)
What is an editor? The editor is a software, its main function is to edit. such as writing a file, writing code.
Common editors in Windows, such as their own notepad. More useful Notepad++,ultraeditor,slickeditor
Linux common editor, comes with the oldest VI. More useful vim,gedit.
Note: The relationship between VI and Vim: VIM is an upgraded version of VI, it is recommended to use VIM.
When we refer to VI in the back, we all refer to vim.
3.1, VI Basic use
* Use VI to open/create a file, vi pathname
Two modes of *VI:
Command mode: When VI is opened by default to command mode, to enter the input mode, you need to press A or I key. In command mode, everything entered on the keyboard is treated as a command by VI.
In command mode, it is best not to enter it randomly. The corresponding command should be entered at this time, to let VI do the corresponding thing.
Input mode: The input mode is used to enter content into the file. You can press a or I into input mode from the command mode. After entering the input mode, you are free to press the keyboard to enter it. If you want to save after the input is complete, go back to command mode (because saving is also a command). Press the ESC key in input mode to return to command mode.
Note: Look at the lower left corner of the screen, when the command mode is silent message or prompt for the file name, etc. in the input mode, prompt--INSERT--
How to save in command mode:
: Wq Save and exit
: W only save does not eject
: Q Do not save exit come in and look at it without changing out
: q! does not save forced exits
: wq! Save and Force exit
3.2, VI of the advanced use
* Find
In command mode, enter/xxx, you can find the xxx
* Fast Switching line
In command mode, you can quickly switch to num lines by entering: Num
* Set Display line number
In command mode, enter: Set Nu to display line numbers
Note: Setting does not display line numbers, command mode input: Set Nonu
Set the permanent display line number, you need to modify the VI configuration file. Open the configuration file for VI ~/.VIMRC, where you can enter set Nu.
* Row Delete
Command mode, first move the cursor to the row you want to delete, and then enter DD
If you want to delete contiguous rows, for example to delete contiguous 3 rows, use 3DD
* Line Copy and paste
Copy: Command mode, NYY
Paste: In command mode, p
Details, when copying to put the cursor in the first line of multiple lines, paste the actual
Paste to the next line in the row where the current cursor is located.
3.3. Authority representation & Management in Linux
3.3.1, normal user and privileged user su command switch user
There are ordinary users and privileged users in Windows, the privileged user is administrator, and ordinary users can have many.
The privileged user is the administrator of the system and has permission to operate on all files within the system. Each ordinary user can only process their own files, no access to other users ' files, and can not handle the operating system files.
Linux also has the distinction between ordinary users and privileged users. The privileged user is the root user. Normal user permissions are limited, for example, that ordinary users cannot
Cd/root, ordinary users cannot use Apt-get install to install software.
3.3.2, rwx, and permission representations
Ls-l Show Details
drwxr-xr-x10 characters, the first of which represents a file type. The remaining 9 are divided into 3 groups representing the file permissions.
The first three permissions on the file that represent the owner of this file
The middle three represents the permissions of the group to the file that this file belongs to
The last three represent the permissions of other users on the file
Rwx How to parse: R for readable, W for writable, X for executable
RWX: Readable, writable, executable
R-x: Readable, non-writable, executable
r--: Readable, non-writable, non-executable
3.3.3, using sudo to temporarily get root privileges
This is a feature of Ubuntu, in Ubuntu can use the sudo command to let ordinary users temporarily get the root user permissions , without having to switch users.
Linux Small white Introductory three