# File Operations

## Creating a New File and inserting texts

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.

Anjuta occatinally 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.

To insert popular text bits in the file, place the cursor at the insertion point and select the right insert text menu item from File Insert Text. Some of the text bits use the user information (such as name and email) provided in Preferences (General page). So make sure you set them to correct values before inserting texts.

### Save file

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

## 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 OK. 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 OK. If you change your mind, click Cancel to dismiss the dialog without opening the file.

   Pressing TAB in the selection entry box works as auto complete for the file path. It behaves just like the usual shell auto complete and could be very helpful when the filenames are too long to type. 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 simlar 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, if switched on (pressed in), will make the hidden files (files starting with "."; visible in the file list. Depress it to make them hide. Anjuta fileselection dialog also has inbuild file type filter. Select the appropiate 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 OK to save the new file with the name supplied.

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 OK.

   ### 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.

### 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.

## 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 witll be visible. The rest could be made visible from View Editor.

#### Editor Margins

The Tags toolbar

The Line Numbers Margin is lagest 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 give 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 bookmaked lines which could be toggled from 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 visisble. 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 indicatior 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 markes 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 maching 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 Format Force Highlight Style.

### 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.

### 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 clicking on the Auto-format button in the main toolbar or choosing Format Auto-format on the menubar. Change the style of formatting by customizing the choices in the preferences.

#### indent

You will need to have the indent utility installed in order to use this feature. Read the info page for indent for further details.

## 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 refering 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 (souce file). If there is no tags (or sysmbols) 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 corrosponding 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 Find or press Alt F. This will open the Find dialog.

#### Find Text dialog

Find Text 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 OK to start searching.

If the search is successful, the matched text in the document will be highlighted and you will be taken to the line containing the match. If the search is not successful, a match not found message will be displayed.

If you want to search again, click on the Find button on the main toolbar. This will find the next match in the direction of the search. You can even change the search text when you do this. Enter the new string in the Find String text box in the main toolbar.

### Searching and replacing

#### Find and Replace dialog

Find and Replace dialog

Search and replace is similar to just finding text, except that you also specify the replace text in the Replace Text text box, and whether or not you want to be prompted before the replace takes place.

## Finding in Multiple Files and Folders

### Find in files dialog

Find in files dialog

To find in files and/or folders, add all the files and/or folders you want to search in by entering their names in the text box and clicking on the Add button.

Remember, directories are searched recursively. All of the files under the directory, and the files under all the subdirectories, and the files under all of the sub-subdirectories (and so on) are all included in the search.

If you want to remove or edit an entry in the list, select it by clicking on the item. Click on Remove, or make changes in the text box and click on Update.

Clicking on Clear will clear all the entries.

Enter the text you want to search and specify whether the search should be case-sensitive. Click OK to start searching.

The search results will be listed in the message window. Double clicking on them will take you to the file and particular line number where the match has been found. The matching line is also highlighted.

## 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 hilighted in the editor are also highlighted similarly in the print (or preview). Addtional options are available to print with the line numbers, wrapped lines and/or headers in the print preferences from File Page Setup.

### Print preview of a C file

Print preview

In the page setup (or print preferences), print margins, landscaped or portrait page layout 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 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.

### Print Dialog

Print dialog