The editor view within Eclipse, which sits under the LPCXpresso IDE, provides a large number of powerful features for editing your source files. These include...
Within the editor view, functions, structures etc may be folded to show the structure and hide the detail.
To enable folding, right click in the margin of the editor view to bring up the context sensitive menu, then select Folding->Enable Folding, or the keyboard shortcut Ctrl-Numpad_Divide.
You can then click on the (-) or (+) icon that now appear in the margin next to each function, structure, etc, to expand or collapse it, or use the Folding->Expand all and Folding->Collapse all options from the context sensitive menu (or use keyboard shortcuts Ctrl-Numpad_Multiply and Ctrl-Shift-Numpad_Divide).
Various settings for Folding can also be controlled through
Window -> Preferences -> C/C++ -> Editor -> Folding
Editor templates and Code completion
Within the editor, a number of related pieces of functionality allow you to enter code quickly and easily.
First of all, templates are fragments of code that can be inserted in a semi-automatic manner to ease the entering of repetive code - such as blocks of code for C code structures such as for loops, if-then-else statements and so on.
Secondly, the indexing of your source code that is done by default by the tools, allows for autocompletion of function and variable names. This is known as "content assist".
- Ctrl-Space at any point will list available editor template, function names etc
- Ctrl-Shift-Space will display function parameters
- Alt-/ for word completion (press multiple times to cycle through multiple options).
In addition, the predefined templates are user extensible via
Window -> Preferences -> C/C++ -> Editor -> Templates
The editor can highlight corresponding open and closing braces in a couple of ways.
First of all, if you place the cursor immediately to the right of a brace (either an opening or closing brace), then the editor will display a rectangle around the corresponding brace.
Secondly, if you double click immediately to the right of a brace, then the editor will automatically highlight all of the text between this brace and the corresponding one.
Syntax Coloring specifies how your source code is rendered in the editor view, with different colors used for different elements of your source code. The settings used can be modified in:
Window -> Preferences -> C/C++ -> Editor -> Syntax Coloring
Note that general text editor settings such as the background color can be configured in:
Window -> Preferences -> General -> Text Editors
Fonts may be configured in:
Window -> Preferences -> General -> Appearance -> Colors and Fonts
The editor offers a number of ways of comment in or out one or more lines of text. These can be accessed using the Source entry of the editor context-sensitive menu, or using the following keyboard shortcuts...
- Select the line(s) to comment, then hit Ctrl-/ to comment out using // at the start of the line, or uncomment if the line is currently commented out.
- Select the line(s) to comment, then hit Ctrl-Shift-/ to block comment out (placing /* at the start and */ at the end).
- To remove a block comment, hit Ctrl-Shift-\.
The editor can format your code to match the coding standards in use (Window -> Preferences -> C/C++ -> Code Style). This can automatically deal with layout elements such as indentation and where braces are placed. This can be carried out on the currently selected text using the Source->Format entry of the editor context-sensitive menu, or using the keyboard shortcuts Ctrl-Shift-F. If no text is selected, then the format will take place on the whole of the current file.
As you enter code in the editor, it will attempt to automatically indent your code appropriately, based on the code standards in use, and also the layout of the preceeding text. However in some circumstances, for example after manually laying text out, you may end up with incorrect indentation.
This can usually be corrected using the Source->Correct Indentation entry of the editor context-sensitive menu, or using the keyboard shortcuts Ctrl-I. Alternatively use the "Format code" option which will fix other layout issues in addition to indentation.
Insert spaces for tabs in editor
You can configure the IDE so that when editing a file, pressing the TAB key inserts spaces instead of tab characters. To do this go to
Window -> Preferences -> General -> Editors -> Text Editors
and tick the "Insert spaces for tabs" box.
If you tick "Show whitespace characters" you can see whether a tab character or space characters are being inserted when you press the TAB key
Replacing tabs with spaces
To replace existing tabs with spaces throughout the file, open the Code Style preferences:
Window -> Preferences -> C/C++ -> Code Style
Select a Code Style profile and then select Edit...
Choose the Indentation tab
For the Tab policy, select Spaces only
Apply the changes.
The new style will be applied when the source is next formatted
Source -> Format