Vim Command Detailed

Source: Internet
Author: User
Tags exit in

Vi:visual Interface Visual Interface
VIM:VI improved VI enhanced version

Full screen editor, modal editor

Vim mode:

Edit mode (Command mode)
Input mode
Last-line mode
Mode conversion:

Edit--Input:

i: 在当前光标所在字符的前面,转为输入模式;a: 在当前光标所在字符的后面,转为输入模式;o: 在当前光标所在行的下方,新建一行,并转为输入模式;I:在当前光标所在行的行首,转换为输入模式A:在当前光标所在行的行尾,转换为输入模式O:在当前光标所在行的上方,新建一行,并转为输入模式;

Input-to-edit:

ESC

Edit-to-last line:

:

Last line--edit:

ESC, ESC

Note: There is no direct switch between the input mode and the last line mode
First, open the file

vim +# :打开文件,并定位于第#行vim +:打开文件,定位至最后一行vim +/PATTERN : 打开文件,定位至第一次被PATTERN匹配到的行的行首

Note: default is in edit mode
Second, close the file

1, the last line mode closed file

:q  退出:wq 保存并退出:q! 不保存并退出:w 保存:w! 强行保存:wq --> :x

2. Exit in edit mode

ZZ: Save and exit
Third, move the cursor (edit mode)

1, character-by-word movement:

h: 左l: 右j: 下k: 上#h: 移动#个字符

2. Move in Word units

w: 移至下一个单词的词首e: 跳至当前或下一个单词的词尾b: 跳至当前或前一个单词的词首#w: 移动#个单词

3, in-line jump:

0: 绝对行首^: 行首的第一个非空白字符$: 绝对行尾

4. Jump between rows

#G:跳转至第#行gg: 第一行G:最后一行

5, the last line mode

.: 表示当前行$: 最后一行#:第#行+#: 向下的#行

Four, turn the screen

Ctrl+f: 向下翻一屏Ctrl+b: 向上翻一屏Ctrl+d: 向下翻半屏Ctrl+u: 向上翻半屏

V. Delete a single character

x: 删除光标所在处的单个字符#x: 删除光标所在处及向后的共#个字符

Vi. Delete command: D

The D command is used in combination with the jump command

#dw, #de, #db

DD: Deletes the current cursor in the row
#dd: Delete the line containing the line of the current cursor;

Seven, Paste command p

p: 如果删除或复制为整行内容,则粘贴至光标所在行的下方,如果复制或删除的内容为非整行,则粘贴至光标所在字符的后面P: 如果删除或复制为整行内容,则粘贴至光标所在行的上方,如果复制或删除的内容为非整行,则粘贴至光标所在字符的前面

Eight, copy command y

Here is the basic command for VIM copy and paste:

yy复制游标所在行整行。或大写一个Y。 2yy或y2y复制两行。 ㄟ ,请举一反三好不好! :-) y^复制至行首,或y0。不含游标所在处字元。 y$复制至行尾。含游标所在处字元。 yw复制一个word。 y2w复制两个字(单词)。 yG复制至档尾。 y1G复制至档首。 p小写p代表贴至游标后(下)。 P大写P代表贴至游标前(上)。

Copy a single character

首选进入正常模式(按ESC就行)然后按v(指定粘贴板为"1v 引号不能少),进入visual方式,然后就可以移动方向键选中文本,然后按y,就拷贝完成,如果你要从光标处开始复制 4 个字符,可以按 4yl (复制光标后的)("14yl)("110yl 后面10个字符),4yh(复制光标前的) ,就复制了4个字符到缓冲区中了,按下来就可以用 p (指定粘贴板为"1v 引号不能少)命令随便粘贴了(1为指下粘贴板名)          

Nine, modify: First delete the content, and then converted into the input mode

c: 用法同d命令

Ten, replace:

r:单字符替换#r: 光标后#个字符全部替换R: 替换模式

Xi. undo Edit Operation U

u:撤消前一次的编辑操作#u: 直接撤消最近#次编辑操作连续u命令可撤消此前的n次编辑操作撤消最近一次撤消操作:Ctrl+r

12. Repeat the previous edit operation

.:编辑模式重复前一次编辑操作

13. Visualization Mode

v: 按字符选取V:按矩形选取

14. Find

/PATTERN?PATTERNn 下一个N 上一个

XV, find and replace

Use the S command in the last-line mode

headline,footlines#PATTERN#string#g1,$:表示全文%:表示全文

16. Use Vim to edit multiple files

vim FILE1 FILE2 FILE3:next 切换至下一个文件:prev 切换至前一个文件:last 切换至最后一个文件:first 切换至第一个文件:q退出当前文件:qa 全部退出

17, split screen display a file

Ctrl+w, s: 水平拆分窗口Ctrl+w, v: 垂直拆分窗口

Toggle the cursor between windows:

Ctrl+w, ARROW(h,j,k,l或方向键) :qa 关闭所有窗口

18. Edit multiple files in a window

vim -o : 水平分割显示vim -O : 垂直分割显示

19. Save some of the contents of the current file as a different file

Use the W command in the last row mode

:ADDR1,ADDR2w /path/to/somewhere

20. Populate the contents of another file in the current file

:r /path/to/somefile附加到当前文件光标后

21. Interacting with the shell

:! COMMAND

22. Advanced Topics

1. Display or suppress line numbers

:set nu:set nonumu = number

2. Display ignores or distinguishes character case

:set ic:set noicic = ignorecase

3. Set Auto Indent

:set ai:set noaiai = autoindent

4. Check the found text highlighting or canceling

:set hlsearch:set nohlsearch

5. Syntax highlighting

:syntax on:syntax off

Note: The feature is currently valid, if you want to modify the configuration file permanently
23. Configuration Files

/etc/vimrc    针对所有用户~/.vimrc    针对当前用户

This article was reproduced from: http://www.cnblogs.com/usergaojie/p/4583796.html

Vim Command Detailed

Related Article

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.