If you see a lot of VIM command classifications at first, you will definitely lose interest in this editor. So let's look at a fun game first! Game web side: https://vim-adventures.com/
Whether it's a headache for a lot of vim's hotkeys, you can now use this little game to get familiar with vim hotkeys. In the game you will need to use various vim keys.
In this way, you learned vim in the game!
There are pictures and the truth
The following article was translated from "Learn Vim Progressively". Although it is an old article, I think this is an upgrade tutorial for the best VIM for beginners. It does not list all the commands, but lists the most useful commands. It is very good. .
Do you want to learn the best text editor VIM in human history as quickly as possible? You first have to know how to survive in VIM and then learn little tricks.
Vim the Six Billion Dollar editor
Better, Stronger, Faster.
Learn vim and it will be your last text editor to use. There is no better text editor than this, it is very difficult to learn, but it is incredibly easy to use.
I suggest the following four steps:
Survival
feel good
Feel better, stronger, faster
Using VIM's Super Power
When you finish this article, you will become a vim superstar.
Before I start learning, I need to give you some warnings:
Learning vim is painful at the beginning.
needs time
You need to practice constantly, just like you learn a musical instrument.
Do not expect that you can practice vim more efficiently than other editors within 3 days.
In fact, you need 2 weeks of hard work instead of 3 days.
Level 1 - Survival
1, install vim
2, start vim
3, don't do anything! Please read:
After you have installed an editor, you will definitely want to enter something in it and see what the editor looks like. But vim is not like this, please follow the following command:
After starting Vim, vim is in Normal mode.
Let's enter Insert mode, press key i.
(Chen Hao Note: You will see a -insert– character in the lower left corner of vim, indicating that you can enter it as an insert)
At this point, you can enter text as if you were using "notepad."
If you want to return to Normal mode, press ESC.
Now you know how to switch between Insert and Normal modes. Here are some commands that will allow you to survive in Normal mode:
i → Insert mode, press ESC to return to Normal mode.
x → Delete the character where the current cursor is.
:wq → save + exit (:w save, :q exit) (Chen Yu Note: :w can be followed by the file name)
Dd → Delete the current line and save the deleted line to the clipboard
p → Paste clipboard
recommend:
Hjkl (strong case is recommended for moving cursor but not required) →You can also use cursor keys (â†â†“↑→). Note: j is like down arrow.
:help
You can survive in vim and only need the above five commands, you can edit the text, and you must practice these commands into a subconscious state. So you can begin to advance to the second level.
When it is, when you enter the second level, you need to talk about the Normal mode again. Under normal editors, when you need to copy a piece of text, you need to use the Ctrl key, for example: Ctrl-C. In other words, the Ctrl key is like a function key. When you press the function key Ctrl, C is not C, and it is a command or a fast key. In VIM's Normal mode, all The key is the function key. This you need to know.
mark:
In the following text, if it is Ctrl-λ I will write
With : start command you need to enter
Level 2 - Feel good
The above commands only allow you to survive. Now it's time to learn some more commands. Here are my suggestions: (Chen Hao Note: All commands need to be used in Normal mode if you don't know now What kind of mode, you just press ESC several times.)
1, a variety of insertion mode
a → insert after the cursor
o → insert a new line after the current line
O → insert a new line before the current line
Cw → replace characters from the cursor position to the end of a word
2, a simple move cursor
0 → number zero, to the beginning of the line
^ → to the first position of the line that is not a blank character (blank characters are spaces, tabs, newlines, carriage returns, etc.)
$ → To the end of the line
G_ → to the last position in the line that is not a blank character.
/pattern → Search pattern string (Chen Hao Note: If you search for multiple matches, press n to move to the next one)
3, copy / paste (Chen Hao Note: p / P can be, p is that after the current position, P said before the current position)
P → Paste
Yy → copy current line when ddP
4, Undo/Redo
u → undo
5, open / save / exit / change the file (Buffer)
:e
:w → Save
:saveas
:x, ZZ or :wq → Save and exit (:x means saving only when needed, ZZ does not need to enter a colon and enter)
:q! → Exit without saving: qa! Forcibly quit all files being edited even if other files have changed.
:bn and :bp → You can open many files at the same time, use these two commands to switch the next or previous file. (Chen Hao Note: I like to use: n to the next file)
Take a moment to familiarize yourself with the above commands. Once you have mastered them, you can do almost anything that other editors can do. But until now, you still think that using vim is still a bit clumsy, but it doesn't matter. You can progress to the third level.
Level 3 - Better, Stronger, Faster
Congratulations! You are doing very well. We can start something more interesting. At the third level, we only talk about those commands that are compatible with vi.
better
Below, let's see how vim repeats itself:
. (Decimal point) The previous command can be repeated
N
Here is an example. To find a file you can try the following command:
2dd → ​​Delete 2 lines
3p → Paste text 3 times
100idesu [ESC] → will write "desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu desu "
→ Repeat the previous command - 100 "desu".
3. → Repeat 3 times "desu" (Note: Not 300, you see, VIM is smarter).
Stronger
You have to make your cursor move more efficiently. You must understand the following commands. Do not skip it.
1, NG → to the Nth line (Chen Hao Note: Note that the G command is capitalized, and I generally use: N to the Nth line, such as: 137 to 137 lines)
2, gg → to the first line. (Chen Hao Note: equivalent to 1G, or: 1)
3, G → to the last line.
4, according to the word move:
w → to the beginning of the next word.
e → to the end of the next word.
> If you think the word is by default, use lowercase e and w. By default, a word consists of letters, numbers, and underscores (Chen Hao Note: Program Variables)
> If you think the word is a blank character separator, then you need to use uppercase E and W. (Chen Hao Note: program statement)
Below, let me say the strongest cursor movement:
% : Match the parentheses to move, including (, {, [. (Chen's Note: You need to move the cursor first to parentheses)
* and #: match the word that the cursor is currently in, move the cursor to the next (or previous) match word (* is next, # is previous)
Trust me, the above three commands are quite powerful for programmers.
Faster
You must remember the movement of the cursor, because many commands can be linked with these commands to move the cursor. Many commands can be done as follows:
For example, the 0y$ command means:
0 → first come first
y → Start copying from here
$ → copy to the last character of the line
You can enter ye to copy from the current position to the last character of this word;
You can also type y2/foo to copy two strings between "foo".
There is still a lot of time and you don't have to press y to copy. The following command will also be copied:
d (remove)
v (visualization choice)
gU (enlarged)
Gu (lowercase)
and many more
(Chen Hao Note: Visualization is a very interesting command, you can press v first, then move the cursor, you will see the text is selected, then, you may d, can also be y, can also be capitalized, etc.)
Level 4 - Vim Super Power
You only need to master the previous commands and you can use VIM very comfortably. However, now we introduce you to the VIM killer feature. The following are the reasons why I only use vim.
Moving a cursor on the current line: 0 ^ $ f F t T,;
0 → to the head
^ → The first non-blank character to this line
$ → to the end of the line
G_ → to the last position in the line that is not a blank character.
Fa → To the next character with a, you can also fs to the next s character.
t, → The first character before the comma. Comma can be changed to other characters.
3fa → Find the third occurrence of a on the current line.
F and T → and f and t are just the opposite direction.
Another useful command is dt" → delete everything until double quotation marks are encountered."
Area selection
In visual mode, these commands are very powerful and their command format is:
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 space-separated word, s a sentence, p a paragraph. It can also be a special character: ",",),},].
Suppose you have a string (map (+) ("foo")). The cursor keys are in the first o position.
Vi" → will choose foo.
Va" → will choose "foo".
Vi) → will select "foo".
Va) → will choose ("foo").
V2i) → will select map (+) ("foo")
V2a) → will select (map (+) ("foo"))
Block operation:
Block operation, typical operation: 0
^ → To the head
I-- [ESC] → I is inserted, insert "--", press the ESC key to take effect for each line.
In Windows vim, you need to use
Automatic prompt:
In Insert mode, you can enter the beginning of a word and press
Macro recording: qa operation sequence q, @a, @@
Qa Record your operation in register a.
So @a will replay the recorded macro.
@@ is a shortcut key to replay the newly recorded macro.
Example
In a text that is only one line and this line is only "1", type the following command:
qaYp
Qa start recording
Yp copy line.
q Stop recording.
@a → Write 1 under 1
@@ → Write 3 in front of 2
Doing 100@@ now will create a new 100 rows and increase the data to 103.
Visual choice: v, V,
In front, we saw
J → connect all the lines (make one line)
< or > → Indent left and right
= → Automatic indentation (Chen Hao Note: This feature is quite powerful, I like it too much)
Add something after all the selected lines:
Select the relevant row (you can use j or
$ to the end of the line
A, Enter the string and press ESC.
Split screen: :split and vsplit.
Here are the main commands, you can use VIM help :help split. You can refer to a previous article on this site VIM split screen.
:split → Create split screen (:vsplit creates vertical split screen)
Conclusion
Above is the author's most commonly used 90% command.
I suggest you learn 1 to 2 new commands every day.
After two to three weeks, you will feel vim's powerful.
Sometimes learning VIM is like dying something.
Fortunately, vim has a lot of good tools and excellent documentation.
Run vimtutor until you are familiar with the basic commands.
In the online help documentation you should read carefully :help usr_02.txt.
You will learn many other features such as directories, registers, plugins and more.
Learning vim is like learning to play the piano. Once you learn it, you benefit from it. For vi/vim just a point of comment: This is an editor you do not need to use the mouse, do not need to use a small keyboard, just use the large keyboard to complete a lot of complex text editing. Otherwise, Visual Studio will not have vim plugins anymore.
via: Cool shell - CoolShell.cn Author: Chen Hao
- END -
Hey, do you want to make your keyboard a piano?
We put together a lot of Vim keyboard HD images,
Various styles, there is always one for you!
You can print in color or black and white.
Posted on the wall, you can also cut and paste it on your keyboard.
DIY it so you can get new skills faster.
ZTTEK Batteries, For 5G backup base station .Customize the lithium ion battery packs according to the application and product requirements of the customers.
Lithium ion battery integration requires a special set of skill and expertise to optimize the performance and battery life.ZTTEK Batteries , using the most advanced technology delivers the best quality battery packs.
Our batteries are safe to use, better performance, higher shelf life and a very low maintenance cost.
48V200Ah Lithium Ion Battery,Lifepo4 Battery 48V 200Ah,Rechargeable Battery 48V 200Ah,48V 200Ah Lifepo4 Battery Pack
Jiangsu Zhitai New Energy Technology Co.,Ltd , https://www.zt-tek.com