"Go" vim multi-line indent and advanced commands

Source: Internet
Author: User

Learn other people's posts, the content into their own is to grow, here mark

Vim multi-line indentation Tips

1. Press V to enter visual state, select multiple lines, indent or indent with > or <

2. Automatic indentation is usually used according to the language characteristics: Use = = (Double press = two) for the current line in the command state, or n== (n is the natural number) for multiple lines to automatically indent the following n rows from the current line. You can try to indent the code arbitrarily and then use the n== layout, which is equivalent to the normal IDE's code format. Use Gg=g to compose the entire code. 3.gg shift+g 4. Full text word replacement%s/source/dist/g or: 1,$ s/source/dist/g: s/vivian/sky/Replace the current line the first Vivian for Sky

: S/vivian/sky/g replaces the current line all Vivian are sky

: N, $s/vivian/sky/replaces the first Vivian of each row in the nth row to the last row is sky

: N, $s/vivian/sky/g replace the nth line to the last row all Vivian are sky

N is a number, if N is., indicating the beginning of the current line to the last row

:%s/vivian/sky/(equivalent to: g/vivian/s//sky/) replaces the first Vivian of each line as Sky

:%s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all Vivian in each row as Sky

You can use # as a delimiter, at which time the middle/not as a delimiter

: s#vivian/#sky/# Replace the current row 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 replaces the current line all Vivian are sky

2.: N, $s/vivian/sky/the first Vivian of each row in the beginning of line N to the last row is sky

: N, $s/vivian/sky/g replace the nth line to the last row all Vivian are sky

(n is a number, if N is., representing the beginning of the current line to the last row)

3.:%s/vivian/sky/(equivalent to: g/vivian/s//sky/) replaces the first Vivian of each line as Sky

:%s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all Vivian in each row as Sky

4. You can use # as a delimiter, at which time the middle appears/does not act as a delimiter

: s#vivian/#sky/# Replace the current row the first vivian/is sky/

5. Delete the ^m in the text

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. This way, when you copy a file on a window to UNIX, there is always a ^m. Write a shell or C program that uses a newline character (0D) that filters 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 it.

· In VI Processing: First use VI to open the file, and then press the ESC key, followed by the command:%s/^v^m//.

· :%s/^m$//g

If the above method is useless, the correct solution is:

· Tr-d "\ r" < src >dest

· Tr-d "\015" dest

· Strings A>b

6. Other

Use the: s command to implement a string substitution. Specific uses include:

: s/str1/str2/replaces the first occurrence of a string in a line with a string str2 str1

: S/str1/str2/g replaces all occurrences of strings in a line with a string str2 str1

:., $ s/str1/str2/g Replace all occurrences of the current line to the end of the string with the string str2 str1

: 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

Replace the first occurrence of the string, and G at the beginning of the command to replace all rows in the body that contain the search string.

Original address: http://blog.csdn.net/topasstem8/article/details/6678215

"Go" vim multi-line indent and advanced commands

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.