1.5 VIM Command mode

Source: Internet
Author: User

#显示行号

Set Nu


#取消行号

Set Nonu


#查找

Vi/etc/init.d/iptables

/iptables


#查找并替换

1,20s/iptables/iptables/g G is a global substitution and cannot be replaced globally without g

1, $s/iptables/iptables/g $ is a full file

%s/iptables/iptables/g% is a full file, replacing 1,$

%[email Protected]@[email protected]


Exercises:

1. The following actions and results are described correctly?

Direct input in normal mode: Set NU Displays line number

When the line number is displayed, you can enter: Set Nonu suppress line number display

When you finish editing a file, you need to press ESC and enter: Wq to save the exit document

If you accidentally enter the wrong command, you need to press ESC twice to cancel the command you just knocked and then go to normal mode.

2. What are the ways to search for keywords in vim?

General mode, direct input/word

General mode, direct input? word

General mode, direct input:/word


Summarize:

Main: Find and replace,%s#root#tim#g

Minor: Display line number, set Nu; Cancel line number, set Nonu

Practice the Truth

Extended Learning
1). Move 5 characters down, right, left, right, respectively
J L H 5l

2). Turn down and up two pages, respectively.

CTRL +b CTRL + F


3). Move the cursor to line 49th
49G

4). Move the cursor to the end of the line, and then move to the beginning
Shift+6
SHIFT + 4

5). Move to the last line of the 1.txt file
Dd
Gg
P

6). Move to the first line of the file
Gg

7). Search for the iptables that appear in the file and count how many are there.
/iptables

8). Replace the iptables that appear from the first row to the third row with the iptable
1,3s/iptables/iptable/g

9). Restore previous action
U

10). Replace all iptables in the entire file with iptable
%s/iptables/iptable/g

11). Move the cursor to 25 lines, delete the character "$"
V
X

12). Restore previous action
U

13). Delete Line 50th
50dd

14). Restore previous action
U

15). Delete all content from 37 rows to 42 rows
6dd

16). Restore previous action
U
17). Copy 48 lines and paste them below 52 lines
48yy
P

18). Restore previous action
U

19). Copy the contents from 37 rows to 42 rows and paste them above 44 lines
37pp
P

20). Restore the previous action (press two times u)
Uu

21). Move the contents of lines 37 to 42 below 19 lines
37dd
P

22). Restore previous action
U

23). Move the cursor to the first line and change the/bin/sh to/bin/bash
Shift+6
1s#/bin/sh#/bin/bash#

24). Insert a new line below the first line and enter "# hello!"
O
# hello!

25). Save the document and exit

Wq


1.5 VIM Command mode

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.