Next Previous Table of Contents

### 7. Working with the Editor

An important part of the integrated development environment is the editor. You're using it for:

- creating, opening and saving source and project files
- editing source and project files
- writing your SGML documentation
- printing your project files

Generally, the editor itself doesn't do much difference in comparison to other editors; especially as it is a build-in version of the popular KWrite, also known as the "Extended Editor". If you're familiar with that, you won't have any problems using it for managing your projects. In addition to normal editors, KDevelop contains a new printing system, that is far more extended for use with sourcecodes- and you can choose between the printing program you want to use.

This section gives you more information about how to handle your project files and to make you more familiar with the editor's functionality. A lot of Unix-hardliners would prefer using Emacs or XEmacs- they're fine with that. But it isn't necessary for easy programming, and especially for beginners, to work themselves into powerful editors which shall, in the result, only allow you to enter your code.

### 7.1 Managing Project Files

The following sections describe how to create, save, open and close your project files you need to edit- mind that this doesn't include translation files or pixmaps. Those are recognized automatically and the according editing program like KTranslator opens those files for you.

To give you an easy access to your files, KDevelop contains two easy-to-handle tree-views, similar to a filemanager, that recognize if you selected a file, and opens it in the according editor window. The main view contains two windows that are used independently, but connected via the Project Editor, so you can do all menubar actions the same way. The intention behind this is that it allows you to handle two windows at the same time, although only one is visible. The C/C++ window thereby takes another task, which allows you to easily compile your sources one by one, so you can check the implementations without having to run a complete build-process over your project.

This can be done when having the C/C++ window on top. Select "Compile File" from the Build-menu or press the according button in the toolbar. Your file gets saved and compiled, and you can control any errors by the Compiler output in the output window.

Within the IDE you can open as many text files as you like. All opened files are listed in the Window-menu, so you can switch between them by selecting the according filename from the menu. Further, the actual opened file is displayed with its name in the window frame of KDevelop.

#### Creating and Saving Files

To create a new file, choose "New" from the File-menu. This opens the "New File" dialog, where you can specify the filename and type. Additionally, you have to set the destination directory as well if the file is added to the project or not. Finally, you can also use your header template for the project in case you want to add a new sourcefile without generating a new class by the Class-Generator.

After the file has been created, you can edit the new file as usual; if you have to switch between different files, you can always turn back to the file either via the file-trees or by the Window-menu.

For saving any changes, KDevelop offers a whole variety of options. The standard way would be to save the file by selecting "Save" or "Save As" from the File-menu or by the Save-button on the toolbar. For saving all changed files at once, you could as well select "Save all" from the File-menu.

Now, when working on a project, it is very annoying if something critical happens while you have done a lot of changes on your files; sometimes you will bite yourself that you have forgotten to save the changes. KDevelop takes care of this by offering "Autosaving", which is by default enabled and set to save all files in intervals of 5 minutes. To select another saving period or to disable this, see KDevelop Setup, where the setup options are described.

Additionally, KDevelop takes care for all changes if you open another project or exit KDevelop. You will be asked for saving the changed files, where you also have the option to specify which one to save and which you want to stay unsaved. Further, when invoking any build-processes, your files get saved automatically, so you won't ever wonder why your application doesn't run the way you expected it to do after your changes to the source files. The only exception is the "Compile File" command, which only saves the currently opened source file visible in the source editor window.

#### Opening and Closing Files

To open a source file, you have a lot of options as well. One way could be, as the standard for editors, to select "Open" from the File-menu. You will be presented an "Open File" dialog, which allows you to choose the file you want to edit. Another, probably more frequently used way is to select the file from the LFV, the Logical File Viewer, or the RFV, the Real File Viewer (see Overview ). The advantage of the file trees is that they provide a quick visual access to your files, especially the LFV, which only displays your project files by their type, collected into folders. You can as well configure the LFV towards sorting your files in another manner by a right mouse click on the tree. Select "New Group" from the popup-menu, and you can configure a new group, or select "Edit Group" to install new file filters by specifying the group's file extensions, separated by commas.

The standard file groups for a project generated by KAppWizard are the Headers, Sources, GNU and Others. Additionally, after adding a translation file, KDevelop adds a folder "Translations", containing your *.po files.

To close files, select the file to close from the Window-menu, which loads the opened file into the front editor. Then select "Close" from the File-menu. If your file has been changed, you will be asked to save it. When closing a project, all currently opened files will be checked for changes and you will be asked for saving as well.

### 7.2 Navigating within Files

The following gives you a general guideline how to locate certain positions within your files for a quicker access.

» How to find a certain line in a file

1. Select "Goto Line" in the "View"-menu or press CTRL+G. The dialogfield "Goto Line" appears.
2. Insert the linenumber you want to go to.
3. Press OK.

» How to set a bookmark

1. Set the cursor to the line you want to access via a bookmark
2. Select "Set Bookmark" from the "Bookmarks"-menu.
3. A popup-menu opens that allows you to select the bookmark number you want to set for the new bookmark.
4. Select the bookmark number.

Another way to set bookmarks would be to select "Add Bookmark" from the "Bookmarks"-menu. This sets a bookmark to the current line and appends it to the bookmarks-list. The documentation browser also offers setting a bookmark to the current page by a context menu entry "Add Bookmark".

» How to delete bookmarks

The bookmarks are set for each editing window separately- mind that your bookmarks aren't connected to a certain file you set the bookmark for. To delete all bookmarks, select "Delete Bookmarks" from the "Bookmarks"-menu. This deletes the bookmarks for the window actually on top, either the Header window, the C++ window or the browser window.

» How to go to a bookmarked line

1. Select the "Bookmarks"-menu and open the popup menu containing the bookmarks for the window containing the bookmark you want to view; either the C++-Window or the Header-Window entry.
2. Select the bookmarked line.

Selecting a bookmark for the browser window will open the browser and loads the page.

### 7.3 Working with Keyboard Shortcuts

For using the editor, you should make yourself comfortable with some keyboard shortcuts that make it easier to position the cursor and edit the file. The complete shortcut reference is also listed in section Overview.

    one letter to the left                           Left Arrow
    one letter to the right                          Right Arrow
    one word to the left                             CTRL+Left Arrow
    one word to the right                            CTRL+Right Arrow
    one line upwards                                 Up Arrow
    one line downwards                               Down Arrow
    to the beginning of the line                     POS 1
    to the end of the line                           END
    one page up                                      PageUp
    one page down                                    PageDown
    to the beginning of the current file             CTRL+PageUp
    to the end of the current file                   CTRL+PageDown
    one letter to the left                           SHIFT+Left Arrow
    one letter to the right                          SHIFT+Right Arrow
    one word to the left                             CTRL+SHIFT+Left Arrow
    one word to the right                            CTRL+SHIFT+Right Arrow
    one line upwards                                 CTRL+Up
    one line downwards                               CTRL+Down
    to the beginning of the current line             CTRL+POS 1
    to the end of the current line                   CTRL+END
    one page up                                      SHIFT+PageUp
    one page down                                    SHIFT+PageDown
    to the beginning of the current file             CTRL+SHIFT+PageUp
    to the end of the current file                   CTRL+SHIFT+PageDown
    en/disable insertmode                            INS
    copy selection to the clipboard                  CTRL+C, CTRL+INS
    insert text from the clipboard                   CTRL+V, SHIFT+INS
    delete current line                              CTRL+K
    insert line after current line                   END, then Enter
    insert line before current line                  POS 1, then Enter
    undo editing step                                CTRL+Z
    redo an undo step                                CTRL+Y
    tabulator                                        TAB
    delete letter left of cursor position            Backspace
    delete letter right of cursor position           Delete
    delete selected text                             Select text, then Backspace

### 7.4 Edit Windows Settings

The editor inside KDevelop can be configured towards special editing needs with a global effect on all editing windows. Thereby you can set the color modes, highlighting colors (also configurable in reference to the programming language of the file) and automatic text settings like tab-with and selection modes. The following describes how to set these options by the configuration dialogs provided in the "Options"-menu.

#### General Settings

The editor's general settings can be configured with the "Editor" entry in the "Options"-menu. Select the according values and press OK after you finished with your configuration.

#### Edit Options

Auto Indent:

  this sets the editor to place the cursor below the first literal when a new line is entered.

Backspace Indent:

  this option sets the cursor below the first literal of the line above when backspace is pressed.

Word Wrap:

  words are taken into the next line after the column set in "Wrap Words At:"

Replace Tabs:

  tabulators in the current text are replaced with tabulators of the "Tab Width:" value

Remove Trailing Spaces:

  removes trailing spaces

Wrap Cursor:

  sets the cursor to the end of the last line when backspace enters the beginning of a line

Auto Brackets:

  creates a closing bracket in front of the cursor when a bracket (any kind) is opened.

#### Select Options

Persistent Selections:

  selections made stay marked after setting the cursor to a different place

Multiple Selections:

  allows multiple independent selections within the text

Vertical Selections:

  allows vertical selections of text

Delete On Input:

  deletes a selection when writing in the selection.

Toggle Old:

  allows only one selection. A selection made gets deselected when another selection is made.

Wrap Words At:

  sets the maximum columns that a line can have. The word that contains a letter that reaches over this value will be automatically broken into the next line.

#### Colors

For changing the editor's general appearance, you can define a set of colors that the editor uses by selecting "Editor Colors" from the "Options"-menu. You can configure colors for:

- background: the editor's background
- text background: the background of displayed text
- selected: the color of selected text
- found: the color of text found by a search via the menu "Edit"-"Search", "Repeat search" and "Replace".
- selected + found: the color of text selected to search for and found

#### Syntax Highlighting

The syntax-highlighting mode of KDevelop's editor can be configured by two dialogs; first you can set default colors for syntax-highlighting by the "Editor Defaults" entry in the "Options"-menu. There, you can set colors and fonts as well as the fontsize for e.g. keywords. Select the default item and set all needed options.

The second configuration dialog is accessed by the "Syntax-Highlighting" entry in the "Options"-menu. This allows you to set the file filters for the programming language, e.g. *.cpp, *.h for C++. Then select the item that you want to configure. If you wish to use the default values you've set in the "Editor Defaults" dialog, select the "default" checkboxes in the Item-style and Item-Font sections. This reads the default settings for the selected item. After pressing OK, your new values will be enabled and used by the editor.

### 7.5 Searching and Replacing

#### Single File Search

» How to find one or more characters in the actual editing window

1. Select "Search" from the "Edit"-menu. This opens the search dialog.
2. Specify the expression to search for in the edit field. The drop-down menu offers selecting a previous search expression.
3. Select additional options like "Whole Words only"
4. Press OK.

To repeat searching for an expression entered in the search dialog, press F3.

#### Searching over Several Files

As the search function only is referencing searches over a single file that is currently visible, you're limited to this. But often you want to search for the same expression overall your project. Therefore, KDevelop contains a `grep`-dialog, which lets you search over all files that you specify either by setting the directory to start the search from and/or by mime-type. Specifying the exact directory and the mime-type will therefore reduce the time that KDevelop needs to read your files and display the results. To start a search over several files, select "Search in files..." from the "Edit"-menu. The search dialog opens and lets you enter:

- The expression to search for (the pattern)
- The template used for the search
- The mime-type of files to search in
- The directory to start form
- If the search is recursive over all included subdirectories

By default, the grep-dialog is set to start at your project directory and works recursively over implementation and header files.

You can even extend your search pattern by using the following options:

1. . Match any character
2. ^ Match the beginning of a line
3. $ Match the end of a line
4. \< Match the beginning of a word
5. \> Match the end of a word

For a repeating search, you can also use the available operators:

1. ? The preceding item matches less than once
2. * The preceding item is matched zero or more times
3. + The preceding item is matched once or more times
4. { n } The preceding item is matched exactly n times
5. { n,} The preceding item is matched n or more times
6. {,n } The preceding item matches less than n times
7. {n,m} The preceding item matches at least n times but less than m times

Backreferences to bracketed subexpressions are also available by the notation \n.

After specifying your search, press "Search". The results are then displayed in the result-window. To jump to a file and line number, select the resultline and press Enter or double click the result. The editor will automatically open the according file and place the cursor to the line of the result. This allows a complete specification for any search action and give out exact results.

KDevelop offers also some more specialized functionality to use grep within the editors and the browser. Select the expression you want to search for in either of the windows and press SHIFT+F2 or select "grep:<your_expression>" from the right button popup menu. This will ask grep to search for the selection in your project directory's files and will show the results immediately. Switching to the result works as described above. From within the editor window, it lasts to place the cursor over a word and start searching; the word under the cursor will be the search pattern.

#### Searching within Documentation

While working on a project, you often need to have information about the parameters of member functions you want to use- most often you remember the function's name that matches your needs, but the parameters are a very hard thing to keep in mind. Therefore, and for other purposes that may occur, KDevelop contains a search functionality that combines searching expressions that appear in your files with the documentation browser. To make use of this search functionality, you should have set up the documentation browser correctly and created the search database. For invoking a search through the documentation, do the following:

1. place your cursor at the word you want to search or mark an expression
2. select "Search Marked Text" from the Help-menu or press the right mouse button to open the context menu; then select "Look Up: "expression".
3. after the search result page is displayed in the documentation browser, select the page that you think could contain the information you need.
4. the selected documentation page is displayed and your search result is marked. To display the next result within the same documentation page, press F3.

This allows you to easily find the information you need. For using the results, the documentation browser allows marking a selection and copying it to the clipboard. Then return to the file you're editing and select "Paste" from the "Edit"-menu.

For a full description on how to use the Documentation, see Using the Searchindex.

#### Replacing Text

For replacing an expression, select "Search and Replace" from the "Edit"-menu. The "Search and Replace"-dialog lets you specify the expression to be replaced as well as the replacement expression. Then press OK. The first expression which is found will be marked, so you can see where the expression is and in which context. Then you can specify by a dialog if the expression shall be replaced or not. When the search is finished by reaching the end of the current file, you will be asked if you want to start the search again from the beginning. If you're finished, select "Cancel".

### 7.6 Printing

As KDevelop is designed to give developers the best access to files and information to reduce development cycles, it also contains a new printing utility which makes use of two common printing programs available for Unix-Systems, a2ps (ASCII-to-Postscript) and enscript. Besides these, you can also print by directly using lpr (the lineprinter device). As using a2ps or enscript offers the most options towards printing, you should install either one of these on your system; both programs are usually shipped with distributions, so you shouldn't have any problem to get them. But before printing, you should have a look at the available configuration dialogs to prepare the output according to your needs. The following section describes how to configure KDevelop for printing files.

#### Configuring the Printer

The printing programs can both be configured by selecting "Print" from the "File"-menu; on the printing dialog, select the program by the drop-down-menu in the left upper corner. Then press the "Options" button on the right. This opens the configuration for the selected program that will be used. Another way to configure the programs are selecting "Printer Configuration..." from the "Options"-menu; then select "a2ps" or "enscript".

#### The a2ps Configuration Options

#### Printing

- header: adds a header frame to the page
- filename: if checked, the header frame will contain the filename as its text
- login: adds the User ID to the right upper corner of the page
- borders: adds frame borders to the text page
- Date & Time: adds the printing date and time
- align files: prints out files on the same page, available for two-page printing mode
- set TAB size: sets the TAB size for printing TABs
- headertext: available, if filename is deselected and allows inserting another text to the header frame
- fontsize: sets the fontsize for the text. The default fontsize is 9

#### Textprinting

- cut lines: cuts the line's contents if the line is too large to be printed. If deselected, lines will be broken.
- interpret TAB, BS and FF: interpret TAB, Backspace and FastForward characters.
- replace non-printing character by space: if the file contains non-printable characters, those will be replaced by space characters.
- print non-ASCII character as ISO-Latin 1: prints characters not included in the ASCII format in ISO-Latin 1 mode output
- bold font: prints the whole text in bold font mode.

#### Numbering

- numbering lines: numbers all lines top-down if enabled
- numbering pages: allows selecting page-numbering mode by:
  - file single: numbers each file's pages beginning with 1
  - file together: appends all following pages after the first for page numbering
- lines per page: sets the maximum lines per page to be printed.

#### The enscript Configuration Options

#### Header

- Fancy Header: adds a fancy header
- Header Text: enables adding a header text
  - text: sets the text's contents
  - position: sets the text's position to left, center or right
- Login: add the UserID to the header
  - login: enables adding UserID
  - position: sets the position for the UserID
- Filename: add the filename to the header
  - Size of filename: add filename as full or short, meaning full path or filename only
  - Position: sets the position for the filename
- Hostname: add the hostname to the header
  - hostname: enables adding hostname
  - size of hostname: sets the size for hostname
  - Position: sets the position for hostname

#### Date & Time

- Current Date: include the current date
  - current date: enables current date adding
  - position: sets the position for the date entry
  - format: sets the date format
- Modification Date: include the last modification date
  - modification date: enables modification date adding
  - position: sets the position for modification date entry
  - format: sets the date format
- Current Time: include current time
  - current time: enables current time adding
  - AMPM:/ use AM/PM or 24h format
  - Position: sets the position for the time entry
  - Format: sets the time format
- Modification Time: include the last modification time
  - modification time: enables adding modification time
  - AMPM:/ use AM/PM or 24h format
  - Position: sets the position for the time entry
  - Format: sets the time format

#### Layout

- Numbering & Border:
  - numbering lines: adds line numbers to the document for printing
  - borders: adds a border to the pages for printing
  - numbering pages: numbers pages for printing
  - align files: appends files for page numbering
  - lines per page: the maximum value for lines per page
- Format and TAB:
  - set TAB size: sets the TAB size for interpreting TABs
  - font for header: sets the font used for the header text
  - font for body: sets the font for the body text (file contents)
- Textprinting:
  - cut lines: cuts the lines if too large. If unchecked, lines are broken
  - replace non-printing character by space: replaces characters that the printing charset doesn't support by space characters
- Other Options:
  - table of contents: adds a table of contents page that contains information about printed files, page numbers etc.
  - Highlight bars:
    - highlight bars: highlights rows for printing
    - cycle fo change: sets the number of rows to change highlight style
  - Wrapped line:
    - mark wrapped lines: lines that are broken get marked for printing
    - value for wrapped line: the preset value for the new line the line is broken into.

#### Underlay

- Text: sets the text to underlay
- Position: sets the position of underlay text
- Font: sets the font used for the underlay
- Angle: sets the angle for the underlay text
- Gray scaling: sets the grayscaling for the underlay text
- Style: sets the underlay text to be printed as outlined or filled

#### The Printing Dialog

#### Direct Printing Options

- Program: sets the printing program to be used for printing: a2ps, enscript or lpr
- Printer: sets the printer to be used for printing
- Output location: for printing into a file, select the output location
- Orientation: sets the orientation for printing, either landscape or portrait
- Copy: sets the amount of copies to be made per page
- Paper Size: sets the paper size to be used
- Output Format: for using enscript as printing program, you can choose between postscript or html printing
- Default Printsettings: sets the default settings to use for printing
- Outprinting:
  - Page Printing: sets one or two pages on one sheet
  - Pages: select all,odd or even for using enscript
  - Pretty Print:
    - pretty-print: enables pretty-print mode for enscript
    - color: use color printing
    - Pretty Print Mode: sets the printing mode dependent on your file format

#### File Selection

The file selection dialog is accessed by the "Files" button on the printing dialog. The file selection allows specifying which files to print out by certain criteria:

- File Selection:
  - current: the currently opened file visible in the editing window
  - all in project: all files included in the project currently opened
  - self chosen files: allows choosing the files to be printed by file-selection
  - all cpp files: prints out all source files of the project
  - all headers: prints out all header files of the project
  - changed files: allows specifying files that are changed in a timespan:
- Changed Files:
  - Between: specifies all files changed after:
    - Date: the date the files were changed
    - Time: the time the files were changed
  - And: specifies all files changed before:
    - Date: the date the files were changed
    - Time: the time the files were changed
- Self Chosen Files: available if self chosen files is selected (see above)
  - add: press this to add a file selected for printing in the lineedit field left
  - delete: deletes a selected file from the printing list
  - clear: clears the printing list

#### Print Preview

Print Preview is available for you to control how the output will look like. Therefore, KDevelop uses the program ghostview or kghostview. When the preview-button was pressed on either printing dialog, you will be presented a template output that shows you the effect of the currently set options.

Next Previous Table of Contents