vi for beginner

1.open terminal

2.type "vi" <enter>
if you want to exit, type ":q!"

3.type "cd /etc", which means go to the directory of the etc
type "cd", it will return to root directory.
type "vi /etc/fstab", which means you edit the file.
type "vi xx.txt", if the xx.txt is not exit, then the file is new.

4.when you type "vi", you are in the Command Mode.
if you want to translate to the Inserting Mode, you can type "i".
now, you can input some content, if you want to exit without save, translate to Command Mode, then type ":q!"
if you want to save and exit, you must type ":wq"
if you want to save as other file name, you can type ":w filename"

5. open a file including many lines, type "vi /var/log/syslog"
if you want to find some charactors, type "/charactors". then you can find the first position where the charactors are.
If you want to go on find the charactors, type "n", then you will find the next one.
If you type "N", you will find the previous charactors.
by the way, if you type "?charactors", you will find them.
Then you can use "n" to find the previous one, use "N" to find the next position.

6. cancel
In the Insert Mode, you can type some letters.
In the Command Mode, you can type "u" to cancel.
In order to translat to Insert Mode, you can type "i", else you can tyep "o", but using the latter method means you type extra enter.

7.cut, copy and paste a line
In the Command Mode, you can type "dd". It means you cut the letters of the line.
you can type "p", which means you paste under the current line.
you can type "P", which means you paste above the current line.
you can type "yy", whicn means you cope the letters of the current line.

8.read other file content in the current file
In the Command Mode, type ":r filename", which means you can display the filenmame's context under the current line.

9.cope the letter selected
On the Command Mode, type "v" to translate to Visual Mode, then select the letters and type "p", which means cope,
then type "y", the content will display on the after of the current letter.

10. type "G" to arrive the end, and type "gg" to arrive the begin of the file.

1、打开 terminal
2、输入 "vi", 如果你想结束,那么输入":q!"
3、输入 "cd /etc",那么就进入etc的目录下了
输入"vi /etc/fstab",表示你要编辑这个文件
输入"vi xx.txt",如果这个文件不存在,那么就会创建这个文件

4、输入"vi",此时你是在命令模式的
如果你想切换插入模式,那么输入"i"
在这个模式下,你能输入一些内容,如果你想不保存就结束,那么你可以输入":q!"
如果你想要保存并退出,那么你可以输入":wq"
如果你想另存为,那么输入":w filename", filename要另存为的文件名

5、打开一个有多行内容的文件,比如输入"vi /var/log/syslog"
如果你想要找一些内容,输入"/charactor",(charactor是要找的内容),你就可以找到。
如果你想要继续找,输入"n",你会找到下一个内容
输入"N",你会向上找到这个内容
除此之外,你可以输入"?charactors",你可以找到这个内容
然后,你输入"N",你会找到下一个内容
输入"n",你会向上找到这个内容

6、撤销
在插入模式,你可以输入一些内容,然后切换到命令模式,输入"u"就可以撤销
为了切换到插入模式,你可以输入"i",当然你也可以输入"o",只不过后者多输入一个回车而已

7、剪切,复制和拷贝某一行
在命令模式,你可以输入"dd",这意味着你剪切了某一行
输入"p",粘贴到该行下面
输入"P",粘贴到该行上面
输入"yy",复制该行

8、读取其他文件的内容到当前文件
在命令模式下,输入":r filename",你可以把另一个文件的内容读取,并显示在该行下面

9、拷贝
在命令模式,输入"v",你可以切换到可视模式,然后用光标选中内容,输入"p",这样就复制了
然后,输入"y",他和行就显示在当前字母的后面了

10、输入"G",你可以到文件末尾,输入"gg",你可以到文件的最开头

原文地址:https://www.cnblogs.com/chuanlong/p/2809297.html