一. 编辑文件
使用vim命令编辑文件:[root@Server ~]#vim Myprint.java
以下操作都在命令模式下完成
二. 显示文件的行号
命令模式 :set nu
三. 增加8行 System.out.println(“*”);
光标定位到这一行,输入yy,再按p键8次
四. 将Static 中的S变成小写;myprint更正成MyPrint;
查找Static:/Static
替换Static: :s/Static/static
查找myprint:/myprint
替换myprint::s/myprint/MyPrint
五. 删除第7行~13行的System.out.println(“=”);
光标定位到第7行:7G或者:7回车
删除7行:7dd
六. 在文件前两行行首增加注释符号#
#this is a program to print * on screen
#this is a java file
行首替换为# :1,2s/^/#
七. 取消行号显示
:set nonu
八. 光标定位在第6行,将println替换为print
6G
:s/println/print
九. 将文件中所有的“*”替换成“=”;
:%s/*/=
十. 保存文件并退出
:wq