# File Operations

## Creating a new file and inserting text

### Creating a New File

To create a new file, choose File New from the menu bar, or click on the New File button on the main toolbar. A new page will appear in the editor (or a new window if the parent document is windowed). New documents will be named `newfile#1`, `newfile#2`, `newfile#3` and so on.

#### Save file

You should save new documents as soon as possible to avoid any data loss in case of a crash.

### File Wizard

A wizard can also be used to create a new file. To create a new file, choose File New File from the menu bar. This will open the New File dialog. Select the file type. Enter the filename. The suffix will be automatically added. You can add license information (according to your license choice) and a header. In case of a C/C++ header file, you can also add an header template. Click OK to validate the creation.

#### New File Wizard

The Open File dialog

Anjuta occasionally also creates new file windows during some operations. For example, some Subversion operations such as `Diff` and `View Log` create new file windows and add the output there. You can save the contents of these windows to real files if you like.

### Inserting Macros

You can use macros to quickly edit repetitive sequences of text.

The Macro plugin must be activated.

#### Inserting

Two types of macros are available: Anjuta macros and user macros (displayed as "My macros"). Anjuta macros are not modifiable, but you can define and modify your own user macros.

To insert a macro, move the cursor to the desired place. Select Edit Macros Macros.... A dialog window appears. Select the desired macro in the list. The result of the macro expansion is displayed in the window and a summary is shown in the dialog window. Choose Insert. The expanded macro text is inserted at the cursor position.

Another way to insert a macro is to select Edit Macros Insert Macro..., then to press the desired macro shortcut.

##### Macro

The Macro dialog

#### Defining Macros

From the Insert Macro window, choose Add or select Edit Macros Add Macro... . The Add/Edit window appears. Enter the macro name, choose or define a category and enter a shortcut. Then edit text relative to your macro. The character ' | ' will indicate the cursor position after the macro insertion. Choose OK. The macro is added to the list.

You can also erase a macro by selecting it in the list and choosing Remove. This only works for user macros (My Macros), of course.

Similarly, you can edit and modify a macro by selecting it in the list and choosing Edit.

##### Add/Edit Macro

Add Edit dialog

#### Macro Keywords

Macro keywords are available. They can be included in macro definitions. These macro keywords start and finish with the character ' @ '.

Available macro keywords are @DATE_TIME@, @DATE_YMD@, @DATE_Y@, @USER_NAME@, @FILE_NAME@, @FILE_NAME_UP@, @FILE_NAME_UP_PREFIX@, @EMAIL@, @TABSIZE@, @INDENTSIZE@, and @USETABS@.

##### Keyword Macro

The Keyword macro

## Opening and Saving Files

1. Opening a file: To open an existing file, choose File Open from the menu bar, click on the Open button on the toolbar, or press Ctrl O. This will display the Open File dialog.

   ### Open File dialog

   The Open File dialog Select or enter the name of file you want to open, then click Open. To open more than one file at once, select multiple files to open by holding down the Ctrl key and clicking each file in turn; then press Open. If you change your mind, click Cancel to dismiss the dialog without opening the file.

   ### Open Multiple File dialog

   The Open File dialog in multiple-select mode

   You can enable the Show Hidden Files option through the pop-up menu that appears when you right-click in the Open File dialog. This option will make hidden files (files starting with ".") visible in the file list. Clear the option to hide hidden files. The Open File dialog also has a built-in file type filter. Select the appropriate file type filter in the dialog and the file list will be limited to the files of the selected type only.

2. Saving a file: To save a file, choose File Save from the menu bar, click on the Save button on the toolbar, or press Ctrl S. This will save the file. If the file is new, a Save As dialog will appear. Enter a filename and click Save to save the new file with the name supplied. The Save As File

   ### File autosave

   If you have enabled autosave, Anjuta will not autosave any new files. You must first save them manually. The same applies to the Save All option: Anjuta will not save new files, if you haven't saved them first manually. You must save a file manually before autosave or Save All will work with it.

3. Saving a file with a different name: You can explicitly save a file with a new filename. To do this, choose File Save As from the menu bar. A Save As dialog will appear prompting you to enter the new filename. Enter the name and click Save.

   ### File save as overwrite

   When you use Save As with an existing file, the original is not deleted. It is left unchanged since the last save. If a file with the new filename already exists, a confirmation dialog will appear to ensure that you want to overwrite it. Clicking Yes will overwrite the file with the file you are saving.

4. Closing a file: To close a file, choose File Close from the menu bar, or click on the Close button on the toolbar. (You can also close a file by clicking the X in its filename tab.) This will close the current file. If the file is not saved, or is a new file, then Anjuta will prompt you to save the file before closing it.

## Editing Files

Anjuta has a number of features which help you edit and work with source files. The following sections describe how to use some of the interesting features available.

### Editor Margins

Editor Margins: Editor margins appear to the left of the editor and are used for some special purposes. There are three editor margins available: the line number margin, the marker margin and the code fold margin. By default (that is, when you run Anjuta for the first time) only the code fold margin will be visible. The rest can be made visible via View Editor.

#### Editor Margins

The Tags toolbar

The line number margin is largest of all the three margins (and is slightly darker then rest) and displays a document's line numbers. The line number margin can be shown or hidden by toggling View Editor Line Numbers Margin. Left-clicking on this margin will select an entire line (including the trailing newline, if present). You can set font properties for the line number margin in the preferences.

The marker margin can be shown or hidden via View Editor Markers Margin. This margin displays graphical icons to mark the given line. The margin may display bookmark markers (blue and rectangular), breakpoint markers (red and circular) and line indicator markers (which look like a yellow pointed arrow). A bookmark marker indicates a bookmarked line, and can be toggled via Goto Bookmark Toggle Bookmark with the cursor placed on that line. A breakpoint marker is used in the debugger to indicate a debugging breakpoint (see the Debugging section for more details). A line indicator marker is used to indicate the current program position in the debugger.

The code fold margin is where the folding tree is visible. Clicking on folding tree nodes will fold or unfold code blocks. An underline will also be drawn below a folded line to make it more obvious that a block of code has been folded below the line. For more details on code folding, see the section Code Folding below.

#### Invisible margin marker

If the marker margin is not visible, Anjuta displays markers by changing the background color of a line. For example, if a breakpoint marker is set in a line and the marker margin is not visible, that line will be displayed with a red background. Similarly, for a bookmark marker and a line indicator marker the background color of the line will be sky blue and yellow, respectively. If you do not like this (perhaps due to some contrasting themes), enable the marker margin via View Editor Marker Margin.

#### Editor markers when the marker margin is invisible

The Tags toolbar

### Editor Guides

The editor can be set to display certain document information which is normally invisible, including indentation guides, white space and line end characters. They can be make visible or invisible by toggling the menu items in View Editor. Indentation guides are small dotted lines drawn to connect matching braces in source code. When the cursor is over a matching brace, its dotted indentation guide is highlighted to emphasize the indentation level visually.

#### Editor with guides

Editor with guides

### Syntax highlighting

Anjuta can highlight the syntax of many different languages. This is usually done automatically by determining the type of a file from its extension. If Anjuta cannot determine the type of a file, there will be no syntax highlighting. You can explicitly force a particular highlight style by selecting the style from the menu View Editor Highlight Mode.

Anjuta uses a properties file named `$prefix/share/anjuta/properties/anjuta.properties`, which has the same format as a SciTE properties file but does not use all properties. The style of each element for all languages is defined in a file named `$prefix/share/anjuta/properties/styles.properties`. It uses some common properties defined by Anjuta in the file `$home/.config/anjuta/scintilla/editor-style.properties`.

### Code folding

Anjuta can display code folds for source files in block-structured languages (such as C, C++, Pascal, and Java). All code blocks in a source file can be folded or unfolded by clicking on the fold points in the code fold margin of the Editor window (usually a +/- symbol or up/down arrow). These fold points automatically appear for source files which use code blocks.

Code folding is especially useful when editing large source files with thousands of lines. Once the folds are closed, a document appears to become smaller, facilitating easy browsing and editing of the file.

Please note that code folding and editor guides are only available in the Scintilla-based editor.

### Auto-formatting source code

Anjuta can automatically indent (auto-format) C or C++ source or header files. This gives a clean look to the source code, increases legibility, reduces the likelihood of syntax errors, and above all saves time. To auto-indent the current source file, choose Edit Auto Indent on the menu bar. You can change the style of formatting by customizing the choices in the preferences.

## The Symbol Browser

You can browse C and C++ source and header files using tags in the files. A tag (or symbol) refers to a named entity such as a function definition, structure, or macro. Anjuta scans open C and C++ source and header files for available tags.

Anjuta will automatically scan for tags in all of the source and header files of any open project. You can jump to any function definition, structure definition, class definition or other tag without manually opening the containing file. You don't even have to know which file the tag is found in. The symbol browser lists all available symbols in the project.

### Symbol browser

Symbol browser

### Tag synchronization

You don't have to worry about the synchronization and update of the tag database. Anjuta will take care of everything. You just have to decide which tag you want to go to!

## Searching for and Replacing text in files

### Searching

To search for a string or regular expression in the current file, choose Edit Search Find or press Ctrl Alt F. This will open the Find dialog.

Use the text box to specify the string to search for, and select whether it is a normal string or a regular expression. You can also specify the direction of search, whether the search is case-sensitive or not, and the scope of the search. Click Search to start searching.

If the search is successful, Anjuta will jump to the matched text or perform another action (according to the Search Action you choose in the Search Target tab). If the search is not successful, Anjuta will display a message indicating that the search text was not found.

If you want to search again, click the Search button again or press Ctrl G. This will find the next match (use Shift Ctrl G for the previous match). You can even change the search text when you do this; enter the new string in the Search Expression text box in the search dialog.

#### Search Text dialog

To stop a long search, press the Stop button.

### Specifying Search Range

In the Search Target tab, define the search location and the action to be performed if the search succeeds.

You can define the maximum number of actions to be performed.

#### Search Target dialog

You can select which text will be searched.

#### Search Target In choice

#### Searching in Files

To find text in your project, set Search In to All Project Files.

In the Search Expression tab, enter the text you want to search for and specify search options, such as the Match case or Match complete words options. Click Search to start searching.

To find text in a set of files, set Search In to Specify File Patterns. Define the search variables. Click Search to start searching.

##### Search File Pattern

### Specifying a Search Action

You can select which action will be performed when a search succeeds.

Depending on the previous selections (Search In, Search Direction , and so on), some actions may be unavailable.

#### Search Target Action choice

### Replacing

Searching and replacing is similar to just finding text, except that you also specify the replacement text in the Replace With text box, and also specify whether or not you want to be prompted before each replacement takes place (Replace First Match or Replace All Matches).

#### Replacing

Choose Replace to replace the matched text or Forward to jump to the next matched text.

### Search Setting

You may also save search options.

The item highlighted in red is the active item. The default item specifies search settings which are loaded when Anjuta launches.

#### Search Setting dialog

## Printing a file

You can perform a print preview by selecting File Print Preview. This will render the current file and present a preview of the print. Source code which is highlighted in the editor is also highlighted similarly in the preview (and subsequent print). The Printing tab of your editor plugin preferences contains additional options which let you print with line numbers, wrapped lines and/or headers.

### Print preview of a C file

Print preview

### Print Preferences

Print preferences

When you are ready to print and satisfied with the preview, select File Print or Print from the print preview window. This will bring up the actual print dialog as shown below. Select the appropriate print parameters and press Print to print the file.

You can also set landscaped or portrait page layout and the paper size, page orientation and paper type. Remember to set them up properly according to your printer, otherwise printing may not look correct.

### Print Dialog

Print Dialog