Liunx basic commands (vim editing files)

Source: Internet
Author: User

Hello everyone, the content continues to explain. This time, we will introduce the vim file editing command in liunx. Well, this command can bring out so much content as you can imagine its importance, in this section, I suggest you contact us to learn more, because this will affect the speed of future operations. Come on ..


Vim Text Editor


Edit File

Vi


[Root @ 0425 ~] # Vim xu

After entering the command mode

Input mode

Last Row Mode



Enter the input mode in command mode


A is inserted after the current character

A: Enter the end of the current row

I Current Character Input

I current character header Input

O input the next row of the current row

O input of the previous row of the current row

S. Delete the current character and enter

S. After deleting the current row, enter



Command mode


U undo one-step operation

Ait + r restore previous step


Home

End


Copy


Yy is to copy a row

P is the next line of the row where the cursor is located)



Copy 3 rows

3yy is to copy 3 rows

P Paste


Cut


50 dd cut 50 rows

P Paste


Delete


Delete 50 rows in 50dd


The difference between deleting and pasting is that p-pasting is not needed.



^ Beginning and end of the row $



D ^ Delete the current character to the beginning of the line

D $ Delete the current character to the end of the line



W. the first character of the next word


Yw copies a word from the cursor to include the cursor

Dw cut a word


G indicates the ending line.


Gg indicates the first line



Dgg deletes the current row to the first row


DG deletes the current row to the end


------

The last row mode and the last row mode are all input:


Input:

W save

Q exit

Wq save and exit

Q! Force exit

W! Force save

Wq! Force save and exit


W aa is saved as aa in the current directory


2, 4, w aa, 2 to 4 rows stored in the current directory named aa





Quickly move the cursor in vim


H: Move to left l: Move to right

K: Move up j: Move down


Move now

The keyboard is up, down, and right



Bytes -----------------------------------------------------------------------------------

Read a file


Open vim

Input: e/root/aa



Append a file to another file

Vim/etc/aa


: R/tmp/bb



Re-read the current file

: E!




Search content


Search

/From top down? From bottom to top n N next



Remove search keywords

Search for a character that does not exist, and press OK.



Replace part: s ///


: S/AB/$/

: S/AB/$/g replace the whole

: % S/AB/$/replace all rows

: 3, 6 s/AB/$/g replace 3 to 6 rows

: S/AB/$/gc optional line replacement



: % S // s/g remove spaces \ s spaces of all rows

: % S/\ t // g remove all spaces \ t tabulation symbols

\ N merge into one row

Remove spaces (\ s) Starting with lines 2-6)

2, 6 s/^ // g

2, 6 s/^ \ s // g



Remove all spaces in the entire file

% S/\ s // g

% S // g

% S/* // g



Replace line feed characters with spaces (\ n)

: % S/\ n // g


Remove all empty rows


G/^ $/d

G/^ \ s * $/d



Call up row number

: Set nu


Remove row number

: Set nonu


Auto indent


Set autoindent

Set noautoindent



Save and exit


: X is as bad as wq and sometimes cannot be saved)

Enter a password for the encrypted file

: X

Others can also perform the 2nd password.



Cancel Password

Input here: X 2nd times not input


View process l: Move to the right


[Root @ 0425 a] # ps-ef


------------------


Vim main configuration file


[Root @ 0425 etc] # vim/etc/vimrc



Open multiple files


[Root @ 0425 ~] # Vim cc.txt aa.txt cc.txt


: Args: next: prev: last: first ctrl + 6)




Multiple files are stored on the same screen at the same time.

Open a file

Vimdiff aa.txt cc.txt tt.txt has a messy color

[Root @ 0425 ~] # Vim-O cc.txt aa.txt cc.txt no color


Ctrl + ww is to switch files



Vim Help documentation


[Root @ 0425 ~] # Cd/usr/share/vim/vim70/tutor/

[Root @ 0425 tutor] # If gedit tutor. zh. euc is opened, it is garbled to change character coding to UTF-8.


It is not garbled when it is replaced here. It cannot be used in Chinese)


Convert UTF8 to GB18030 and output tutor. zh. euc to test.txt.

[Root @ 0425 tmp] # iconv-f UTF8-t GB18030 tutor. zh. euc-o test.txt

-F file source Character Set-t output character set-o output file


This article is from the "history_xcy" blog, please be sure to keep this http://historys.blog.51cto.com/7903899/1296609

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.