Enable Vim to display spaces and multi-line comments with the Tab character Vim

Source: Internet
Author: User

1. display the tab key

When the file contains the tab key, you cannot see it. To display it:

: Set list

Now the tab key is displayed as ^ I, and $ is displayed at the end of each line, so that you can find the spaces that may be ignored.
One disadvantage of this is that it looks ugly when there are many tabs. If you use a color terminal or GUI mode, VIM can highlight spaces and tabs.
Use the 'listchars' option:

: Set listchars = tab:>-, trail :-

Now, the tab is displayed as ">-", and the extra blank characters at the end of the line are displayed "-". It looks much better, right?

----------------------------

2. Enable Vim to display spaces at the end of the line.

Under fedora 9 System
Add the following two lines to the/etc/vimrc file:
Highlight whitespaceeol ctermbg = red guibg = red
Match whitespaceeol/\ s \ + $/

----------------------------

3. search and replace Vim

Search for the replacement range. If no range is specified, search for and replace the current row.

Search and replace all rows. Range symbol% Indicates replacement of search in all rows. : % S/from/to/is to find the from in the full text and replace it with.
Search and replace the specified row. : 1st S/from/to/indicates search and replacement between 50th rows and rows (including 1 and 50 rows. : 45 S/from/to/indicates that only 45th rows are searched and replaced. The range of "1, $" and "%" are equivalent.

----------------------------

4. Vim multi-line indent Technique

Keyword: Vim indent

Press V to enter the visual state, select multiple rows, and use> or <indent or collapse

Generally, auto indent layout is used based on language features: In the command status, the current row is used = (two connections by =), or N = (N is a natural number) indicates that N rows are automatically indented from the current row. You can try to unindent the code and use n = for typographical layout, which is equivalent to the code format in the general ide. You can use Gg = g to typeset the entire code.

Vim multi-line comment

: 20th S/^/#/g to 30 lines, comment out.

: 20, 30 s/^ # // G uncomment

: S/^ [^ I] \ + // remove the blank characters at the beginning of the line

Use. to indicate the current row.

:., 30 s/^/#/g

You can see that the vim command is for the current line, and you can add a range in front of it to target multiple lines.

: CO 12

Copy the current row to the location of row 12.

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.