Sprout new note-vim command "=", "d", and "y" usage (combined with the cursor movement command, it will be very convenient in some cases), vim is very convenient

Source: Internet
Author: User

Sprout new note-vim command "=", "d", and "y" usage (combined with the cursor movement command, it will be very convenient in some cases), vim is very convenient

Vim has many commands. on the Internet, you can search for a bunch of posts and articles to list commands for various functions.

For "=", "d", and "y", I accidentally discovered some of the same usage. Here are three examples:

= NGdnGynG

N indicates the row number. Note that the row number is followed by the uppercase letter "G ". "NG" is the command to move the cursor to line n.

For "=", "= nG" means formatting from the current row to the nth row. A common command "gg = G" is to execute "gg" to jump the cursor to the first line, and then execute "= G ". If no row number is written, it is the last line. Therefore, "gg = G" Can format all the contents of the current file. The length of the formatted tab is set in. vimrc.

Similarly, dnG is used to cut the current row to the nth row, and ynG is used to copy the current row to the nth row.

In addition, n can be smaller than the current number of rows. For example, if the current row is 70 rows, execute "y35G" to copy the content from 70 rows to 35th rows, in fact, it is equivalent to copying 35 to 70 rows.

With this, it is very convenient in the following scenarios:

Suppose you want to copy the content from 25 rows to 78 rows, then you can directly use "25Gy78G" instead of calculating the total number of rows, and then execute ndd.

For "d" and "y", you can also do this:

"D ^", "d $", cut from the cursor position to the beginning/End of the line, "dw", cut the cursor's current position to the first letter of the word, and so on.

In short, it is to combine "=", "d", and "y" with the operation of moving the cursor to produce the desired effect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.