Hey, Nuggets, I’m the silent King who’s been pretending to study since Monday.
I wanted to write Vim after Shell, because Vim is the best text editor in the history of mankind. Please take it with a grain of salt if you disagree.
Better, Stronger, Faster.
These three words are not too much to praise Vim. It’s just that Vim’s learning curve is pretty big, a fact even I have to admit. It is like playing a guitar. It is very painful to learn it at the beginning, and I almost want to break it. But after learning it, I can feel the infinite charm of the instrument and the small eyes of the young girls who worship it.
Go ahead, make up your mind to embrace it, there’s no better text editor, it’s incredibly hard to learn, but incredibly easy to use.
01. First acquaintance with Vim
Vim has a long history. In the late 1980s, Bram Miller developed version 1.0 of Vim based on an open source vi (an earlier computer text editor that I remember a reader going by that name).
In 1994, a landmark multi-window editing mode was added to Vim 3.0.
In 1996, a graphical interface was added to Vim 4.0.
Syntax highlighting was added to Vim 5.0 in 1998.
.
In short, stronger and stronger! The latest version, 8.0, displays a heart-warming message on the screen — “Help Poor Children in Uganda,” which translates to “Please Help the poor children of Uganda.” This reminds me of one of my favorite bands, a song by Beyond called Amani.
Open the terminal and type “vim” to enter the startup interface, as shown in the picture below.
Vim has a lot of clever design, so many other tools support Vim mode, such as Visual Studio Code. The amazing thing is that Vim has escaped the mouse and can manipulate text with the keyboard alone.
Type :help to check out the Vim help documentation, which is the most authoritative Vim learning material, even though it is in English. Take my advice and read it.
Type :q to exit the help document. Of course, if English is really painful to read, I have prepared an online Chinese translation document for you, check it out here:
Yianwillis. Making. IO/vimcdoc/doc…
02, practical operation Vim
As the saying goes, “All talk and no action.” Let’s get right into it. Type the vim XXX command. As shown in the figure below.
Then hit enter to enter the reading mode of XXX file. As shown in the figure below.
In reading mode, you need to try these commands.
- Up, down, left, and right: Corresponds to the up, down, and right keys
- Move by word: w (next word), B (first letter of word), E (last letter of word), not suitable for Chinese
- Move by line: 0 (first line), $(end of line),
: + rows
Jump directly to the specified line (where + means down:
Then enter the number of lines, such as 10. - Move by screen: H (top of screen), M (middle of screen), L (bottom of screen)
- Page flipping: Different keyboards, like the Mac’s chocolate keyboard,
Fn + write
The key flips up,Fn + left
Key scroll down (+ here means combination key) - Gg (move to start of file), G (move to end of file)
/ + keywords
(the + here means to press the backslash and then enter the keyword) for a search,n/N
Used for downward or upward matching
In addition, in reading mode, you can:
- type
i
Enter insert mode, which appears at the bottom of the window-- INSERT --
The words.
Press ESC in insert mode to return to read mode. A serious reminder: If you don’t know what mode you’re in, press ESC.
In addition to the I key to enter the insert mode, there are several other keys to enter the insert mode, such as the A key to insert after the cursor; The O key can be inserted after the current line; The 0 key can be inserted before the current row.
-
Type DD to delete the current row and save the deleted row to the clipboard.
-
Type x to remove a character where the current cursor is located.
-
Type P to paste the last copy.
-
Type YY to copy the contents of the current line.
-
Type u to undo the current action.
-
Type :w to save the current changes.
-
Type: q! You can exit Vim without saving the content.
-
Type :wq to exit Vim with the content saved.
** If you are in insert mode and want to exit or save content, be sure to press ESC to exit reading mode first.
Well, that’s it. You’re an entry-level Vim user. Really, with these commands, you can use Vim to do everything other editors can do.
03, advanced
After sun Wukong became the king of the water curtain cave in the Mountain of flowers and fruits, he felt unprecedented loneliness. He wanted to advance, so he took a boat to worship teachers and learn art. Again, when we master these commands, we are lonelier than ever, because Vim is more powerful than that.
Let’s see how Vim repeats himself.
-
Type. You can repeat the previous command. What does that mean? It means that if we type DD and delete a line, if we want to delete another line, we don’t have to press D twice, we just have to press once. Student: A key.
-
You can repeat a command N times by typing N+. (The + here means to press the number of times before entering the command). What does that mean? It means a big increase in productivity!
For example, in reading mode, typing 3DD deletes three lines at a time; Typing 10p pastes text 10 times.
Give me a good one.
Open a new text file with vim hello.txt. Then type 10+ I + Hello World + Enter + ESC (the + here means that after pressing the number of times, type I again to enter insert mode, type Hello World again, press Enter again to break the line, and press ESC again to exit reading mode) and something amazing happens. See the picture below.
Think about it. Type 10. What happens? Trust me, after you play it, you’ll be “wow.”
Wonderful, wonderful indeed. In addition, you can also type:
%
Match parentheses to move, including{[(
If you need to move the cursor over the parentheses.*
Matching words move to the next. (Chinese is not available)#
Match words to move up one. (ditto)
Remember the cursor movement to be free from the mouse. Most commands can be done as follows:
Start cursor position + command + end cursor positionCopy the code
For example, 0y$means:
- 0, cursor moves to the beginning of the line
- Y, copy from here
- $, until the end of the line
If you want to see which text is selected by the cursor, press v to enter the visual view and then move the cursor, as shown below.
More powerful operation, you can see uncle Mouse translated a “concise Vim training guide” :
Coolshell. Cn/articles / 54…
In reading mode, type :sp to split the window horizontally and type: VSP to split the window vertically, as shown in the following figure.
Comfortable? Original side edit, a preview, under Vim, only need to type three or four characters!
04, endnotes
If you want to keep a Copy of Vim’s help manual handy so you don’t have to search around while using Vim, to be honest, I’ve got it for you, just so sweet. Really, it took two days to compile a Vim Chinese User Manual with 310 pages and very comprehensive contents.
Vim Chinese user manual download (no need to decompress the password, no routine, pure sharing)
Finally, say more. As programmers, we spend most of our time fiddling with, no, no, no, code editors, so it’s well worth taking the time to master an editor that works for you. A lot of big guys use Vim directly as a code editor, and while I’m not quite there yet, I use Vim to manipulate logs and configuration files quite often.
To master Vim, you need to:
- Read the passage carefully;
- Stick with Vim for all text editing, even if it’s painful at first;
- Consult the help document at any time to strengthen muscle memory;
- After two weeks of hard training, you will find that the efficiency of work and study has been greatly improved.
- A month later, you ran to thank me, “brother, your ya, cow force”!
PS: Wow, the previous share of basic computer knowledge, let me addicted by Denver’s friends like ah, have 447 praised the (including my own one, hey hey, for shame!), is my share on the nuggets number is one of the highest praise in content, while 1000 praise is still very far away, but their heart was very happy, Riding my favorite scooter, going for a chill!
Ok, I am silent king two, hope this article can also help you! See you next time.