Familiar with vim Editor

Source: Internet
Author: User
Tags ruby on rails

I used to work as an intern in a company on Ruby on Rails. Aptana is used as the IDE, and its speed is sometimes very slow. Then we can see that some old employees in the company use Vim as the compiler. Looking at how they use Vim to make their own IDE, they were very interested in vim! So I decided to use the vim compiler from today on. I decided to use my blog as my learning diary.

First, I got a gvim72 online. Installed. Some Basic settings:

    • Shiftwidth (number of indented spaces );
    • Tabstop (Tab width );
    • Expandtab (whether to use spaces to replace indentation and Tab keys; Use noexpandtab to cancel settings );
    • Softtabstop (soft tab width. If it is set to a non-zero value, the number of cells moved by the tab key and backspace time mark is equal to this value, but the actually inserted characters are still controlled by tabstop and expandtab );
    • Autoindent (Auto indent, that is, the indent value of each line is equal to that of the previous line; Use noautoindent to cancel the setting );
    • Cindent (using C language indentation, the indentation is automatically adjusted based on special characters such as "{", "}", ":", and whether the statement ends; it is automatically set when editing C/C ++ and other types of files; Use nocindent to cancel the settings );
    • Cinoptions (for details about how to indent C language, see ": Help cinoptions-values ");
    • PasteCode-- Keep the original code style; Use nopaste to cancel the settings ).

Below are some common combinations:

    • Shiftwidth = 4 tabstop = 4: many windowsProgramYou will get used to this setting so that the indentation is equal to the tab width.
    • Shiftwidth = 4 tabstop = 8: Many Unix programmers still use the commonly used four-cell indent, but the tab width is the Standard 8.
    • Cinoptions => 4, N-2, {2, ^-2,: 2, = 2, G0, H2, P5, T0, + 2, (0, U0, W1, m1 shiftwidth = 2 tabstop = 8: Standard GNU encoding style settings, which make many minor adjustments to Vim's default C indent style, for example, "{" and "}" in the IF statement must be indented after "if", but the "{" and "}" in the function definition are still aligned with the function name. Open-source software often uses this indent style.

Vim supports Automatic completion of words. For example, if you use a long variable name named alongvariable, you do not need to complete the input. Most likely, you just need to type "Al" and press "Ctrl-P" (search for matching words and complete them) you can get the complete variable name (if you do not get the expected result, press Ctrl-P for a few times, or enter a few more characters, such as "alongv "). Similar Commands include "Ctrl-n" (backward searching for matching words and completing) and "Ctrl-x Ctrl-l" (searching for matching rows and completing), "Ctrl-x Ctrl-F" (search for matching file names and complete), etc. For details, see ": Help ins-completion ".

Command Used for the first exercise:

Sy: syntax highlight: sy on enable syntax highlight: Sy clear cancel syntax highlight.

Set Go =: go is the abbreviation of GUI option. Set Go =: no menu.

Colo: Set the color. You can select the desired color method, such as Colo evening.

Tabnew: open a new text. For example, tabnew C:/text.txt.

: X can encrypt the file. For the first time, I think a feature is very useful. You can also use: set key = for decryption. At the same time, it is found that if the file is encrypted by yourself, you can enter the file by entering a password at will when the hacker looks at it, but it will be garbled! If you modify the file content, that is, you can use the correct password to access the file! From this perspective, X encryption is not so powerful.

Matching and replacement:

For example, % S/content to be replaced/new content to be replaced/GC % indicates full text s indicates replacement GC indicates all replacement, for example: % S/Yes/&/R/GC this command replaces "yes" with "yes.

In command mode, you can use Gg to jump to the file and start to remove 2x to delete two characters dd to delete a row.

You can use the Q command to record the macro and Use Q to launch the recording macro and use @ to use the recording macro.

Vim also supports powerful plug-ins.

The first time I used vim, I thought it was really powerful.

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.