Detailed Linux vim command

 Linux vi and vim are both 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 coding. 

    Now the command line of vim is collected in the following: 


vi has 3 modes: insert mode, command mode, low-line mode. 

    Insert Mode: In this mode, you can enter characters, press ESC to return to command mode. 
    Command mode: You can move the cursor, delete characters, etc. 
    Low-line mode: You can save files, exit vi, set vi, search and other functions (low-line mode can also be regarded as command mode). 

1. Open, save, and close files (used in vi command mode) 

vi filename //Open the filename file 
: w //Save the file 
: w vpser.net //Save to the vpser.net file 
: q //Exit the editor, If the file has been modified, please use the following command 
: q! //Exit the editor without saving 
: wq //Exit the editor and save the file 
2. Insert text or line (used in vi command mode, after executing the following command, it will Enter insert mode, press ESC to exit insert mode) 

a //Add text 
i to the right of the current cursor position //Add text A to the left of the current cursor position  //Add text I
to the end of the current line //In the current position 
Add text at the beginning of the line (the beginning of a non-blank character) 
O //Create a new line above the current line 
o //Create a new line below the current line 
R //Replace (overwrite) the current cursor position and some text that follows 
J //Merge the line where the cursor is located and the next line (still in command mode) 
3. Move the cursor (used in vi command mode) 

1. Use the up, down, left, and right arrow keys 

2. In command mode: h left, j down, k up, l right. 
Spacebar to the right, Backspace to the left, Enter to move to the beginning of the next line, - to move to the beginning of the previous line. 
4. Delete and restore characters or lines (used in vi command mode) 

x //delete the current character 
nx //delete n characters starting from the cursor 
dd //delete the current line 
ndd //delete n including the current line down Line 
u //Undo the previous operation 
U //Undo all operations on the current line 
5. Search (used in vi command mode) 

/vpser //Search for the vpser string under the cursor 
? vpser //Search for the vpser string on the cursor 
n //Search down the previous search action 
N //Search up the previous search action 
6. Jump to the specified line (used in vi command mode) 

n+ //Jump down n lines 
n- //Jump up n lines 
nG //Jump to the line 
G with line number n //Jump to the bottom of the file 
7. Set the line number (used in vi command mode) 

:set nu //Display the line number 
:set nonu //Cancel the display of the line number 
Eight, copy, paste (used in vi command mode) 

yy //Copy the current line to the buffer area, you can also use "ayy to copy, "a is Buffer, a can also be replaced with any letter from a to z, which can complete multiple copy tasks. 
nyy //Copy the current line down n lines to the buffer, you can also use "anyy copy, "a is the buffer, a can also be replaced with any letter from a to z, you can complete multiple copy tasks. 
yw //Copy the characters from the cursor to the end of the word. 
nyw //Copy n words starting from the cursor. 
y^ //Copy the content from the cursor to the beginning of the line. VPS Detective 
y$ //Copy from cursor to end of line. 
p //Paste the content in the clipboard after the cursor, if the previous custom buffer is used, it is recommended to use "ap to paste. 
P //Paste the content in the clipboard before the cursor, if the previous custom buffer is used Custom buffer, it is recommended to use "aP" for pasting. 
9. Replace (used in vi command mode) 

:s/old/new //Replace the first occurrence of old in the line with new 
:s/old/new/g //Replace all old in the line with new 
:n,ms/ old/new/g //Replace all old in lines from n to m with new 
:%s/old/new/g //Replace all old in the current file with new 
10. Edit other files 

:e otherfilename //Edit the file whose filename is otherfilename. 
11. Modify the file format 

: set fileformat=unix //Modify the file to unix format, such as the text file below win will appear ^M under linux. 

===========================================================

1, first open a file:

      vim   filename

2, go to the end of the file

      Type G in command mode

3, go to line 10

      Enter 10G in command mode

4, delete everything: first go to the end of the file with G, then use the following command:

     :1, .d

5. Delete the contents of lines 10 to 20: first go to line 20 with 20G, and then use the following command:

     :9, .d

6. Some notes on deletion:

            1 In vi, "." means the current line, "1, ." means from the first line to the current line, and "" means delete.

            2 If you just want to delete a certain line, point the cursor to the line, and then enter dd.

7. Set the display line number

Execute in  vim  (press colon directly in normal mode and enter the following command)

1
: set  number

 

:set nu //Display line number 
:set nonu //Cancel display line number 

===================================================================

 

Delete entire line in VI editor under Linux system

 

dd: delete a whole row where the cursor is located (commonly used)
ndd: n is a number. Delete the downward n lines where the cursor is located, for example, 20dd is to delete the downward 20 lines where the cursor is located
d1G: delete all data from the cursor to the first line
dG: delete all data from the cursor to the last line
d$: delete the cursor at the last character of the line
d0: that is the number 0, delete the cursor to the front of the line a character
x, X: x delete a character backward (equivalent to the [del] key), X forward Delete a character (equivalent to [backspace] is the backspace key)
nx:n is a number, delete n characters backwards continuously

 

x //delete the current character 
nx //delete n characters starting from the cursor 
dd //delete the current line 
ndd //delete n lines including the current line down 
u //undo the previous operation 
U //undo the current line all operations of 

 

a //Add text to the right of the current cursor position 
i //Add text to the left of the current cursor position 
A //Add text to the end of the current line 
I //Add text to the beginning of the current line (lines with non-blank characters First) 
O //Create a new line above the current line 
o //Create a new line below the current line 
R //Replace (overwrite) the current cursor position and some text that follows 
J //Merge the line where the cursor is located and the next line to a line ( still in command mode) 

 

$ tar -zxvf file2.tar -C /home/usr2

 

from:http://ericslau.iteye.com/blog/1703443

 

===============================================

Detailed tar compression and decompression commands

tar

-c: create a compressed archive
-x: decompress
-t: view content
-r: append files to the end of the compressed archive
-u: update the files in the original compressed package

These five commands are independent, and one of them should be used for compression and decompression. It can be used in conjunction with other commands, but only one of them can be used. The following parameters are optional when compressing or decompressing archives as needed.

-z: with gzip attribute
-j: with bz2 attribute
-Z: with compress attribute
-v: show all processes
-O: unpack file to stdout

The following parameter -f is required

-f: Use the file name, remember, this parameter is the last parameter, only the file name can be followed.

# tar -cf all.tar *.jpg
This command is to type all .jpg files into a package named all.tar. -c means to generate a new package, -f specifies the file name of the package.

# tar -rf all.tar *.gif
This command is to add all .gif files to the all.tar package. -r means to add files.

# tar -uf all.tar logo.gif
This command is to update the logo.gif file in the original tar package all.tar, -u means to update the file.

# tar -tf all.tar
This command is to list all the files in the all.tar package, -t means to list the files

# tar -xf all.tar
This command is to extract all the files in the all.tar package, -t means unpack

compression

tar -cvf jpg.tar *.jpg //Package all jpg files in the directory into tar.jpg 

tar -czf jpg.tar.gz *.jpg //Pack all jpg files in the directory into jpg.tar, and compress it with gzip to generate a gzip compressed package named jpg.tar.gz

 tar -cjf jpg.tar.bz2 *.jpg //Pack all jpg files in the directory into jpg.tar, and compress them with bzip2 to generate a bzip2 compressed package named jpg.tar.bz2

tar -cZf jpg.tar.Z *.jpg //Pack all jpg files in the directory into jpg.tar, and compress it with compress to generate a umcompress compressed package named jpg.tar.Z

rar a jpg.rar *.jpg //Compression in rar format, you need to download rar for linux first

zip jpg.zip *.jpg //Compression in zip format, you need to download zip for linux first

decompress

tar -xvf file.tar //decompress the tar package

tar -xzvf file.tar.gz // 解压 tar.gz

tar -xjvf file.tar.bz2 // 解压 tar.bz2

tar -xZvf file.tar.Z //decompress tar.Z

unrar e file.rar // depressurar

unzip file.zip //unzip the zip

Summarize

1. Decompress *.tar with tar -xvf

2. Decompress *.gz with gzip -d or gunzip

3. Decompress *.tar.gz and *.tgz with tar -xzf

4. Decompress *.bz2 with bzip2 -d or with bunzip2

5. Unzip *.tar.bz2 with tar -xjf

6. *.Z decompress with uncompress

7. Unzip *.tar.Z with tar -xZf

8. *.rar decompress with unrar e

9. Unzip *.zip with unzip

 

 

Guess you like

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