Eclipse sets soft tab (replaced by four spaces) and default UTF-8 file encoding (UNIX)

Source: Internet
Author: User

 

Eclipse sets soft tab (replaced by four spaces) and default UTF-8 file encoding (UNIX)

 

Summary:


1. How to configure the eclipse editor to support softtab (replace the default tab indentation with several space characters );


2. How to configure the editor in eclipse to support Utf-8 file encoding in UNIX mode by default;


----------------------------------------- The details are as follows ----------------------------------------------------


Recently, you need to use eclipse to write something,


Consider how to run the code on the Linux server to be uploaded,


In addition, you may use VI or Vim in Linux to directly open the source file for editing,


So before the start, we made the following compatibility configuration for these two purposes for Eclipse:


Note:


The following settings are in the menu "window-> Preferences", which is the English version of eclipse. The Chinese version can correspond to the corresponding menu options.


First, set the tab key indentation that is frequently used during text editing,


It is replaced by four spaces,


To ensure that the indent format is still correct when opened with VI or vim.


The procedure is as follows:


1. Open option: General
-> Editors-> text editors


Find displayed tab width on the right:


Select Insert spaces for tabs,


Click OK and save. Create an HTML file, enter several tab keys, and press the left and right arrow keys to move the cursor,


It is found that the original tab has been replaced with four space characters.

However, if you want to set the same effect for the Java file,

Perform the following step 2 Settings:


2. Configure softtab for java files


Open the menu on the left: Java-> code style-> formatter,


Then, click the edit button in active profile,


In the displayed window, select "spaces only" as the tab policy in general settings,

Select the Edit... button on the right. In the general settings page, select space only in the drop-down box on the right of the tab policy!

Then, set the indentation size and Tab size to the number of spaces you want! Generally, there are 4 spaces !!


Modify the profile name and save it.

Second, configure the editor in eclipse to support UTF-8 format file encoding in UNIX mode by default


Choose General> workspace,


Select: text file encoding as UTF-8,


New
Text File line Delimiter is UNIX,


Click OK to save.

Conclusion:


Through the above two settings,


It can also effectively solve the problem of using different development tools on the front end and back end of a project to generate files edited by front-end personnel,


Enable Chinese garbled characters in eclipse used by backend engineers,


The most fundamental reason may be that the UTF-8 file pattern is different,


In UNIX, The UTF-8 Format File Header does not contain the BOM identifier,


The UTF-8 file header in window mode contains the BOM identifier.


After softtab is set, different editors can be used for front-end and back-end users,


Open the same file and you will see different results.


After the compatibility settings, there is no restriction on the editor tools used by developers,


In most cases, front-end developers are not familiar with eclipse and do not need to use it,


This can also ensure that they can all use tools they are familiar with, so as to avoid excessive unnecessary external factors affecting development efficiency.

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.