# File Operations

## Creating a New File and inserting texts

### Creating New File

To create a new file, choose File New from the menubar, or click on the New File button on the toolbar. A new page will appear in the editor (or a new window if the parent document is windowed). This new document 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 FileNew File from the menubar. This will open the New File Wizard dialog. Select the file type. Enter the File name. The suffix will be automatically added. You can add a license information (according to your license choice) and a header. In case of 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 files during some operations. For example, some CVS operations, such as diff, file log, file status etc, create new files and add the output there. These could be saved in real file just like normal new files.

### Inserting Macros

Macros can be used to quickly edit repetitive sequences of text.

Macro plugin must be activated.

#### Inserting

Two types of macros are available: Anjuta macros and User macros (My macros). Anjuta macros are not modifiable by the user. On the other hand, User macros can be defined and modified by the user.

To insert macro, move the cursor at the desired place. Select EditMacros Macros.... The dialog window appears. Select the wanted 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 possibility to insert macro is to select Edit Macros Insert Macro..., then to press the wanted macro shortcut.

##### Macro

The Macro dialog

#### Defining Macros

From the Insert-Macro window, choose Add or select EditMacros 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.

The user can also erase a macro by selecting it in the list (only My Macros) then by choosing Remove.

Same manner, macro can be edited and modified by selecting it in the list then by choosing Edit.

##### Add/Edit Macro

Add Edit dialog

#### Macro Keywords

Macros Keywords are available. They can be integrated in the macro definitions. The names of these macro Keywords start and finish by 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@, @USETABS@.

##### Keyword Macro

The Keyword macro

## Opening and Saving Files

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

   ### Open File dialog

   The Open File dialog Select or enter the file you want to open, then click Open. To open more than one file at once, select multiple files to open by first pressing CTRL and clicking the files in the list and press Open. If you change your mind, click Cancel to dismiss the dialog without opening the file.

   For selecting multiple files at once, select a file in the dialog and press CTRL once. This will bring the file selection dialog in multiple-select mode and multiple files could be selected from the list. Multiple file select mode is similar to single file select mode, except that the file operation (for which the file selection was being done) will be performed for all the selected files.

   ### Open Multiple File dialog

   The Open File dialog in multiple-select mode

   The Show Hidden Files, if switched on (Click right), will make the hidden files (files starting with "."; visible in the file list. Depress it to make them hide. Anjuta file selection dialog also has inbuilt 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 menubar, click on the Save button on the toolbar, or press CtrlS. 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 auto save

   If you have enabled auto-save, it will not auto-save any new files. You must first save them manually. The same applies to the Save All option: it will not save new files, if you haven't saved them first manually. You must save a file manually before auto-save 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 menubar. 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 menubar, or click on the Close button on the toolbar. The file could also be closed by clicking the cross in the 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 helpful features which aid in editing and working with source files. The following sections describe how to use some of the interesting features available.

### Editor Margins

Editor Margins: Editor margins are the small area on the left of the editor for some special purposes. There are three editor margins available and all of them may not be available when you first start anjuta. They are Line numbers margin, Markers margin and 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 could be made visible from View Editor.

#### Editor Margins

The Tags toolbar

The Line Numbers Margin is largest of all the three margins (and slightly darker then rest) and displays the document's line numbers. Line Number Margin could be made visible or invisible by toggling View Editor Line Numbers Margin. Single left clicking on this margin will select the whole line (including the last newline, if present). You can set the font properties for line number margin in the preferences.

Markers Margin is the next margin which can be made visible or invisible by selecting View Editor Markers Margin. This margin displays graphical icons to mark the given line. The markers which will be displayed in this margin are Bookmark marker (rectangular blue colored icon), Breakpoint marker (circular red colored) and Line indicator (pointed arrow yellow colored). Bookmark marker is used to indicate bookmarked lines which could be toggled from Goto Bookmark Toggle Bookmark with the cursor placed in that line. The breakpoint marker is used in debugger to mark the line with debugging breakpoints (see debugging section for more details). The line indicator marker is used to indicate a line when we do a jump from another part, for example when navigating the bookmarks and during single stepping in debugger.

Code folding margin is where the folding tree is visible. Clicking on these folding tree nodes will fold or unfold the code blocks. An underline will also be drawn below the 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, the markers will be displayed by changing the background color of the line. For example, if there a breakpoint marker is set in a line and the marker margin is not visible, that line will be displayed with red background. Similarly, for bookmark marker and line indication 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 Markers Margins from View Editor Markers Margin.

#### Editor markers when markers margin is invisible

The Tags toolbar

### Editor Guides

The editor could be made to make certain document information, which otherwise are normally not visible. Indentation guides, white spaces and line end characters are such information which could be made visible for editing comfort. They could be make visible or invisible by toggling the menu items in View Editor. Indentation guides are the small dotted lines drawn to connect the matching braces in the source code. When the cursor is over one such matching braces, the dotted indentation guide is highlighted to give a visual region of the indentation.

#### Editor with guides

Editor with guides

### Syntax highlighting

Anjuta can highlight many different languages. This is usually done automatically by determining the type of the file from the file extension. If Anjuta cannot determine the type of the 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.

### Code folding

Source files which have block coding properties (such as C, C++, Pascal, Java etc.), have the advantage of working with code folds. All of the code blocks in the source file can be folded or unfolded by clicking on the fold points in the 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 big source files that run to thousands of lines. Once the folds are closed, the 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

If the current file is a C or C++ source or header file, then it is possible to automatically indent (auto-format) the file. This gives a clean look to the source code, increases legibility, reduces the likelihood of syntax errors, and above all it saves time. This can be performed by choosing Edit Auto Indent on the menubar. Change the style of formatting by customizing the choices in the preferences.

## Symbol browser and Browsing Files

All C and C++ source and header files can be browsed using the tags in the files. All of the open C and C++ source and header files are scanned for available tags (a "tag" refers to a function definition, structure, macro, etc.). Please note that Tag and Symbol is used synonymously in this manual, except when referring to Tags browser and Symbol browser, which two different interfaces.

1. Tags Browser: Tags browser is available on the Browser toolbar. It shows a list of tags available in the currently active file (source file). If there is no tags (or symbols) available in the file, the tags list will be invisible and a "No Tags" will be displayed instead. The tags in this list are shown along with the line numbers where they are found. If there are multiple symbols with the same name, they will be shown with different line numbers.

   ### Tags toolbar

   The Tags toolbar

   ### Function symbols

   Function prototype and definition, if present in the same file, can be usually distinguished from the corresponding line numbers. Prototypes usually comes before the definition, so they are likely to have smaller line numbers.

2. Symbol Browser: If there is a project open, Anjuta will scan for tags in all of the source and header files of the project. This way it is possible to go to any function definition, structure definition, class definition etc. without manually opening the file. You don't even have to know which file that tag is found in (except in the case of function definitions). The symbol browser lists all the available symbols in the project.

   ### Tags toolbar

   Symbol browser

### Tags 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 text or regular expression string in the current file, choose Edit Search Find or press CtrlF. 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 (RegExp). It is also possible to 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, the matched text in the document will be highlighted, marked... (according to the search action choice). If the search is not successful, a The match "search text" was not found message will be displayed.

If you want to search again, click on the Search button on the main toolbar or press CtrlG. This will find the next match (ShiftCtrl 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 main toolbar.

#### Search Text dialog

To stop a long research, choose Stop button.

If the "Basic Search" option is selected in the Setting window, the search direction can be chosen from the Expression window.

#### Basic Search Text dialog

### Specifying Search Range

In the "Search Target dialog", define the search location and the action to be done in case of search success.

The maximum number actions can be defined by User.

#### Search Target dialog

The user can select where the text will be searched.

#### Search Target In choice

#### Searching in Files

To find text in your project, select "search in" All Project Files.

Enter the text you want to search and specify search options (case-sensitive, complete words ...). Click Search to start searching.

To find text in File list, select "search in" Specifying File List. Define the Search variables. Click Search to start searching.

##### Search File Pattern

### Specifying Search Action

The user selects which action will be done in case of search success.

According to the previous selections (Search in, Search direction ...), some actions could be unavailable.

#### Search Target Action choice

### Replacing

Search and replace is similar to just finding text, except that you also specify the replace text in the Replace With: text box, and whether or not you want to be prompted before the replace 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

The user has the possibility of saving the setting of his search options.

Item highlighted in red is the active item. Item by default is the search setting which is loaded at Anjuta launching.

#### Search Setting dialog

## Printing a file

Print preview could be taken by selecting File Print Preview. It will render the current file and present a preview of the print. Source codes which are highlighted in the editor are also highlighted similarly in the print (or preview). Additional options are available to print with the line numbers, wrapped lines and/or headers in the Printing tab of your editor plugin preferences.

### 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 print the file with Print on it.

Landscaped or portrait page layout, paper size, page orientation and paper type could also be set. Remember to set them up properly according to your printer, otherwise printing may not come up properly.

### Print Dialog

Print Dialog