In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use the efficient editor VIM, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Although VIM has been used since a long time ago, it has always been half-tuned, tossing and turning only with orders that you can use. Here is a brief introduction to the operation of VIM, and does not say why to use VIM, if you want to know the answer can go to Google,VIM is known as the editor god.
This tutorial covers some basic techniques for using VIM in different working modes-insert mode (insert mode), command mode (command mode), access to files, and so on. The aim is to help novices who are new to VIM use this excellent editor more efficiently.
Description: in this article, it stands for Ctrl + Xmure-that is, hold down the Ctrl key and then press X. And you can use help command in many cases to get help with most commands, which is the internal help file command of VIM.
Efficient mobility
Outside the insert mode
Basically, you should stay in insert mode as little as possible, because VIM is like a "dumb" editor in insert mode. Many beginners stay in insert mode all the time because it is easy to use. But the power of VIM lies in its command-line mode! You will find that as you learn more about VIM, you will spend less and less time using insert mode.
Use h, j, k, l
The first step in efficient editing with VIM is to give up the use of arrow keys. With VIM, you don't have to move frequently between arrow keys and letter keys, which saves you a lot of time. When you are in command mode, you can use h, j, k, l to achieve the left, bottom, up and right arrow functions, respectively. You may need to get used to it at first, but once you get used to it, you'll find it efficient.
When you edit your email or other text with paragraphs, you may find that using arrow keys does not work as you expect, sometimes skipping many lines at a time. This is because your paragraph looks like a big, long line to VIM. At this point, you can type a g before pressing h, j, k, or l, so that VIM will move as you want on the top of the screen.
Effectively move the cursor within the current line
Many editors provide only simple commands to control the movement of the cursor (such as left, top, right, bottom, to the beginning / end of the line, etc.). VIM provides a lot of powerful commands to satisfy your desire to control the cursor. When the cursor moves from one point to another, the text between these two points (including the two points) is called "crossed", and the command here is also called motion. (to be brief, this important concept will be used later.)
Here are some commonly used commands (motion):
Fx: move the cursor to the next x of the current line. Obviously, x can be any letter, and you can use; to repeat your last f command.
Tx: similar to the command above, but move to the left position of x. (this is really useful.)
Fx: similar to fx, but looking back.
W: move the cursor forward one word.
B: move the cursor back one word.
0: move the cursor to the beginning of the current line.
^: move the cursor to the first letter of the current line.
$: move the cursor to the end of the line.
Move the cursor to the next sentence.
Move the cursor to the previous sentence.
Effectively move the cursor throughout the file
VIM has a lot of commands that can be used to get to where you want to go in the file. Here are some commands to move through the file:
Move down one screen. : move up one screen.
G: to the end of the file
NumG: moves the cursor to the specified line (num). (for example, 10G is to line 10)
Gg: to the beginning of the file
H: move the cursor to the top of the screen
M: move the cursor to the middle of the screen
L: move the cursor to the bottom of the screen
*: read the string at the cursor and move the cursor to where it appears again.
Similar to the one above, but looking in the opposite direction.
/ text: start searching for the string text at the current cursor and reach where the text appears. You must use enter to start this search command. If you want to repeat the last search, press n.
? Text: similar to the above, but in the opposite direction.
Ma: marks a bookmark with the name an at the current cursor position. Book signatures can only be in lowercase letters. You can't see the bookmark, but it's already there.
`a: go to bookmark a. Note that this is not a single quote, it is usually located to the left of the 1 of most keyboards.
`. Go to the place where you edited the file last time. This command is useful, and you don't have to mark it yourself.
Efficient input
Automatic completion using keywords
VIM has a very beautiful keyword completion system. This means that you can type part of a long word, then press a key, and VIM will complete the long word for you. For example: you have a variable named iAmALongAndAwkwardVarName somewhere in the code you write. Maybe you don't want to type it one letter at a time.
To use keyword completion, you only need to type the first few letters (such as iAmAL), and then press (hold down Ctrl, then press N) or. If VIM doesn't give you the word you want, keep pressing until you're satisfied, and VIM will loop through the matching string it finds.
Enter insert mode wisely
Many beginners enter insert mode only with I. This, of course, allows you to enter insert mode, but it is usually not appropriate, because VIM provides a lot of commands to enter insert mode. Here are some of the most commonly used:
I: insert to the left of the current character
I: insert at the beginning of the current line
A: insert to the right of the current character
A: insert at the end of the current line
O: insert a new line below the current line
O: insert a new line above the current line
C {motion}: deletes the characters crossed by the motion command and enters insert mode. For example: clocked, which removes the character from the cursor position to the end of the line and enters insert mode. Ct! Which removes from the cursor position to the next exclamation point (but not including), and then enters insert mode The deleted characters are stored in the clipboard and can be pasted out.
D {motion}: similar to the above, but does not enter insert mode.
Effectively move large pieces of text
Use visual selection (visual selections) and appropriate selection mode
Unlike the original VI,VIM, it allows you to highlight (select) some text and manipulate it. There are three visual selection modes:
V: select by character. A frequently used pattern, so try it for yourself.
V: select by row. This is especially useful when you want to copy or move many lines of text.
Select by block. It's very powerful, and it's only available in very few editors. You can select a rectangular block, and the text inside the rectangle will be highlighted.
Use the arrow keys and commands (motion) described above when selecting the mode. Vwww, for example, highlights the three words in front of the cursor. Vjj will highlight the current line and the next two lines.
Cut and copy in visual selection mode
Once you highlight your selection, you may want to do something:
D: clip the selected contents to the clipboard.
Y: copy the selected content to the clipboard.
C: clip the selected content to the clipboard and enter insert mode.
Cut and copy in non-visual selection mode
If you know exactly what you want to copy or cut, you don't need to enter visual selection mode at all. This will also save time:
D {motion}: cut the characters crossed by the motion command to the clipboard. For example, dw cuts a word and dfS cuts the characters from the current cursor to the next S to the clipboard.
Y {motion}: similar to the above, but a copy.
C {motion}: is similar to d {motion}, but finally enters insert mode.
Dd: cuts the current line.
Yy: copy the current line.
Cc: cuts the current line and enters insert mode.
D: cut from the cursor position to the end of the line to the clipboard.
Y: copy the current line.
C: similar to D, finally enter insert mode.
X: cut the current character to the clipboard.
S: similar to x, but finally in insert mode.
Paste
Paste is easy, press p.
Use multiple clipboard
Many editors provide only one clipboard. There are many VIM. The clipboard is called a Registers in VIM. You can list all currently defined register names and their contents with the command ": reg". It is best to use lowercase letters as the name of the register, because some uppercase ones are occupied by VIM.
The command to use registers is double quotation marks.
For example, we need to copy the current line to register k. You should press "kyy." you can also use V "ky. Why is this all right? ) the current line should now be stored in register k until you copy something into register k. Now you can use the command "kp" to paste the contents of register k to the location you want.
Avoid repetition
Amazing. Command
In VI, enter. (decimal symbol) will repeat the last command you entered. For example, if your last command was "dw" (delete a word), VI will then delete another word.
Use numbers
Using numbers is also one of the most powerful and time-saving features of VIM. Many VIM commands can be preceded by a number that tells VIM how many times the command needs to be executed. For example:
3J will move the cursor down three lines.
10dd will delete ten lines.
Y3 "will copy the contents from the current cursor to the third quotation mark that appears to the clipboard.
Numbers are a very effective way to extend the scope of motion commands.
Recording macro
Sometimes you will find yourself repeating the same series of actions in every paragraph or line of the article. VIM allows you to record a macro to fulfill your special needs.
Qregister: record macros to register register, where register is the name of any of your registers. Qa, for example, will record and store macros in register a.
Q: ends the recording of the macro.
Register: use macros with register register. For example, @ a will use macros stored in register a.
It is important to remember that macros only record your series of keystrokes and repeat them. They're not magic. Because there are many ways to accomplish your goals in VIM, sometimes you have to be careful about choosing commands to record your macros. Because they will be executed in all the places where you want to execute it.
Write code in VIM
VIM is an excellent editor for writing code because it has some features designed specifically for programmers. Here are some common ones:
] p: similar to p, but it automatically adjusts the indentation of the pasted text to fit the position of the current code. Try it!
%: match curly braces, square brackets, parentheses, etc. On top of a parenthesis, then press%, and the mouse will appear in the other half of the matching bracket.
Indent all selected codes
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.