How to Use Vim Efficiently

  question, vim

The novice has just come into contact with Vim. I hope prawns will recommend some basic training courses. At present, Vim is just used as a normal editor. Also, pressing Esc to return to normal mode seems a little troublesome. Is there any simple way to reach the upper left corner of the keyboard? Thank you first!

After using vim for nearly two years, I have seen a lot of tutorials. Generally speaking, I still need to practice more. When I feel that I need it, I will add more functions. Here, I’d like to share the best tutorial I’ve ever seen. It was written by a friend of the post bar and is very good.

Zero

Learn to play blind

one

The configuration file starts from the simplest, do not consider configuring plug-ins before level 5, do not memorize commands, and do not directly access other people’s configuration files
Basically, if you stay in insert mode for a long time, you will feel that vim is neither good nor useful.

At this time, the editing efficiency may be lower than that of the original general editor. When people ask what editor to use,
Most of them will answer: vim with another nano nano, kate, kwrite, gedit, geany or other IDE

Two

Get into the habit of staying in normal mode(normal is not called in vain), only enter insert mode when entering, and < ESC > immediately after entering
Learn the move command under normal mode. Enter the text standard flow at this time:

  1. The normal mode move command accurately positions the cursor (remember, the search command is also a move command)
  2. Enter insert mode for editing (don’t just use I when entering insert mode; get used to using I a A o O s C depending on the situation)
  3. < ESC > returns to normal mode

At this time, the editing effect will return to the same as that of the normal editor you used before, even slightly improved.

Three

Learn what is operator and what is motion. Etc.),
Learn the method of operator+motion, such as ct. (delete the content between the current cursor and the point) and enter insert mode for modification)
Learn the basic Ex command: s or something

At this time, editing efficiency began to improve obviously, and when using other general editors, they would begin to feel unaccustomed and inefficient.

Four

Learning text-objects, knowing the method of operator+text-objects, can carry out precise positioning and modification like surgery.
Since you are mainly used in c/c++, give some useful examples in this case:

Ci “(composed of change operator and text-object i”)

This command will find the string enclosed by the next “in the line where the current cursor is located, clear the contents inside the quotation marks, and enter insert mode to facilitate modification.
It is easier to use than to explain. you can use const char* hello = “Hello world. “; Code like this to test

YaB (composed of yank operator and text-object aB)

This command copies the current cursor’s code block ({} enclosed contents, including curly braces themselves) to the default register.
It is convenient to paste it with p in other places (of course, writing code does not encourage copy and paste). you can test it with any {} and then find another place p

GUiw (composed of make uppercase operator and text-object iw)

This command capitalizes the word where the current cursor is located.
If max_size is changed to MAX_SIZE

At this time, I began to know why vim is accurate and efficient, and not because the whole keyboard does not need a mouse.

company

After getting used to operator+motion, I found that. commands are very useful. pay more attention to using repeatable command combinations.
Exercise Bookmark Positioning, Q Record Macros, Multiple register, args, buffer
Use other Ex commands

At this time, I can’t remember how the days before vim came to an end.

Land

Start with commands that map uses over and over again, start writing vimscript, and start to know what kind of plug-in you need.
Try to recommend a few:
Pathogen or vundle, tagbar, CtrlP, Gundo, UltiSnips, surround, Syntastic, Conque, ack.vim, vim-commentary, fugitive (if git user)
There are many more, but many of them are not directly helpful to c/c++, so they will not be mentioned.

At this time, I am not interested in other editors, except perhaps emacs.

Seven

Having a completely personalized vimrc, it has basically entered the cultural realm and become a legend in the Jianghu.
After watching your editor, people often arouse their ambition to learn vim, try for a few hours and give up because they think hot keys are too inhuman.
However, he occasionally mentions to others that he has seen a man like you in the Jianghu.