Vim Training Class

Source: Internet
Author: User

Since entering this company, every now and then by the next big God shocked, first time by his proficiency in the terminal command line, and then he was in the vim to modify the code when the quick search, replace shock.

Every time to ask him for help, the first sentence is: "Give me the terminal!" ”。 Oh, my god--"Give me the terminal!" ”

So I decided to take a good look at the command line on Linux, and Vim. To be honest, I have been using the terminal for some time, and I have been learning vim for some time.

Feel, the terminal is really very powerful, when I look for files on the hard disk, it is very convenient, and vim in the configuration of my software to modify the more comfortable, but general text class configuration file, Vim kill.

Here are the VIM commands that I extracted when I finished reading this article. For more detailed articles, please read:

The concise Vim Practice Level Introduction

In the above article, the author mentioned that the introduction of vim, a total of 4 parts, the feeling is very good, I followed this practice for a week, has been feeling refreshed:

First Level:
?   i → Insert 模式,按 ESC 回到 Normal 模式.?   x → 删当前光标所在的一个字符。?   :wq → 存盘 + 退出 (:w 存盘, :q 退出)   (陈皓注::w 后可以跟文件名)?   dd → 删除当前行,并把删除的行存到剪贴板里?   p → 粘贴剪贴板

Recommended:
? HJKL (strong example recommends using it to move the cursor, but not necessary) → You can also use the cursor key (←↓↑→). Note: J is like the down arrow.
? : help→ displays Help for related commands. You can also enter: Help instead of the command. (Chenhao Note: Exit help requires input: Q)

Second Level:
1   各种插入模式?   a → 在光标后插入?   o → 在当前行后插入一个新行?   O → 在当前行前插入一个新行?   cw → 替换从光标所在位置后到一个单词结尾的字符   2   简单的移动光标?   0 → 数字零,到行头?   ^ → 到本行第一个不是blank字符的位置(所谓blank字符就是空格,tab,换行,回车等)?   $ → 到本行行尾?   g_ → 到本行最后一个不是blank字符的位置。?   /pattern → 搜索 pattern 的字符串(陈皓注:如果搜索出多个匹配,可按n键到下一个)  3   拷贝/粘贴 (陈皓注:p/P都可以,p是表示在当前位置之后,P表示在当前位置之前)?   P → 粘贴?   yy → 拷贝当前行当行于 ddP   4   Undo/Redo?   u → undo?   <C-r> → redo    5   打开/保存/退出/改变文件(Buffer)?   :e <path/to/file> → 打开一个文件?   :w → 存盘?   :saveas <path/to/file> → 另存为 <path/to/file>?   :x, ZZ 或 :wq → 保存并退出 (:x 表示仅在需要时保存,ZZ不需要输入冒号并回车)?   :q! → 退出不保存 :qa! 强行退出所有的正在编辑的文件,就算别的文件有更改。?   :bn 和 :bp → 你可以同时打开很多文件,使用这两个命令来切换下一个或上一个文件。(陈皓注:我喜欢使用:n到下一个文件)
Third Level:
. (小数点)  ——>可以重复上一次的命令N<Command> ——>重复上一次命令N次。NG ——> 100G ,跳转到100行gg ——> 到第一行G ——> 到最后一行 按照单词移动:    1、w——>到下一个单词的开头    2、e——>到下一个单词的结尾    如果单词是默认方式(单词、数字、下划线——程序变量),用小写的 w 和 e    如果单词是由blank字符分隔符,用大写的W 和 E% : 匹配括号移动,包括 (, {, [. (需要把光标先移到括号上)* 和 #:  匹配光标当前所在的单词,移动光标到下一个(或上一个)匹配单词(*是下一个,#是上一个)0y$:0 → 先到行头y → 从这里开始拷贝$ → 拷贝到本行最后一个字符ye:从当前位置拷贝到本单词的最后一个字符 y2/foo :拷贝2个 “foo” 之间的字符串d (删除 )v (可视化的选择)gU (变大写)gu (变小写)    可视化选择是一个很有意思的命令,你可以先按v,然后移动光标,你就会看到文本被选择,然后,你可能d,也可y,也可以变大写等
level Fourth:

Move the cursor over the current line: 0 ^ $ f f t T,;

0 → 到行头^ → 到本行的第一个非blank字符$ → 到行尾g_ → 到本行最后一个不是blank字符的位置。fa → 到下一个为a的字符处,你也可以fs到下一个为s的字符。t, → 到逗号前的第一个字符。逗号可以变成其它字符。3fa → 在当前行查找第三个出现的a。F 和 T → 和 f 和 t 一样,只不过是相反方向。dt" → 删除所有的内容,直到遇到双引号—— "

Region selection A or I

The action can be any command, such as D (delete), Y (copy), V (selectable depending on the mode).
The object may be: W A word, w a word separated by a space, s a sentence, p a paragraph. can also be a special character: ", ',"),},].
Suppose you have a string (map (+) ("foo")). The cursor key is positioned at the first O.
VI "→ Will choose foo; va" → "foo" will be selected.
VI) → will select "foo", VA) → Will Select ("foo").
V2i) → will choose map (+) ("foo"), v2a) → Will Select (Map (+) ("foo"))

Block Operation:

Block operation, typical operation: 0 I–[esc]
^→ to Wardrobe
→ Start block operation
→ Move down (you can also use HJKL to move the cursor, or use%, or something else)
I–[esc]→i is inserted, insert "-", press ESC to take effect for each line.

Automatic hints: and

In Insert mode, you can enter the beginning of a word, and then press or the auto-fill function will appear ...

Macro recording: QA operation sequence Q, @a, @@

QA Records your operation in register a.
So @a will replay the macro that was recorded.
@@ 是 A shortcut key used to replay the latest recorded macro.
Example: In a text that has only one row and this line has only "1", type the following command:
Qaypq→qa start recording, Yp copy line, increase 1;q stop recording, @a→ write Down Under 1 2;@@→ on 2 front write 3
Now do [email protected]@ will create a new 100 rows and increase the data to 103.

Visual selection: V,v,

Earlier, we saw an example. Once you've been chosen, you can do the following:
j→ to connect all the rows (into one line)
< or >→ indent around
=→ Auto-indent (Chenhao Note: This feature is quite powerful, I love it too)
Add something after all the selected lines:
: Select the relevant line (can use J or/pattern or% ...)
$ To line last
A, enter a string and press ESC.

Split screen:: Split and Vsplit.

Here are the main commands that you can use to help with Vim: helping split. You can refer to the previous article of the site Vim split screen.
: split→ Create split screen (: Vsplit Create vertical split screen)

dir is the direction, can be a hjkl or ←↓↑→, which is used to switch the split screen.
_ (or |) : Maximized Size (| vertical split screen)
+ (or-): Increase size

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Vim Training Class

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.