The use of vi editor of linux basic knowledge

Before introducing the vi editor, let's take a look at the use of aliases in the Linux system (the article knowledge is written from the blogger bug master, thanks to the blogger)

      Aliases are two different names referring to a person, and two different commands have the same effect.
Now, you must be wondering what aliases are on your system.
 
[root@localhost ~]#  alias              Query aliases in the system
alias cp='cp -i'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm = 'rm -i'
alias vi='come'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
 
How to define aliases, if I'm used to copy under dos and don't want to use cp, then I can define an alias for copy for cp.
[root@localhost ~]# alias copy=cp              assigns the cp command function to copy
[root@localhost ~]# alias drm="rm -rf"       will " rm -rf " command define a drm alias.
 
[root@localhost ~]# unalias copy       cancel alias
 
vim/vi editor                                                                                     
 
  vim/vi is a powerful screen text editor and the most commonly used text editor on linux and UNIX. Its function is to create, edit and display text files.
vim/vi has no menus, only commands.
vim is an enhanced version of vi, when many users are still accustomed to using vi to edit files
[root@localhost test]# vim services.test enter the file
Three modes of vi:

Three modes of conversion:
  Enter a, i, o in command mode  to enter  insert mode
  In insert mode  , press ESC to enter   command mode
  Enter in command mode  : (colon) to enter  edit mode
  If the command is wrong in edit mode  , return to  command mode
 
Do you think it's a bit confusing, in fact, we just need to remember that after vi enters the file, press the i key to edit the file.
After editing, press Esc to exit edit mode. There are three things that must be remembered when exiting.
:q is to quit (when the file has not changed)
:q! Exit without saving (when the file is changed)
:wq save and exit the specific operation of vim/vi  
: shift+zz Press shift+z twice in a row to exit and save 
 
Knowing some of the following commands will help us quickly edit and use vi 
 
Command mode:
 The command mode mainly uses the arrow keys to move the cursor position to edit the text. The common operation commands and their meanings are listed below.
 The up, down, left and right keys and h, j, k, l keys are used to move the cursor, respectively.
$ ------------ move to end of line
0 (zero) ----- move to the beginning of the line
H ---------- move to the top of the screen
M ------------ move to the center of the screen
L ------------ move to the bottom of the screen
gg --------- to the first line of the file
G ---------- to end of file
PageDn ----- move down one page
PageUp ----- move up one page
d+direction key----- delete text
dd ----- delete entire line
pp ----- copy the entire line
r ----- modify the character where the cursor is located
S ---- Delete the column where the cursor is located and enter the input mode
 
Insert mode:
 
You can enter "Insert Mode" from "Command Mode" with the following command
a------------ Append text after the subscript
A------------ Append text at the end of this line
i-------------Insert text before cursor
I-------------Insert text at the beginning of this line
o------------ Insert a new line under the cursor
O------------Insert a new line at the cursor
ESC -------- exit "insert mode"
 
Edit mode:
Edit mode mainly performs some text editing auxiliary functions, such as string search, substitution, and file saving operations.
:q -----End the Vi program, if the file has been modified, save the file first
:q! -----Force quit Vi program
:wq ----- save changes and exit the program
:set nu ---- make the line number appear before each line of text
:set nonu ------ Cancel the line number before each line
:n ------------ to line n

 

 
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324632654&siteId=291194637