Vim replaces "Turn"

Source: Internet
Author: User

:[range]s/from/to/[flags]

    • range: The search scope, if no range is specified, acts on but forward.

      1. :1,10s/from/to/Indicates a search substitution between lines 1th through 10th (containing 1th, 10th lines);
      2. :10s/from/to/Indicates that the search is replaced only on the 10th line;
      3. :%s/from/to/Represents a search substitution in all rows;
      4. 1,$s/from/to/Ditto.
    • flagsThe following four options are available:

      1. cConfirm, ask before each replacement;
      2. eError, do not display errors;
      3. gGloble, do not ask, the whole line is replaced. If no option is added g , only the first matching string of each row is replaced;
      4. iIgnore, ignoring case.

      These options can be used in combination, such as representing case insensitive cgi , full line substitution, and asking before replacing.

Regular expressions
  1. Metacharacters

    • Metacharacters

      Meta character Description
      . Match any character
      [ABC] Matches any one of the characters in the square brackets, which can be used to - represent a range of characters. such as [a-z0-9] matches lowercase letters and numbers
      [^ABC] Match any character except the character in square brackets
      \d Matching Arabic numerals, equivalent to [0-9]
      \d Matches any character other than the Arabic numeral, equivalent to [^0-9]
      \x Match hexadecimal digits, equivalent to [0-9a-fa-f]
      \x Matches any character other than a hexadecimal number, equivalent to [^0-9a-fa-f]
      \l Match [A-z]
      \l Match [^a-z]
      \u Match [A-z]
      \u Match [^a-z]
      \w Match word letter, equivalent to [0-9a-za-z_]
      \w Matches any character other than the word letter, equivalent to [^0-9a-za-z_]
      \ t Match <TAB> character
      \s Match white space character, equivalent to [\ t]
      \s Match non-whitespace characters, equivalent to [^\t]

    • Some ordinary characters need to be transferred

      \* match *   character
      .   character
      \/ match   /   character
      \ match   \   character
      \[ match   [   characters
      \] match   ]   character

       

    • Represents the number of metacharacters

      * match 0-any one
      \+ match 1-any of
      \?
      \{n,m} match n-m
      \{n} match n
      \{n,} matches N-any
      \{,m} match 0-m

       

    • Meta-character representing position

      Meta character Description
      $ Match end of Line
      ^ Match beginning
      \< Match the first words of the word
      \> Match word endings

  2. Substitution variables

    Regular expressions in and around regular \( expressions \) , which can be used in the subsequent use \1 , \2 such as variables to access \( and \) in the content.

Example
    1. Delete line trailing spaces::%s/\s+$//g
    2. Remove extra spaces at the beginning of the line: %s/^\s*// or%s/^ *//
    3. Delete empty lines that are not in the content: %s/^$// org/^$/d
    4. Delete empty lines that consist of spaces: %s/^\s*$// org/^\s*$/d
    5. Delete blank lines beginning with space or tab to the end: %s/^[ |\t]*$// org/^[ |\t]*$/d
    6. Replace all strings in the text "abc......xyz" with "XYZ......ABC" to have the following wording

      :%s/abc\(.*\)xyz/xyz\1abc/g:%s/\(abc\)\(.*\)\(xyz\)/\3\2\1/g

SED: Specify file to replace

Sed-i "s/from/to/g" file name

Vim replaces "Turn"

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.