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 ModelUsed for editing and moving in the window, and also for quick editing
  • View ModelOperations for selecting chunks of content (copy, cut, delete, replace)
  • Insert ModelFor 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)

  • 0outfit$At the end of the line, after many operations0$Same thing goes to the head and the end of the line
  • j kUp and downh lThe 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 bMove 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 content
  • dw: Cut a word

Replace operation (Normal Model & View Model)

  • inNormal ModelNext, according to therThen press the letter again to replace the selected letter with the entered letter.
  • pPaste 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 useyMake a copy. Then use the View Model to select the part that needs to be replaced"0pLet’s make a substitution. One of the0Is 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 changing0I can paste different ones

Tip::reg allows you to view the contents of all relevant registers

  • The other way is in theNormal ModelPress 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+VTo 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;ddCut the line where the cursor is located
  • yyCopies the current line of the cursor
  • dj/D writeCut the cursor and the previous line,dk/D leftCut the cursor position and the next line.

Some tips

Operation related

  • Move up and down faster while holding Shift
  • JYou can indent the following line to the current cursor line
  • ~You can change the case of the selected part of the cursor
  • uIs to undo what I just did,Ctrl+rIs 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(
  • zzMoves 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.