Vim doesn’t ask for help
preface
Dear monkeys, you are all familiar with Vim. Vim looks very cool to use, usually we do not recite Vim shortcut keys, however, we know that the use of learning back too little, soon from the entry to give up. We still look at Devops in awe as he expertly clicks on Vim. However, I recently found a way to learn how to play 666 on Vim without too much effort. Below, I will share my learning methods and practical tips with you. Vim does not ask for help from the beginning to the beginning.
Idea + Vim > 2
In our daily work, WE use Idea to write codes. If we can use Vim to write code in the familiar Idea, we must be very quick to get started. This is also a deliberate practice mentioned in the program Ape Paddling Guide in the last article – we put ourselves out of our comfort zone and into the learning zone by installing the Vim plug-in in Idea. Next, let’s start with the simplest plug-in installation and share with you how to use Vim and my experience.
Installing a plug-in
Preferences->Plugins->Marketplace-> Enter Vim in the search box
~/.ideavimrc
IdeaVim
IdeaVimExtension
Idea
IdeaVim
IdeaVimExtension
Three patterns
As we all know, Vim has three models:
Normal Model
Used for editing and moving in the window, and also for quick editingView Model
Operations for selecting chunks of content (copy, cut, delete, replace)Insert Model
For inserting content
When we use Vim coding, we can get twice the result with half the effort by choosing the right mode. Now, let’s see how we move the cursor after entering Vim.
Fast moving (Normal Model & View Model)
0
outfit$
At the end of the line, after many operations0
和$
Same thing goes to the head and the end of the linej
k
Up and downh
l
The left and right can do the same as the arrows. Once we’re good at it, we’ll be able to hit the 66 keysHHKBUp side to side, up and down.w
b
Move over the next or previous word
(
)
Method (blank line) beginning and method end{
}
Moves up and down between methods (blank lines)
Have you noticed that suddenly writing code is much faster?
Clipping operation (Normal Model & View Model)
Under Normal Model we have a lot of handy clip-and-delete operations that don’t need to go into Insert Model. Also, cut and delete in Vim is one use, depending on whether you have pasted in the content. By taking full advantage of the various shortcuts in Vim, we can achieve the purpose of fast editing content.
x
: Clipping the cursor selection, Normal Model clipping a letter, View Model clipping all the selected contentdw
: Cut a word
Replace operation (Normal Model & View Model)
- in
Normal Model
Next, according to ther
Then press the letter again to replace the selected letter with the entered letter. p
Paste the content that you just cut out. If you select part of the content under the View Model, that is actuallyreplaceThe selected content is selected.
But what if we have to replace multiple places? There’s no rush. There are two ways. Let’s try them one at a time.
- Under the View Model, select the part that you want to paste and use
y
Make a copy. Then use the View Model to select the part that needs to be replaced"0p
Let’s make a substitution. One of the0
Is the number zero, which is the number of the contents in the Vim register, which is the same as the stack structure. We do it by changing0
I can paste different ones
Tip::reg allows you to view the contents of all relevant registers
- The other way is in the
Normal Model
Press the:
Enter command mode, and then replace it by typing the following command on the command line that appears
:s/from/to- Replace the first in the current line with fromto. :s/from/to/g - Replace all of the current line with fromto. :a,bs/from/to/g - Replace files with fromaRow tobDo all of theto.Copy the code
Since Idea’s Vim plugin does not support replacement well, it is recommended to use it directly on the selected contentCtrl+C
Ctrl+V
To operate.
Edit operations (Normal Model & Insert Model)
i
: Insert before the cursor;I
: inserts before the first non-null character on the current line;gI
: inserts in the first column of the current row;a
: Insert after the cursor;A
: inserts at the end of the current line;o
: Create a new line below to insert;O
: Insert a new line above;
Row operations (Normal Model)
D
: clipping from cursor to end of line;dd
Cut the line where the cursor is locatedyy
Copies the current line of the cursordj
/D write
Cut the cursor and the previous line,dk
/D left
Cut the cursor position and the next line.
Some tips
Operation related
- Move up and down faster while holding Shift
J
You can indent the following line to the current cursor line~
You can change the case of the selected part of the cursoru
Is to undo what I just did,Ctrl+r
Is to redo the action that was just undone.r+<Enter>
Move the content after the cursor to the new line below- Modify the content between ()
ci(
, cut the content between ()di(
Copy the contents between ()yi(
zz
Moves the current row to the center of the screen.
Configuration related
- Vim also has some map instructions that you can put together and write to a config file. You will also have your own unique Vim (more on that later)
nnoremap <space>i<space><esc>
nnoremap <enter>i<end><enter><esc>
Copy the code
This is my map configuration so that I can use space and enter to manipulate content Spaces and newlines in Normal Model
other
- Install Vim plug-ins on all ides and editors you use
- Keep handy shortcuts in a small notepad, and if you forget to open them right away, you’ll remember them a few times
- Use Vim Vundle to manage your Vim plugin, you will find Vim more and more fun.
As long as you persist, you will win
It only takes a few days, a few businesses, and suddenly Vim isn’t that hard to use after all. On the other hand, after mastering Vim, no matter Idea or VScode, no matter Mac or Linux; For you they’re all one IDE, seamless, seamless. Still have, suggest everybody collect this web page, use to operate query. Everyone found other better operation routines, be sure to share with me, it is better to be happy alone than happy together. Finally, I share my shortcut notepad with you.