Linux Initial VI Editor

Source: Internet
Author: User

Q: What is the VI editor?
A:VI Editor is the most basic Linux and Unix text editor, in character mode, graphical desktop work, powerful, while editing a non-existent text file is created by default, vi editor is every Linux beginner's introductory course and required.

What is the difference between Q:vi editor and Vim?
A:vim is a vi-enhanced version, capable of displaying characters in different colors, especially useful when editing a configuration file.

Now let's briefly introduce the VI editor.

Three modes of the VI Editor:

1.命令模式,用户进入vi编辑器后的模式,接收用户输入的不同命令执行不同操作2.编辑模式,用户编辑文本3.末行模式,文本编辑结束后执行保存等操作重点:三种模式之间的转换命令模式-->键入a/i/o-->编辑模式-->键入Esc-->命令模式-->键入:(英文)-->末行模式-->键入Esc-->命令模式

Operations in command mode

1. Cursor movement

上下左右

2. Page turn

上一页:PgUp/Ctrl + b下一页:PgDn/Ctrl + f

3. Quick jump in line

跳转至行首:Home / “^” /”0”跳转至行末:End / “$”

4. Quick Jump between rows

1G / gg:回到行首G:转至最后一行nG:跳转到文件中的第n行

5, line number display

:set nu               #显示行号:set nonu        #取消行号显示

6. Delete

X或del :删除光标所在的单个字符dd :删除光标所在行ndd :删除从光标开始的n行d^ :删除从光标开始到行首的所有内容(不包括光标所在字符)d$ :删除从光标开始到行末的所有内容(不包括光标所在字符)

7. Copy

yy :复制整行内容nyy :复制从光标开始的n行

8. Paste

P(大写) :粘贴内容到光标之前p(小写) :粘贴内容到光标之后

9. Content Search

/word :从上到下查找字符(串)word?word :从下到上查找字符(串)wordn :下一个N :上一个

10. Undo Edit

u :按一次取消最近一次的操作,多次重复按u键,回复已经进行多次的操作U :用于取消当前行所有的编辑ZZ :保存当前文件内容并退出vi编辑器

Operations in the last-line mode

1. Save and exit

     保存文件:               :w                     #保存修改的内容               :w /a.txt            #另存为     退出:               :q                        #未修改退出               :q!                    #放弃对文件的修改,并退出

2. Save and exit

     :wq            #保存并退出

3. Open a new file or read into other file contents

     :e 文件       #读入该文件内容     :r 文件        #在当前文件中光标所在行后读入其他文件的内容

4, the replacement of the contents of the file

     1、:s  /old/new                #在当前行中用new替换第一个old     2、:s  /old/new/g              #替换当前行中所有的old为new     3、:n1,n2  s/old/new/g       #在行号n1到n2中,替换所有的old为new     4、:%s  /old/new/g           #在整个文件范围内替换old为new     5、:s  /old/new/c               #每个替换动作都会提醒用户确认

Linux Initial VI Editor

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.