Linux实验——vi高级操作

实验三:vi高级操作

 

实验步骤

  1. 登录系统。

a.使用实验一创建的用户名和密码登录系统。

b.打开Terminal。

 

  1. 创建文件并录入内容

a.在主目录中创建文件garden。

b.使用vi打开garden,并输入如下内容。

Everywhere the trend is toward a simpler, and easy to care garden. Few advises might help you to have less trouble with you gardening. I am sure you have heard them before, but listen once more. Gardening: The easy approach visit the plant nurseries, it is good for you soul. Let me tell you that there is no easy to care garden. Use plants that are suitable for your climate. Native plants are good CHOICE. Before planting, choose the right site. Use your imagination, plants grow faster than what you think. Gardening can be made easier and more enjoyable if you hire a gardener to do the job. Use mulches to reduce weeds and save time in watering the plants. Do not use too much chemicals to kill every weed insight. You are the only one who sees the weeds, let them grow. The keep the moisture and prevent soil erosion.

 

 

  1. 在vi中完成如下操作:

a.创建自己的姓名首字母缩写并将它加到文件头(单独一行)。

Esc

1G

O

XMSX(姓名缩写)

 

b.将光标移到第5行。

:55G

 

c.将光标移到文件头和文件尾。

:11G   移到文件头行头列

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

:$        移到文件尾行头列

$         移到尾行尾列

 

d.创建map键[F3],用它查找包含Gardening的行。

:map #3 /Gardening

(在命令模式下,输入F3,在底行自动显示/Gardening

 

e.创建缩写jlu,用于简化输入Jilin University。

:ab jlu Jilin University

(在文本模式下,输入jlu和空格,自动替换为Jilin University

 

f.在vi中shell执行命令,显示用户当前用户。

:!who am i

 

g.用date命令获取日期和时间并将它插入第一行的下面。

:1

:r !date

 

h.读取《实验二》中生成的文件vi_history_1,将它的内容放到当前文件末尾。

:$

:r vi_history_1

 

i.设置showmode选项,多次切换命令模式和文本插入模式,观察vi的变化。

:set showmode

vi末行有模式的提示)

 

j.设置行号选项,然后再取消行号选项,观察其效果。

:set number

:set nonumber

 

 

k.设置report选项为1。

set report=1

(为下一个操作设置)

 

l.一次删除1-5行,观察vi的反馈信息。然后撤销删除操作。

1G

5dd (底部会显示提示信息)

u

 

m.从文件头复制5行到文件尾,观察vi的反馈信息。

1G

5yy

:$

(底部会显示提示信息)

 

n.使用翻页键、[Ctrl-d]、[Ctrl-u]等键,观察结果。

[Ctrl-d]:向后翻页

[Ctrl-u]:向前翻页

 

o.将当前vi中的前5行,保存到文件garden5lines中。

:1,5 w garden5lines

 

p. 将当前vi中的后5行,追加到文件garden5lines中。

:6,10 w>> garden5lines

 

  1. 使用vi在当前主目录中创建文件filea,其内容如下:

*Unix help everyone, we like Unix*

*Linux help everyone, we like Linux*

*Linux help everyone, we like Linux*

*Linux help everyone, we like Linux*

*Linux help everyone, we like Linux*

*Linux help everyone, we like Linux*

 

a. 解释下面vi命令序列中每行命令的含义。

:5

2dd

:1

yy

2p

:1,$s/\*/#/g

:1,3s/#/\*

 

答案:

跳转到第5

删除2

跳转到第1

复制1

粘贴到2行和3

全文替换*#

1-3行第一个#替换为*

 

b. 在vi执行上面命令序列之后,验证其结果。

 

*Unix help everyone, we like Unix#

*Unix help everyone, we like Unix#

*Unix help everyone, we like Unix#

#Linux help everyone, we like Linux#

#Linux help everyone, we like Linux#

#Linux help everyone, we like Linux#

 

 

 

  1. 使用vi在当前主目录中创建文件fileb,其内容如下:

********************

*                  *

*Unix,Linux         *

*                  *

********************

 

请在命令模式下,将文件内容修改为如下结果:

####################

# Unix,Linux        #

# Unix,Linux        #

#                  #

####################

 

答案

1步:全文替换*#

:1,$s/\*/#/g

2步:删除2

:2

dd

3步:复制第2

yy

4不:粘贴

p

发布了58 篇原创文章 · 获赞 22 · 访问量 9854

猜你喜欢

转载自blog.csdn.net/zsd0819qwq/article/details/103868840
今日推荐