Liunx Vim commands Edit file contents

Source: Internet
Author: User
Tags clear screen save file

Sometimes the project has been deployed in Tomcat, but you need to modify some of the contents of the configuration file or modify the content of a JSP file, you will think of the local modified files uploaded to the server and then replace it, in fact, you can use the VIM command directly edit the good ...

Here's an example ↓

Create a file in a folder first

Here I first created a test folder with the MkDir command, and then created a a.txt file with the vim a.txt command in the Test folder. You'll find that after you've implemented Vim A.txt, you'll be the following ↓

This time you press the I key to open the insert and then enter the text on the line.

Press ESC to exit Edit state after you enter, and then the last row type: wq! Save exit

Then enter the cat command to view the A.txt file and you will see the contents of the file you edited.
OK, this is just a simple example, then JSP and other files such as the same method of editing just here the example of the command too little, below gives me the online collection of the more complete command ↓

1.
Vim
Enter VIM in the command line and enter the VIM editor
2.
I
Click the i key, the lower end shows –insert–
Insert command, in Vim, any character may be useful
3.
Esc
Exit I (insert) command to use other commands
4.
: R filename
Reads the contents of a file and writes it to the current editor
5.
: w NewFileName
Writes the contents of the editor to a new file
6.
: W
Save the file in the editing process, which is equivalent to ctrl+s in Word
7.
:! Command
Temporarily leave the vi to instruction column mode to execute the command display results. For example
:!ls
Executing the shell command in the edit process LS
8.
: SH
Go to the shell command line, after executing the command ctrl+d exit re-enter vim edit continue Edit
Execute ctral+l to clear screen under shell command
9.
: Wq
Save File and exit
10.
Zz
Save the file and exit, with the previous command, note capitalization
11.
: q!
Force exit, do not save
12.
: Set number or: Set Nu
Make the file in the edit display line numbers
13.
: Set Nonumber or: Set Nonu
The line number is not displayed, as opposed to the previous command
14.
: Help I
View Insert Command Help
15.
U
Undo the previous action
16.
/fedora
Find Fedora Characters
17.
: S/fedora/redhat
Replace Fedora characters with Redhat (only the line on which the cursor is located)
18.
Dw
Delete Word
Dd
Delete Row
19.
O
Open a blank line
20.
Vim + filename
Edit the last line of a file
21st.
Vim +n filename
Enter file n row for Edit
22.
: 1,.s/redhat/fedora
The. Number represents the current line, which is the cursor
The 1th line to the current line (.) The first occurrence of redhat characters instead of Fedora
23.
: 1,.s/redhat/fedora/g
The 1th line to the current line (.) All occurrences of redhat characters are replaced by fedora,g
Global flag
24.
: 1, s/redhat/fedora/g s/redhat/fedora/g represents the last line
Replace all occurrences of redhat characters from line 1th to the last line as Fedora
25.
:%s/redhat/fedora/g
Same previous command
26.
:%s/\/fedora/g
Replace all occurrences of the Redhat word for Fedora with line 1th to the last line
words, not characters
27.
: F
Display file contents, status, etc.
Same Ctrl+g command
28.
: e!
Current file, returning to last saved
: E File
Toggle Edit File
29.
: N
When editing has multiple files (such as vim file1 file2) switch to the next file, and: E file
Combined use

                         Vim Command Encyclopedia

Cursor Control command
command cursor move
H move one character
J Move Down line
K move up one line
L move to the last line of the file
G move to the end of the document
W move to the beginning of the next word The beginning of the next word, ignore the punctuation mark
B moves to the beginning of the previous word
B moves to the beginning of the previous word, ignores the punctuation mark
L moves to the last line of the screen
moves to the middle line of the screen
H moves to the first line of the screen
E moves to the end of the next word
E moves to the end of the next word, ignore the punctuation mark
(move to the beginning of the sentence
) and move to the end of the sentence
{move to the beginning of paragraph
} move to the beginning of the next paragraph
0 (number), | Move to the first column of the current row
^ move to when The first non-null character
moves to the last character of the current line +, Enter move to the first character of the next line − move to the first non-null character in the previous line add a text command in VI Insert action A after the cursor insert text A at the current line Insert text I before the cursor insert text before the current line o in the

Related Article

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.