Vim Advanced editing Tips

Source: Internet
Author: User

  1. Global substitution
    Format:
    ":%s/to replace character/replace with new character/g"
    :%s/old/new/g
    Specify line substitution
    Format: ": Starting line, terminating line s/to replace character/replace with new character/g"
    : 1,5 s/old/new/g
  2. Multi-file replacement
    For multiple file replacements, such as replacing All. c files with A_value as B_value, you can use the following methods:
    VI *.c
    : Argdo%s/a_value/b_value/ge | Update
    Where update is a direct replacement overwrite the original file, if you need to confirm, you can use
    : Argdo%s/a_value/b_value/gec | Update
  3. Multi-line Comments:
    First press ESC to enter command line mode, press Ctrl + V to enter the column (also known as block) mode;
    Use the upper and lower keys at the beginning of the line to select multiple lines to comment;
    Press the keyboard (uppercase) "I" key to enter the insertion mode;
    Then enter the comment symbol ("//", "#", etc.);
    Finally, press the "ESC" key.
    Note: After pressing the ESC key, will wait a moment to appear the comment , do not worry ~ ~ Time is very short
  4. To delete multiple lines of comment:
    First press ESC to enter command line mode, press Ctrl + V to enter the column mode;
    Select multiple lines to uncomment;
    Press "X" or "D".
    Note: If it is a "//" comment, it needs to be done twice, if it is a "#" comment, once
  5. Delete multiple characters at the beginning of a line
    First press ESC to enter command line mode, press Ctrl + V, enter the column mode, press "right arrow" to select the length of the character to delete;
    Press the DOWN arrow to select how many rows to delete
    Press "D" to delete
  6. Other
    Display line number: Set Nu
    To suppress line numbers: Set Nonu
    Back to end of sentence: Shift + $
    Back to the first sentence: Shift + ^
    Segment Header: {
    Kenu:}
    Previous modification: G,
    Post-amendment: g;
    Delete the remaining part of the word after the cursor: DW
    Delete the remaining part of the line after the cursor: d$
    Merge the next line to the end of the current line: J

Vim Advanced editing Tips

Related Article

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.