Emacs local variables and VIM modeline

Source: Internet
Author: User

 

Both Emacs and VIM can influence the current document by setting some variables in the file. In Emacs, it is called local variables or file variables. In vim, it is called modeline. The functions are the same, but there are some differences in writing.

1 Emacs

Emacs uses the following format in the first line:

 
-*-Var1: value1; var2: value2 ;... -*-that is, the variable and its value are included between two "-*-". You can write multiple groups of variables, which are separated by ";" before each group; each group of variables and values is separated by ":". The variable name is before the colon, and the value of the variable is written after the colon. In this sectionCodeYou can add any character before, that is, you can add the corresponding comment before and after, so that it does not affect the actual text.

For example, if you want to enable a file to automatically enter C ++-mode when it is opened, and set tab-width to 4, you can write it in the file header:

 
//-*-Mode: C ++; tab-width: 4 ;-*-If you enter the python mode and set coding to GBK, it is:

#-*-Mode: Python; coding: GBK ;-*-

In some languages with special use in the first line, emacs can also put local variables at the end of the file. The method is to start with a line containing "local variables:" and end with "end:" in the last few lines of the file, and put a variable in each row in the middle.

For example, if a file is in the C mode and requires the tab-width to be 8, write at the end of the file:

/* Local variables: */<br/>/* mode: C */<br/>/* Table-width: 8 */<br/>/* end: */<br/>

2 Vim

Vim modeline can be written in two ways:

(1) The first format:

[Text] {White} {vi: | VIM: | ex:} [White] {options}

    • [Text] any text, or blank.
    • {White} must contain at least one space or tab.
    • {Vi: | VIM: | ex:} is one of the three strings, "VI:", "VIM:" or "EX :".
    • [White] spaces that can or cannot be left blank.
    • {Options} is a list of set options separated by the colon.

For example:

 
// VIM: Ft = CPP: tabstop = 8(2) The second format:

[Text] {White} {vi: | VIM: | ex:} [White] set {options}: [text]

    • [Text] any text or blank.
    • {White} must contain at least one space or tab.
    • {Vi: | VIM: | ex:} is one of the three strings, "VI:", "VIM:" or "EX :".
    • [White] spaces that can or cannot be left blank.
    • Set string "set" (note that the space after set is indispensable ).
    • {Options} Option List, separated by spaces.
    • : A colon.
    • [Text] any text, or blank.

For example:

 
/* VIM: Set Ft = C tabstop = 2 :*/Differences between the two formats:

For the first format, the rest of the line will be used once it is identified.

 
/* VIM: Ft = C: tabstop = 8 */The following */error occurs.

The second format does not have this problem, because it will end explicitly with a colon.

  /* VIM: Set Ft = C tabstop = 2: */  to make modeline take effect in Vim, you must enable the modeline option by running set modeline or adding it to vimrc. 
In addition, you can set Vim to read the first few rows as modeline by setting set modelines = 8 to 8 rows. The default value is 5 rows.
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.