Vi/vim Find Replacement Use method

Source: Internet
Author: User

vi/vim Find and replace using method VI/You can use the: s command to replace a string in vim.     The command has a number of different details of how to use the method, you can implement complex functions, record several here, convenient later query. : s/vivian/sky/Replace the current line the first Vivian is Sky:s/vivian/sky/G replaces the current line with all Vivian as sky:n, $s/vivian/sky/replaces the first Vivian of each row in the beginning of the nth row to the last row is sky:n, $s/vivian/sky/g Replace the nth line start to the last row in each row all Vivian is a number of sky N, if N is., the beginning of the current line to the last row:%s/vivian/sky/(equivalent to: G/VIVIAN/S//sky/) Replace the first Vivian of each line with Sky:%s/vivian/sky/g (equivalent to: G/VIVIAN/S//sky/g) Replace all Vivian in each row as Skyyou can use # as the delimiter, which appears in the middle of the/does not act as a delimiter: S#vivian/#sky/# Replace the current line the first vivian/is sky/:%s+/oradata/apras/+/user01/apras1+ (use + to replace/):/oradata/apras/Replace with/user01/apras1/1.: s/vivian/sky/Replace the current line the first Vivian is Sky:s/vivian/sky/g Replace current line all Vivian for Sky2. : N, $s/vivian/sky/replaces the first Vivian of each row in the beginning of the nth row to the last row is sky:n, $s/vivian/sky/g Replace the nth line start to the last row all Vivian are Sky (n is a number, if N is., which is the beginning of the current line to the last row)3. :%s/vivian/sky/(equivalent to: G/VIVIAN/S//sky/) Replace the first Vivian of each line with Sky:%s/vivian/sky/g (equivalent to: G/VIVIAN/S//sky/g) Replace all Vivian in each row as Sky      4. You can use # as a delimiter, which appears in the middle of thedoes not act as a delimiter: S#vivian/#sky/# Replace the current line the first vivian/is sky/5. Delete the ^ in the textM Problem Description: For line breaks, the window is replaced with a carriage return (0a0d) to indicate that Linux is a carriage return (0A) to represent. So, when you copy a file on a window to UNIX, there's always a^m. Please write a shell or C program that uses a newline character (0D) to filter Windows files under UNIX. Using the command: Cat filename1| tr-d "^v^m" >NewFile;. Use command: sed-E "s/^v^m//"filename > OutputFileName. It is important to note that in 1, 22 methods, ^v and ^m refer to Ctrl + V and ctrl+m. You have to do the input manually, not paste. . Process in VI: First use VI to open the file, then press ESC, then enter the command:%s/^v^m//. . :%s/^m$//gif the above method is useless, the correct workaround is: [Page]. TR-D \"\\r\ "< src >dest. TR-D \"\\015\ "Dest. Strings A>B6Replacement Confirmation There are many times when a character (string) is required to be replaced in some position in the article, while other locations are not replaced by the selected action, which requires the user to confirm, and the same support for the VI's lookup substitution for example: s/vivian/sky/g Replace the current line all Vivian for Sky after the command with a letter C can be implemented, namely: s/vivian/sky/GC as implies meaning, C is the abbreviation of Confirm7Other uses: The S command enables the substitution of strings. Specific usage includes:: s/str1/str2/replaces the first occurrence of a string in a row with a string str2 str1:s/str1/str2/G replaces all occurrences of string str1 in a line with a string str2:. , $ s/str1/str2/G replaces all occurrences of string str1 with the string str2 the current line to the end of the body:1, $ s/str1/str2/G replaces all occurrences of strings in the body with a string str2 str1:g/str1/s//str2/g function Ibid .you can see from the Replace command above that the G is placed at the end of the command to replace each occurrence of the search string, without g, which means that only the search

Vi/vim Find Replacement Use method

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.