Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Vim text selection operation and logo function

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article Xiaobian for you to introduce in detail the "Vim text selection operation and logo function how to use", detailed content, clear steps, details handled properly, I hope this "Vim text selection operation and logo function how to use" article can help you solve doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge bar.

Text selection function of Vim

Let's assume that you already have the basics of the Vim editor (if not, you can read this article first). You should know that the d command can cut / delete a line. If you want to cut 3 lines, you can repeat the command 3 times. But what if you need to cut 15 lines? Is it a practical solution to repeat the d command 15 times?

Apparently not. The best way to do this is to select the line you want to cut / delete, and then run the d command. For example:

If I want to cut / delete the first paragraph of the INTRODUCTION section in the screenshot below:

So what I do is: place the cursor at the beginning of the first line (make sure you exit Insert mode) and press the V (that is, Shift+v) command. At this point, Vim turns on view mode and selects the first row.

Now, I can use the arrow key "Down" to select the entire paragraph.

That's what we want, right? Now you can cut / delete the selected paragraph simply by pressing d. Of course, you can do anything with the selected text except cut / delete.

This brings us to another important question: what do we do when we don't need to delete the entire row? That is, the solution we just discussed applies only to situations where you want to operate on the entire row. What if we just want to delete the first three sentences of the paragraph?

In fact, there are corresponding commands-just use lowercase v instead of uppercase V. In the following example, I use v to select the first three sentences of the paragraph:

Sometimes, the data you need to deal with consists of separate columns, and your requirement may be to select a specific column. Consider the following screenshot:

Suppose we only need to select the second column of the text, the name of the country. In this case, you can place the cursor over the first letter of the column and press Ctrl+v once. Then, press the arrow key "Down" to select the first letter of each country's name:

Then press the arrow key "right" to select this column.

Tip: if you selected a text block before, and now you want to reselect that text block, just press gv in command mode.

Use Fla

Sometimes, when you are working on a large file (such as a source code file or a shell script), you may want to switch to a specific location and then go back to the line you were just on. If the two lines are not far apart, or if you don't do this kind of operation often, then this is not a problem.

However, if you need to frequently switch between the current position and some distant lines, then the best way is to use flags. You just need to mark the current location, and then you can return to the current location from anywhere in the file by the flag name.

In Vim, we mark a line with the m command followed by a letter (the letter represents the flag name, which can be in lowercase a-z). For example, ma. Then you can use the command'a (including the single quotation marks on the left) to return to the line marked a.

Tip: you can use "single quotation marks" to jump to the first character of the flag line, or use "backquotation marks" to jump to a specific column of the flag line.

The logo function of Vim has many other uses. For example, you can mark a line, then move the cursor to another line, and run the following command:

D'[flag name]

To delete everything between the current location and the flag line.

In the Vim official documentation, there is an important content:

Each file has some flags defined by lowercase letters (amurz). In addition, there are some global flags defined by uppercase letters (Amurz) that define a location in a particular file. For example, you may be editing ten files at the same time, each of which can have a flag a, but only one file can have a flag A.

We have discussed the basic use of lowercase letters as Vim logos and their convenience. The following excerpt is clear enough:

Due to various limitations, the uppercase logo may not be as useful as the lowercase flag at first glance, but it can be used as a fast document bookmark. For example, open the .vimrc file, press mV, and then exit. The next time you want to edit the .vimrc file, press'V to open it.

Finally, we use the delmarks command to remove the flag. For example:

: delmarks a

This command removes a flag from the file. Of course, you can also delete the line where the flag is located, so that the flag will be deleted automatically.

Read here, this "Vim text selection operation and logo function how to use" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more about the article, welcome to follow the industry information channel.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report