VI editor (Vim)

  Vi , it is a from the University of California, Berkeley , Bill Joy  research and development of a text editor.


  There are many text editors, such as graphics mode gedit , kwrite , OpenOffice , the editor in text mode has vi , vim ( vi enhanced version). vi and vim are we in Linux is the most commonly used editor. vi or vim is Linux the most basic text editor, vi or vim Although there is no graphical editor as a simple mouse operation, but the vi editor in systems management, server management character interface, never GUI editor can Than.

 (Note: vi is the unix / linux operating system is the most classic text editor, can only be edited characters, not the font, paragraph typesetting ; It can create a new file, you can also edit the file; he is no menu, only the command, and the command range. While vi mode of operation with the other conventional text editor (e.g., the gedit ) are very different, but because of its operation in the interface characters, available for all unix / linux environment, often still being used.)


VI commonly used commands:

QQ picture 20190814084616.png

  

    

vi  three command mode

1.Command (command) mode for entering commands

2.Insert (insert) mode for text insertion

3.Visual (visual) mode for visualization and highlighting of the selected text

( Note: Different versions give vi three different operating modes. Vi has three operating modes: command mode, text editing mode and the last line mode method of operation under different operating modes are different.

1. Command mode:

命令模式是启动vi后进入的工作模式,并可转换为文本编辑模式和最后行模式。在命令模式下,从键盘上输入的任何字符都被当作编辑命令来解释,而不会在屏幕上显示。如果输入的字符是合法的vi命令,则vi就会完成相应的动作;否则vi会响铃警告。

2.文本编辑模式:

文本编辑模式用于字符编辑。在命令模式下输入i(插入命令)、a(附加命令)等命令后进入文本编辑模式,此时输入的任何字符都被vi当作文件内容显示在屏幕上。按Esc键可从文本编辑模式返回到命令模式。

3.末行模式:

在命令模式下,按“:”键进入最后行模式,此时vi会在屏幕的底部显示“:”符号年作为最后行模式的提示符,等待用户输入相关命令。命令执行完毕后,vi自动回到命令模式。

为了实现跨平台操作兼容不同类型的键盘,在vi编辑器中无论是输入命令还是输入内容都是用字母键。例如按字母键“i”在文本编辑模式下表示输入字母“i”,如果在命令模式下则表示将工作模式转换为文本编辑模式。)


不同模式的切换

image.png

a:在光标位置之后输入

i:在光标位置之前输入

o:在光标位置下一行插入

O:在光标位置上一行插入



当我们按ESC进入Command命令模式后,我们可以用下面的一些键位来移动光标

1.方向移动:

  j 向下移动一行

  k 向上移动一行

  h 向左移动一个字符

  l 向右移动一个字符

     向上箭头 向上移动

  向下箭头 向下移动

  向左箭头 向左移动

  向右箭头 向右移动

2.翻页:

 ctrl+b 或page up 向上移动一屏

 ctrl+f 或page down 向下移动一屏

3.行间快速跳转

 1G 或 gg 跳转至文件的首行

 G  跳转至文件的末行

 #G 跳转至文件的第#行

4.行内快速跳转

 Home键或者“^”.数字“0”  跳转至行首

 End键或者“$”  跳转至行尾

5.行号显示

 :set nu 在编辑器中显示行号

 :set nonu 取消编辑器中的行号显示

image.png




文本内容的删除操作;

x或Del 删除光标处一个字符

#x 删除几个字符#表示数字,比如3x

dw 删除一个单词

#dw 删除几个单词,#用数字表示,比如3dw表示删除三个单词

dd 删除一行;

#dd 删除多个行,#代表数字,比如3dd 表示删除光标行及光标的下两行

d$ 删除光标到行尾的所有字符

d^ 删除光标到行首的所有字符


复制操作

yy命令复制当前整行的内容到vi缓冲区

yw复制当前光标所在位置到单词尾字符的内容到vi缓存区,相当于复制一个单词

y$复制光标所在位置到行尾内容到缓存区

y^复制光标所在位置到行首内容到缓存区

#yy例如:5yy就是复制5

#yw例如:2yw就是复制两个单词

If you want to copy the first m -th row to n between the contents of the line, the bottom line can be input mode m , NY example: . 3 , 5Y copy the contents of the third to fifth rows buffer.


Adhesive

After 1.p Copy and paste the contents of the cursor

2.P Copy and paste the contents of the cursor before

image.png

Supplementary: ddp: position the cursor where the line and the next line exchange


Find the file contents

/ Word: from the top down search string "word" in the file

? word: from the bottom up search string "word" in the file

Locating a next matching n search string

N positioned on a search string match

image.png


Undo edit and save and exit

U : Cancel the last operation, can be used multiple times to restore the original operation [1]  

U: cancel all operations

ZZ: save the current file and exit Vi editor



Replace the contents of the file

image.png

image.png

image.png














Guess you like

Origin blog.51cto.com/14469918/2429365