Tag Archives: Ctrl+Shift+F

Eclipse’s shortcut Ctrl + Shift + F doesn’t work

format code (shortcut key for eclipse format code block: Ctrl + Shift + F)

1. Format java code:

①Ctrl+Shift+F

But will we encounter a time when pressing Ctrl + Shift + F doesn’t work
Ctrl + Shift + F is a simple and complex replacement in Sogou Pinyin. Once you install Sogou Pinyin, this shortcut key will be occupied, but you can set the simple and complex shortcut keys of Sogou for other users. In other cases, you can use the format shortcut in eclipse 2. The problem of the whole keyboard
3. The shortcut key of Ctrl + Shift + F is occupied by other software (such as Sogou Pinyin and Baidu Pinyin)

② Eclipse automatically formats code when saving files

many people don’t know that eclipse has a very useful function, that is, the function of automatically formatting source code. In general, people use Ctrl + Shift + F to format files manually, which is a waste of time.

In fact, eclipse already has an automatic formatting function. By default, this function is not available.

Specific method: Windows — > Preferences–> Java –> Editor–> Save actions. You can see the options on the right. Check “perform the selected actions on save”. You can select or configure other options according to your needs.

Don’t forget, finally, apply and OK.

2. Format XML code: Ctrl + Shift + F, but you need to make the following modifications

but for XML files, sometimes after formatting, the configuration attributes of a control are all packed in one line, which is very inconvenient to read and modify.

We hope that the best formatting effect is as follows: each property configuration of the control occupies one line, which is easy to read and modify, and the control without child elements can be used directly/> close:

<?xml version=”1.0″ encoding=”utf-8″?>

< LinearLayout xmlns:android= ” http://schemas.android.com/apk/res/android ”

android:layout_ width=”fill_ parent”

android:layout_ height=”fill_ parent”/>

android:text= “Some Content”

android:layout_ width=”wrap_ content”

android:layout_ height=”wrap_ content” />

</ LinearLayout>

In order to achieve the above formatting effect, you need to modify some configuration of eclipse and do some additional operations

modify the XML format configuration of eclipse

The configuration of this step is to make the formatting effect occupy one line for each property configuration of the control. Enter window/preferences and expand to XML/XML files/editor,

Check “split multiple attributes each on a new line”, as shown in the figure below:


< TextView android:id= “@+id/TextView01”