The Kate Handbook
The Kate Handbook
Next

The Kate Handbook

Anders Lund

Seth Rothberg

Conversion to British English: John Knight
Revision 2.00.00 (2002-01-26)

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

Kate is a programmer's text editor for KDE 2.2 and above.

This handbook documents Kate Version 1.0


Chapter 1. Introduction
Introduction
Prev
Next

Chapter 1. Introduction

Welcome to Kate, a programmer's text editor for KDE version 2.2 and above. Some of Kate's many features include configurable syntax highlighting for languages ranging from C and C++ to HTML to bash scripts, the ability to create and maintain projects, a multiple document interface (MDI), and a self-contained terminal emulator.

But Kate is more than a programmer's editor. Its ability to open several files at once makes it ideal for editing UNIX®'s many configuration files. This document was written in Kate.


Editing this manual...


Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Chapter 2. The Fundamentals
The Fundamentals
Prev
Next

Chapter 2. The Fundamentals

Conversion to British English: Malcolm Hunter

If you have ever used a text editor, you will have no problem using Kate. In the next two sections, Starting Kate and in Working with Kate, we'll show you everything you need to get up and running quickly.

Starting Kate

You can start Kate from the K menu or from the command line.

From the Menu

Open the KDE program menu by clicking on the big K icon on the toolbar at the bottom left of your screen. This will raise the program menu. Move your cursor up the menu to the Editors menu item. A list of available editors will appear. Choose Kate.

Unless you configure Kate not to, it will load the last files you edited. See Configuring Kate to learn how to toggle this feature on and off.

From the Command Line

You can start Kate by typing its name on the command line. If you give it a file name, as in the example below, it will open or create that file.

%kate myfile.txt

If you have an active connection, and permission, you can take advantage of KDE's network transparency to open files on the internet.

%kate ftp://ftp.kde.org/pub/kde/README_FIRST

Command Line Options

Kate accepts following command line options:

kate --help

This lists the most basic options available at the command line.

kate --help-qt

This lists the options available for changing the way Kate interacts with Qt™.

kate --help-kde

This lists the options available for changing the way Kate interacts with KDE.

kate --help-all

This lists all of the command line options.

kate --author

Lists Kate's authors in the terminal window.

kate --version

Lists version information for Qt™, KDE, and Kate. Also available through kate -V

kate --license

Shows licence information.

Drag and Drop

Kate uses the KDE Drag and Drop protocol. Files may be dragged and dropped onto Kate from the Desktop, Konqueror or some remote ftp site opened in one of Konqueror's windows.

Working with Kate
Working with Kate

Working with Kate

Quick Start will show you how to toggle four simple options that will let you configure some of Kate's more powerful features right away. Keystroke Commands lays out some of the default keystroke shortcuts for those who can't or don't want to use a mouse.

Quick Start

This section will describe some of the items on the Settings menu so that you can quickly configure Kate to work the way you want it.

When you start Kate for the first time you'll see two windows with white backgrounds. Above the two windows is a toolbar with the usual labelled icons. And above that, a menu bar.

The left-hand window is a dockable side bar. It combines the Filelist and Fileselector windows. Switch between the two by clicking on the tabs at the top of the window.

If you've started Kate with a file, the right-hand window will show the file you are editing and the Filelist on the side bar will show the name of the file. Use the Fileselector window to open files.

You can toggle the Filelist and Fileselector window on and off in Settings menu. This menu offers you your first glimpse into Kate's power and flexibility. In this section we'll look at four items:

Show Toolbar

Toggles the toolbar on and off.

Show Filelist

Toggles the Filelist on and off. If the Filelist/Fileselector window is not open, Kate launches the side bar as a separate, undocked, window. To dock the window grab the two thin parallel lines above the tabs by clicking on them with your left mouse button and holding the button down. Drag the the window into Kate's editing window and release the left mouse button when you have positioned the Filelist/Fileselector window as you prefer.

Tip

If you have grabbed the two parallel lines successfully your mouse pointer will turn into two crossed arrows as you drag.

Show Fileselector

Toggles the Fileselector on and off. This menu item is the same as Show Filelist with one difference. Toggling it on launches the window with the Fileselector on top.

Show Console

Toggles a console emulator on and off at the bottom of Kate's window. In other words, it gives you a command line within the application.

Keystroke Commands

Many of Kate's keystroke commands (shortcuts) are configurable by way of the Settings menu. By default Kate honours the following key bindings.

Insert

Toggle between Insert and Overwrite mode. When in insert mode the editor will add any typed characters to the text and push any previously typed data to the right of the text cursor. Overwrite mode causes the entry of each character to eliminate the character immediately to the right of the text cursor.

Left Arrow

Move the cursor one character to the left

Right Arrow

Move the cursor one character to the right

Up Arrow

Move the cursor up one line

Down Arrow

Move the cursor down one line

Page Up

Move the cursor up one page

Page Down

Move the cursor down one page

Backspace

Delete the character to the left of the cursor

Home

Move the cursor to the beginning of the line

End

Move the cursor to the end of the line

Delete

Delete the character to the right of the cursor (or any selected text)

Shift+Left Arrow

Mark text one character to the left

Shift+Right Arrow

Mark text one character to the right

F1

Help

Shift+F1

What's this?

Ctrl+F

Find

F3

Find again

Ctrl+B

Set a Bookmark

Ctrl+C

Copy the marked text to the clipboard.

Ctrl+N

New document

Ctrl+P

Print

Ctrl+Q

Quit - close active copy of editor

Ctrl+R

Replace

Ctrl+S

Save your file.

Ctrl+V

Paste.

Ctrl+X

Delete the marked text and copy it to the clipboard.

Ctrl+Z

Undo

Ctrl+Shift+Z

Redo



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Getting Help
Getting Help

Getting Help

With Kate

This manual

Offers detailed documentation on all menu commands, configuration options, tools, dialogues, plugins etc. as well as descriptions of of the Kate window, the editor and various concepts used in the application.

Press F1 or use the Help Contents menu topic to view this manual.

What's This Help

What's This help offers immediate help with single elements of graphical windows, such as buttons or other window areas.

We strive to provide What's This help for any elements for which it makes sense. It is available throughout the configuration dialogue, and in many other dialogues as well.

To employ What's This help, press Shift-F1 or use the Help->What's This menu item to enable What's This mode. The cursor will turn into an arrow with a question mark, and you can now click any element in the window to read the What's This help for that element, if it is available.

Help Buttons in Dialogues

Some dialogues have a Help Button. Pressing it will start the KHelpCenter and open the relevant documentation.

With Your Text Files

Kate does not (yet!) provide any means for reading document related documentation. Depending on the file you are editing, you may find the Built in Konsole helpful for viewing related UNIX® manual pages or info documentation, or you can use Konqueror.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Chapter 3. Working With the Kate MDI
Working With the Kate MDI
Prev
Next

Chapter 3. Working With the Kate MDI

Anders Lund

Conversion to British English: Malcolm Hunter

Overview

Window, View, Document, Frame, Editor... What are they all in the terminology of Kate, and how do you get the most out of it? This chapter will explain all of that, and even more.

The Main Window

The Kate Main Window is a standard KDE application window, with the addition of dockable subwindows, or tool windows. It has a Menubar with all the common menus, and some more, and a toolbar providing access to commonly used commands.

The most important part of the window is the Editing Area, by default displaying a single text editor component, in which you can work with your documents.

The docking capabilities of the window is used for the tool windows:

And possibly other tool windows, for example provided by plugins.

The Tool Windows can be placed anywhere you want them inside or outside the main window by dragging the handle bar in the top of them with the left mouse button pressed, and stacked in shared tab windows if desired.

When dragging a docked window, a black rectangle will be displayed to indicate where the window will be placed if you release the mouse button, unless you move the mouse cursor outside the main window, in which case the dragged window will become a free floating top level window.

The Editor area
The Editor area

The Editor area

Kate is capable of having more than one document open at the same time, and also of splitting the editing area into any number of frames, similar to how for example Konqueror or the popular emacs text editor works. This way you can view several documents at the same time, or more instances of the same document, handy for example if your document contains definitions in the top that you want to see often for reference. Or you could view a program source header in one frame, while editing the implementation file in another.

When a document is available in more than one editor, changes made in one editor will immediately be reflected in the others as well. This includes changing the text as well as selecting text. Search operations or cursor movement is only reflected in the current editor.

It is currently not possible to have more instances of the same document open in the sense that one instance will be edited while the other will not.

When splitting an editor into two frames, it is divided into two equally sized frames, both displaying the current document of that editor. The new frame will be at the bottom (in the case of a horizontal split) or at the right (for a vertical split). The new frame gets the focus, which is visualised by a small green led in the focused frame.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

The File List
The File List

The File List

The file list displays a list of all documents currently open in Kate. Modified files will have a small floppy disk icon on their left to indicate that state.

If two or more files with the same name (located in different folders) are open, the names of the second will be prepended “<2>” and so on. The tool-tip for the file will display its full name including the path, allowing you to choose the desired one.

To display a document in the currently active frame, click the document name in the list.

The default location in the Kate window is to the left of the editing area, in a dockable tab window shared with the File Selector.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

The File Selector
The File Selector

The File Selector

The File Selector is a folder viewer, allowing you to open files from a displayed folder in the current frame.

From top down, the file selector consist of the following elements:

A Toolbar

This contains standard navigations tool buttons:

Home

Pressing it will cause the folder view to cd to your home folder.

Up

This will cause the folder view to cd to the immediate parent of the currently displayed folder if possible.

Back

Causes the folder view to cd to the previously displayed folder in the history. This button is disabled, if there is no previous item.

Forward

Causes the folder view to cd to the next folder in the history. This button is disabled, if there is no next folder.

Sync

This button will cause the folder view to cd to the folder of the currently active document if possible. This button is disabled, if the active document is a new, unsaved file, or the folder in which it resides can not be decided.

A URL entry

Here you can type the path of a folder to browse. The URL entry maintains a list of previously typed paths. To choose one use the arrow button to the right of the entry.

Tip

The URL entry has folder auto-completion. The completion method can be set using the right mouse button menu of the text entry.

A Folder View

This is a standard KDE folder view.

A Filter Entry

The Filter entry allows you to enter a filter for the files displayed in the folder view. The filter uses standard globs; patterns must be separated by white space. Example: *.cpp *.h *.moc

To display all files, enter a single asterisk *.

The filter entry saves the last 10 filters entered between sessions, to use one, press the arrow button on the right of the entry and select the desired filter string.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

The Built in Terminal Emulator
The Built in Terminal Emulator

The Built in Terminal Emulator

The built in Terminal Emulator is a copy of the KDE Konsole terminal application, for your convenience. It is available from the Settings->Show Terminal Emulator menu item or by pressing the F7 key, and will get the focus whenever displayed. Additionally, if the Sync Konsole with active document option is enabled, it will change into the directory of the current document if possible when it is displayed, or when the current document changes.

The default location in the Kate window is at the bottom, below the editing area.

You can configure the Konsole using it's right mouse button menu, for more information, see the Konsole manual.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Chapter 4. Working with the Kate editor
Working with the Kate editor
Prev
Next

Chapter 4. Working with the Kate editor

Conversion to British English: Malcolm Hunter

Overview

The Kate editor is the editing area of the Kate window. This editor is also used by KWrite, and it can be used in Konqueror for displaying text files from your local computer, or from the network.

The editor is composed of the following components:

The editing area

This is where the text of your document is located.

The Scroll bars

The scroll bars indicate the position of the visible part of the document text, and can be used to move around the document. Dragging the scrollbars will not cause the insertion cursor to be moved.

The scroll bars are displayed and hidden as required.

The Icon Border

The icon border is a small pane on the left side of the editor, displaying a small icon next to marked lines.

You can set or remove a bookmark in a visible line by clicking the left mouse button in the icon border next to that line.

The display of the icon border can be toggled using the View->Show Icon Border menu item.

The Line Numbers Pane

The Line numbers pane shows the line numbers of all visible lines in the document.

The display of the Line Numbers Pane can be toggled using the View->Show Line Numbers menu item.

Navigating in the Text
Navigating in the Text

Navigating in the Text

This section is not yet documented.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Working with the Selection
Working with the Selection

Working with the Selection

There are two basic ways of selecting text in Kate: using the mouse, and using the keyboard.

To select using the mouse, hold down the left mouse button while dragging the mouse cursor from where the selection should start, to the desired end point. The text gets selected as you drag.

Double-clicking a word will select that word.

Triple-clicking in a line will select the entire line.

If Shift is held down while clicking, text will be selected:

  • If nothing is already selected, from the text cursor position to the mouse cursor position.

  • If there is a selection, from and including that selection to the mouse cursor position

Note

When selecting text by dragging the mouse, the selected text is copied to the clipboard, and can be pasted by clicking the middle mouse button in the editor, or in any other application to which you want to paste the text.

To select using the keyboard, hold down the Shift key while using the navigation keys (The Arrow keys, Page Up, Page Down, Home and End, possibly in combination with Ctrl to extend the move of the text cursor).

See also the section Navigating in the Text in this Chapter.

To Copy the current selection, use the Edit->Copy menu item or the keyboard shortcut (defaults to Ctrl+C).

To Deselect the current selection, use the Edit->Deselect menu item, or the keyboard shortcut (default is Ctrl+Shift+A), or click with the left mouse button in the editor.

Using Block Selection

When Block Selection is enabled, you can make “vertical selections” in the text, meaning selecting limited columns from multiple lines. This is handy for working with tab separated lines for example.

Block Selection can be toggled using the Edit->Toggle Block Selection menu item. The default keyboard shortcut is F4

Using Overwrite Selection

If Overwrite Selection is enabled, typing or pasting text into the selection will cause the selected text to be replaced. If not enabled, new text will be added at the position of the text cursor.

Overwrite Selection is enabled by default.

To change the setting for this option, use the Select Page of the Configuration Dialogue.

Using Persistent Selection

When Persistent selection is enabled, typing characters or moving the cursor will not cause the Selection to become deselected. This means that you can move the cursor away from the selection and type text.

Persistent Selection is disabled by default.

Persistent Selection can be enabled in the Select Page of the Configuration Dialogue.

Warning

If Persistent Selection and Overwrite Selection are both enabled, typing or pasting text when the text cursor is inside the selection will cause it to be replaced and deselected.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Copying and Pasting Text
Copying and Pasting Text

Copying and Pasting Text

To copy text, select it and use the Edit->Copy menu item. Additionally, selecting text with the mouse will cause selected text to be copied to the clipboard.

To paste the text currently in the clipboard, use the Edit->Paste menu item.

Additionally, text selected with the mouse may be pasted by clicking the middle mouse button at the desired position.

Tip

If you are using the KDE desktop, you can retrieve earlier copied text from any application using the Klipper icon in the Kicker icon tray.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Finding and Replacing Text
Finding and Replacing Text

Finding and Replacing Text

The Find Text and Replace Text Dialogues

The Find and Replace Text dialogues in Kate are very much the same, except the Replace Text dialogue offers the means of entering a replacement string along with a few extra options.

The dialogues offer the following common options:

Text to Find

This is where to enter the search string. The interpretation of the string depends on some of the options described below.

Regular Expression

If checked, the search string is interpreted as a regular expression. A button for using a graphical tool to create or edit the expression will be enabled.

See Regular Expressions for more on these.

Case Insensitive

If enabled, the search will be case insensitive.

Whole Words Only

If checked, the search will only match if there is a word boundary at both ends of the string matching, meaning not an alphanumeric character - either some other visible character or a line end.

From Beginning

If checked, the search will start at the beginning of the first line in the document, otherwise it will start at cursor position.

Find Backwards

If checked, the search will look for the first match above the starting point, either cursor position or the beginning of the document, if the From Beginning option is enabled.

The Replace Text Dialogue offers some additional options:

Replace With

This is where to enter the replacement string.

Selected Text

This option is disabled if no text is selected, or if the Prompt on Replace option is enabled. If checked, all matches of the search string within the selected text will be replaced with the replace string.

Prompt on Replace

If checked, a small dialogue will prompt you for what to do for each time a match is found. It offers the following options:

Yes

Activate this to replace the current match (which is selected in the editor).

No

Activate to skip the current match, and try to find another one.

All

Activate to cancel prompting, and just replace all matches.

Close

Activate this skip the current match and end the searching.

Note

There is currently no way to use minimal matching when searching for a regular expression. This will be added in a future version of Kate

Finding Text

To find text, launch the Find Text Dialogue with Ctrl+For from the Edit->Find... menu item,enter a search string, set the options as desired and hit Ok. If no matches is found between the starting point for the search (either the text cursor position or the beginning of the document) you will be prompted for permission to continue from the start (or end, if you are searching backwards) of the document.

If a match is found it is selected and the Find Text Dialogue is hidden, but stay tuned, finding further matches is very easy:

To find the next match in the search direction, use the Edit->Find Next command or press F3.

To find the next match in the opposite direction, use the Edit->Find Previous command or press Shift+F3.

If no match is found before reaching the document border, you will be prompted for permission to cross that.

Replacing Text

To replace text, launch the Replace text Dialogue using the Edit->Replace command, or the Ctrl+R shortcut, enter a search string and optionally a replace string (if the replace string is empty, each match will be replaced with ""), set the options as desired and hit the Ok button.

Tip

If you are using a regular expression to find the text to replace, you can employ backreferences to reuse text captured in parenthesised subpatterns of the expression.

See Appendix B, Regular Expressions for more on these.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Using Bookmarks
Using Bookmarks

Using Bookmarks

The bookmarks feature allows you to mark certain lines, to be able to easily find them again.

You can set or remove a bookmark in a line in two ways:

  • Moving the insertion cursor to that line, and activate the Bookmarks->Toggle Bookmark (Ctrl+B) command.

  • Clicking in the Icon Border next to that line.

Bookmarks are available in the Bookmarks menu. The individual bookmarks are available as menu items, labelled with the line number of the line with the bookmark, and the first few characters of the text in the line. To move the insertion cursor to the beginning of a bookmarked line, open the menu and select the bookmark.

Tip

If the Reopen Files option in the Config Dialogue is enabled (or if Kate was started by the session manager), your bookmarks will be restored when the document is reopened.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Automatically Wrapping text
Automatically Wrapping text

Automatically Wrapping text

This feature allows you to have the text formatted in a very simple way: the text will be wrapped, so that no lines exceed a maximum number of characters per line, unless there is a longer string of non-whitespace characters.

To enable/disable it, check/uncheck the Word Wrap checkbox in the edit page of the configuration dialogue.

To set the maximum line width (maximum characters per line), use the Wrap Words At option in the edit page of the configuration dialogue.

If enabled, it has the following effects:

  • While typing, the editor will automatically insert a hard line break after the last whitespace character at a position before the maximum line width is reached.

  • While loading a document, the editor will wrap the text in a similar way, so that no lines are longer than the maximum line width, if they contain any whitespace allowing that.

Note

There is currently no way to set word wrap for document types, or even to enable or disable the feature on document level. This will be fixed in a future version of Kate



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Chapter 5. Working with Plugins
Working with Plugins
Prev
Next

Chapter 5. Working with Plugins

Conversion to British English: Malcolm Hunter

This chapter will describe topics related to using plugins

Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Chapter 6. Advanced Editing Tools
Advanced Editing Tools
Prev
Next

Chapter 6. Advanced Editing Tools

Anders Lund

Conversion to British English: Malcolm Hunter

Comment/Uncomment

The Comment and Uncomment commands, available from the Tools menu allow you to add or remove comment markers to the selection, or the current line if no text is selected, it comments are supported by the format of the text you are editing.

The rules for how commenting is done are defined in the syntax definitions, so if syntax highlighting is not used, commenting/uncommenting is not possible.

Some formats define single line comment markers, some multi line markers and some both. If multi line markers are not available, commenting out a selection that does not fully include its last line is not possible.

If a single line marker is available, commenting single lines is preferred where applicable, as this helps to avoid problems with nested comments.

When removing comment markers, no uncommented text should be selected. When removing multiline comment markers from a selection, any whitespace outside the comment markers is ignored.

To place comment markers, use the Tools->Comment menu item or the related keyboard shortcut sequence, default is Ctrl+#.

To remove comment markers, use the Tools->Uncomment menu item or the related keyboard shortcut, default is Ctrl+Shift+#.

Editing Command
Editing Command

Editing Command

This tool, available from the Tools->Editing Command menu item, provides access to a small set of vi/vim-like commands for editing the text. It is a no nonsense tool for advanced or experienced users, but do not let that hold you back from experiencing its powers!

Currently, the following commands are available:

time

This command will output the current time as known by your computer in the format “HH:MM:SS

To use it, launch the Editing Command Dialogue and type into the input box the word time

char

This command allows you to insert literal characters by their numerical identifier, in decimal, octal or hexadecimal form. To use it launch the Editing Command dialogue and type char: [number] in the entry box, then hit OK.

Example 6.1. char examples

Input: char:234

Output: ê

Input: char:0x1234

Output: ê

Input: char:1232

Output: ê

s///[ig] %s///[ig]

This command does a sed-like search/replace operation on the current line, or on the whole file (%s///).

In short, the text is searched for text matching the search pattern, the regular expression between the first and the second slash, and when a match is found, the matching part of the text is replaced with the expression between the middle and last part of the string. Parentheses in the search pattern create back references, that is the command remembers which part of the match matched in the parentheses; these strings can be reused in the replace pattern, referred to as \1 for the first set of parentheses, \2 for the second and so on.

To search for a literal ( or ), you need to escape it using a backslash character: \(\)

If you put an i at the end of the expression, the matching will be case insensitive.

Example 6.2. Replacing text in the current line

Your friendly compiler just stopped, telling you that the class myClass mentioned in line 3902 in your source file is not defined.

"Buckle!" you think, it is of course MyClass. You go to line 3902, and instead of trying to find the word in the text, you launch the Editing Command Dialogue, enter s/myclass/MyClass/i, hit the OK button, save the file and compile – successfully without the error.

Example 6.3. Replacing text in the whole file

Imagine that you have a file, in which you mention a “Miss Jensen” several times, when someone comes in and tells you that she just got married to “Mr Jones”. You want, of course, to replace each and every occurrence of “Miss Jensen” with “Ms Jones”.

Launch the Editing Command dialogue, and type into the entry box: %s/Miss Jensen/Ms Jones/ and hit return, you are done.

Example 6.4. A More Advanced Example

This example makes use of back references as well as a word class (if you do not know what that is, please refer to the related documentation mentioned below).

Suppose you have the following line:

void MyClass::DoStringOps( String      &foo, String &bar String *p, int  &a, int &b )

Now you realise that this is not nice code, and decide that you want to use the const keyword for all “address of” arguments, those characterised by the & operator in front of the argument name. You would also like to simplify the white space, so that there is only 1 whitespace character between each word.

Launch the Editing Command Dialogue, and enter: s/\s+(\w+)\s+(&)/ const \1 \2/g and hit the OK button. The g at the end of the expression makes the regular expression recompile for each match to save the backreferences.

Output: void MyClass::DoStringOps( const String &foo, const String &bar String *p, const int &a, const int &b )

Mission completed! Now, what happened? Well, we looked for some white space (\s+) followed by one or more alphabetic characters (\w+) followed by some more whitespace (\s+) followed by an ampersand, and in the process saved the alphabetic chunk and the ampersand for reuse in the replace operation. Then we replaced the matching part of our line with one whitespace followed by “const” followed by one whitespace followed by our saved alphabetical chunk (\1) followed by one whitespace followed by our saved ampersand (\2)

Now in some cases the alphabetical chunk was “String”, in some “int”, so using the character class \w and the + quantifier proved a valuable asset.

Warning

This is extremely powerful, and though the actions can be undone by calling the Undo command several times (as required) I recommend you practise a bit before using this command for serious editing if you are not familiar with sed or perl regular expressions.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Chapter 7. Menu Entries
Menu Entries
Prev
Next

Chapter 7. Menu Entries

Conversion to British English: Malcolm Hunter

The File Menu

File->New (Ctrl+N)

This command starts a new document in the editing window. In the Filelist on the left the new file is named Untitled.

File->Open (Ctrl+O)

This command does not open a file. It launches KDE's open file dialogue box which waits for you to select the files you want to open.

The open file dialogue box works like a simple version of Konqueror. Use your left mouse button to click on a file name to select it. Double-click on a file name to open that file. Once you've selected a file name, you can also press the OK button to open the file.

Tip

Select multiple files by holding down the Ctrl or the Shift key along with the left mouse button. Ctrl+Left click selects one file at a time. Shift+Left click selects a contiguous set of files.

Clicking on a folder name in the file selection window opens that folder and displays its contents. Clicking on a file name shows a thumbnail view of the file in the preview window to the right of the file system window.

Use the buttons and combo box on the toolbar above the file selection window to move through the file system or to adjust the properties of the open file dialogue box.

Below the file selection window is the Location combo box. Type the name of the file you want to edit here. If you click the arrow on the right of the drop down box, you can choose from recently used files. Open several files at once by quoting each file name.

Below the Location combo box is the Filter combo box. Enter file masks here to filter the kinds of files shown in the selection window. For example, typing the filter *.txt and pressing Enter will limit the display to files with a .txt extension. The Filter combo contains a list of your most recently used filters.

File->Open Recent

This command allows you to open a file from a submenu that contains a list of recently edited files.

File->Save (Ctrl+S)

This command saves your file. Use it often. If the file is Untitled then Save becomes Save As.

File->Save As

Name and rename files with this command. It launches the save file dialogue box. This dialogue works just as the open file dialogue box does. You can use it to navigate through your file system, preview existing files, or filter your file view with file masks.

Type the name you want to give the file you are saving in the Location combo box and press the OK button.

File->Save All (Ctrl+L)

This command saves all open files.

File->Reload (F5)

Reloads the active file from disk. This command is useful if another program or process has changed the file while you have it open in Kate

File->Open with

This command launches the open with dialogue box that allows you to select another application to open the active file. Your file will still be open in Kate.

File->Print (Ctrl+P)

Print the active file.

File->Close (Ctrl+W)

Close the active file with this command. If you have made unsaved changes, you will be prompted to save the file before Kate closes it.

File->Close All

This command closes all the files you have open in Kate.

File->New Window

Opens another instance of Kate. The new instance will be identical to your previous instance.

File->Quit (Ctrl+Q)

This command closes Kate and any files you were editing. If you have made unsaved changes to any of the files you were editing, you will be prompted to save them.

The Edit Menu
The Edit Menu

The Edit Menu

The Edit menu contains a host of commands, all to work with the currently active document.

Menu Entries

Edit->Undo (Ctrl+Z)

Undo the last editing command (typing, copying, cutting etc.)

Note

If grouped undo is enabled, this may undo several editing commands of the same type, like typing in characters.

Edit->Redo (Ctrl+Shift+Z)

Redo the last undo step.

Edit->Cut (Ctrl+X)

Removes selected text if any, and places a copy of the removed text in the clipboard.

Edit->Copy (Ctrl+C)

Copies selected text, if any, to the clipboard.

Edit->Paste (Ctrl+V)

Copies the first item in the clipboard into the editor at cursor position.

Note

If Overwrite Selection is enabled, the pasted text will overwrite the selection, if any.

Edit->Select All (Ctrl+A)

Selects all text in the editor.

Edit->Deselect (Ctrl+Shift+A)

Deselects the selected text in the editor if any.

Edit->Toggle Block Selection (F4)

Toggles Selection Mode. When the Selection Mode is “BLOCK”, you can make vertical selections, ie select column 5 to 10 in lines 9 to 15.

The status bar shows the current state of the Selection Mode, either “NORM” or “BLK”.

Edit->Find (Ctrl+F)

Launch the Find Dialogue to allow you to search for text in the edited document.

Edit->Find Next (F3)

Go to the nearest downwards match of the last text or regular expression searched for, starting from cursor position

Edit->Find Previous (Shift+F3)

Go to the nearest upwards match of the last text or regular expression searched for, starting from cursor position

Edit->Replace (Ctrl+R)

Launch the Replace Dialogue to replace one or more instances of a defined text with something else.

Edit->Indent (Ctrl+I)

Adds one indent step to the current line, or all lines covered by a possible selection.

The indentation depends on the settings in the Indent Page of the Configuration Dialogue.

Edit->Unindent (Ctrl+Shift+I)

Removes one indent step from the current line, or all lines covered by a possible selection.

The indentation depends on the settings in the Indent Page of the Configuration Dialogue.

Edit->Comment (Ctrl+#)

Enclose or prepend the current line, or any selected text, with (a) comment marker(s), according to the rules defined by the syntax rules for the document. Does nothing if no comment rules are defined.

This is interesting mostly when working with source code, for example with C/C++, perl, python etc., as well as with markup text like HTML, XML, CSS and so on.

Edit-> (Ctrl+Shift+#)

Remove comment marker(s) from the current line, or a possible selection, according to the syntax rules for the document.

See also EditComment

Edit->Go to line... (Ctrl+G)

Launches the Go To Line Dialogue, allowing you to enter the number of a line to find in the document



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

The DocumentMenu
The DocumentMenu

The DocumentMenu

The Document menu has two purposes:

  • Allowing you to change the document-specific settings for the currently active document.

  • Choosing which of the open documents to work on

A menu entry for each open document will be available below the entries documented here. Clicking one of these will bring the requested document to focus. If you have multiple frames, an editor for that document will be displayed in the currently active frame.

Menu items

Document->Back (Alt+Left)

This will bring the previous document in the stack in focus. If you have multiple frames, an editor for the document will be displayed in the currently active frame.

The order is the order in which documents were opened, rather than a logical history. This behaviour may change in future versions of Kate.

Document->Forward (Alt+Right)

This will bring the previous document in the stack in focus. If you have multiple frames, an editor for the document will be displayed in the currently active frame.

The order is the order in which the documents were opened, rather than a logical history. This behaviour may change in future versions of Kate.

Document->Highlight Mode

The Highlight Mode menu allows you to manually decide which syntax rules to use for highlighting and comment'ing the active document. The menu groups the available syntax rule sets into logical groups.

Document->End of Line

This menu allows you to manually set the End of Line mode for the active document. Changing the mode will replace all line separators in the document with the character sequence for the new mode.

The available modes are:

Unix

On UNIX® systems, end of line is a single newline character.

DOS

On DOS (and Windows®) systems, end of line is represented by a carriage return followed by a newline.

Mac

On Mac® systems, end of line is represented by a by a carriage return.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

The View menu
The View menu

The View menu

The View menu allows you to manage settings specific to the active editor, and to manage frames.

Menu Items

View->Split Vertical (Ctrl+Shift+L)

This will split the frame (which may be the main editing area) in two equally sized frames, the new one to the left of the current one. The new frame gets the focus, and will display the same document as the old one.

See also Working with the Kate MDI

View->Split Horizontal (Ctrl+Shift+T)

Splits the current frame (which may be the main editing area) in two equally sized frames, the new one at the bottom half. The new frame gets the focus, and displays the same document as the old one.

See also Working with the Kate MDI

View->Close Current (Ctrl+Shift+R)

Closes the active frame. This is disabled, if there is only one frame (the main editing area).

No documents get closed by closing a frame – they will still be available in the Documents Menu as well as in the File List.

See also Working with the Kate MDI

View->Show Icon Border (F6)

This is a toggle item. Setting it on checked will make the side of the active editor, and vice versa.

View->Show Line Numbers (F11)

This is a toggle Item. Setting it on checked will make a pane displaying the line numbers of the document visible in the left border of the active editor, and vice versa.

View->Go
Next View (F8)

Move focus to the next frame; the order is following order of creation rather than that of visual logic. This behaviour may change in a future version of Kate

See also Working with the Kate MDI

Previous View (Shift+F8)

Move focus to the previous frame; the order is following order of creation rather than that of visual logic. This behaviour may change in a future version of Kate

See also Working with the Kate MDI



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

The Bookmarks Menu
The Bookmarks Menu

The Bookmarks Menu

The Bookmarks menu allows you to work with the bookmarks in the currently active document.

Below the entries described here, one entry for each bookmark in the active document will be available. The text will be the first few words of the marked line. Choose an item to move the cursor to the start of that line. The editor will scroll as necessary to make that line visible.

Menu Items

Bookmarks->Toggle Bookmark (Ctrl+B)

Sets or removes a bookmark in the current line of the active document. (If it's there, it is removed, otherwise one is set.)

Bookmarks->Clear Bookmarks

Clears (removes) all bookmarks of the active document.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

The Tools Menu
The Tools Menu

The Tools Menu

The Tools menu contains commands of two categories:

  • Tools doing advanced editing of the current document, for example Editing Command.

  • Tools adding functionality to the application, for example the Find in Files tool.

Edit->Editing Command... (Ctrl+M)

Launch the Editing Command Dialogue

Edit->Find in Files... (Ctrl+Shift+F)

Launch the Find In Files Dialogue to search for a specified text in files on disk.

Edit->Apply Word Wrap

Apply word wrap to ? according to the settings in the ?

Edit->Spelling...

Spell check the current document using the KDE spell checker



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

The Settings Menu
The Settings Menu

The Settings Menu

The Settings menu allows you to change the properties of the main window, such as showing/hiding toolbars and boxes, and provides access to the configuration dialogues.

Settings->Show Toolbar

Toggles the display of the main toolbar.

Settings->Show Filelist

Toggle the display of the Kate Filelist

Settings->Show Fileselector

Toggle the display of the Kate File Selector

Settings->Show Konsole (F7)

Toggles the display of the built in terminal emulator.

When activated the first time, the terminal will be created.

When the terminal emulator is displayed, it will get the focus, so that you can start typing in commands immediately. If the Sync Konsole with Active Document option is enabled in the General Page of the Main configuration dialogue the shell session will change to the directory of the active document, if it is a local file.

Settings->Configure Shortcuts

Display the the familiar KDE Keyboard Shortcut Configuration Dialogue.

Settings->Configure Toolbars

Display the the familiar KDE Toolbar Configuration Dialogue.

Settings->Configure Kate

Launch the Main Configuration Dialogue



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

The Help Menu
The Help Menu

The Help Menu

The Help menu provides access to the online help available for Kate; as well as to the usual about dialogues.

As well as the standard KDE Help menu items described below, if you have installed the kdeaddons package with additional Kate plugins, you will have a menu entry to show the Plugins User Manuals.

Help->Contents... (F1)

Invokes the KDE Help system starting at the Kate help pages. (this document).

Help->What's This? (Shift+F1)

Changes the mouse cursor to a combination arrow and question mark. Clicking on items within Kate will open a help window (if one exists for the particular item) explaining the item's function.

Help->Report Bug...

Opens the Bug report dialogue where you can report a bug or request a “wishlist” feature.

Help->About Kate

This will display version and author information.

Help->About KDE

This displays the KDE version and other basic information.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Chapter 8. Configuring Kate
Configuring Kate
Prev
Next

Chapter 8. Configuring Kate

Conversion to British English: Malcolm Hunter

Overview

Kate offers several means of tweaking the application to behave as desired. The most important ones are:

The Configuration Dialogue

The main configuration tool, allowing you to configure the Kate application, the editor component and the usage of plugins.

The Settings Menu

Allows you to change often used settings, and to launch the configuration dialogues.

The View Menu

Allows you to split the current frame, as well as to display the icons and line numbers pane for the currently edited document.

The embedded Konsole is using the configuration defined in the KDE Control Centre, and may be configured by clicking the right mouse button and choosing from the Settings sub menu.

The Main Configuration Dialogue
The Main Configuration Dialogue

The Main Configuration Dialogue



The Kate configuration dialogue displays a tree of topics on the left, and a configuration page corresponding to the selected topic on the right. The tree groups the pages of the dialogue into logical groups.

The Kate group

This group contains pages to configure the main Kate application

The General Page

Global Options for Kate

Application Mode

This group lets you choose between Kate MDI and Kate SDI mode, selecting the appropriate button.

Kate MDI (Multiple Document Interface), which is the default mode, makes Kate use a single window for all open files. You can choose the document to edit from the File List (docked into the Kate window by default) or by selecting the document from the Document menu.

Kate SDI (Single Document Interface) will make Kate open each document in a window of its own, and the File List/File Selector will have a separate window.

If you change this setting, you will need to restart Kate for it to take effect.

At Startup

These options determine how and if Kate will restore your editing session when launched after a normal shutdown (if restored by the session manager, Kate will always attempt to restore your session as close as possible to what it was when you last used Kate).

Reopen Files

If this option is enabled, files open when you last closed Kate will be reopened. Bookmarks will be restored, and the cursor position, icon border and line numbers settings for the last editor used with the document will be re-established

Restore View Configuration

If this option is enabled, Kate will attempt to restore your frames exactly as you left them.

Restrict to single instance

Enabling this means you can only have one running instance of Kate running at any given time. If you attempt to start another one, the current instance will take over and also open files as requested. For example, if you use Kate for displaying sources for web pages in Konqueror, they will all be opened in an existing instance of Kate if this option is enabled.

Show Contents While Resizing Frames

If this option is enabled, the windows will be fully repainted while dragging the frame splitters. If unchecked, a so-called “rubber band” (indicating the new size of the frame) will be used instead.

Sync Konsole with Active Document

This will cause the built-in Konsole to cd into the directory of the active document when launched and when a new document gets the focus. If not enabled, you have to do all your navigation in the Konsole on your own.

Number of Recent Files

Unsurprisingly, this allows you to decide how long the Open Recent files menu should grow.

The Editor Group

This group contains all pages related to the editor component of Kate

The Colours Page

This page allows you to change the background and selection background colours of the editor. Initially, Kate will use the colours as set in the KDE Control Centre Look'n'Feel->Colours page.

To change a colour, press the associated button and select the desired colour in the colour chooser.

Note

Choosing the background colour may render Syntax Highlighted text unreadable. You should use a light colour for the background, and a dark colour for the selection background.

Otherwise, you will probably need to change the Default Styles.

The Fonts Page

This page allows you to choose the default fonts for Kate. The settings will be used for the KWrite and for viewing text files in Konqueror as well.

The page presents two tabs, one for the editor font and one for the printing font. Select a tab and choose the desired font. The default is to use the KDE global setting for fixed font.

Tip

As it is not currently possible to use individual fonts for documents, nor to change the font for printing from the print dialogue, be careful. A fixed-width font is strongly recommended.

The Indent Page

This page allows you to change the behaviour of indentation.

Indent Options

Auto indent

If checked, Kate will automatically indent new lines equal to the previous line. If the previous line is blank, the nearest above line with contents is used.

Indent with Spaces

If checked, Kate will indent with spaces rather than tabs.

Backspace key indents

If this is checked, Kate will unindent equal to the nearest above line with contents when you press the Backspace key if the part of the line preceding the cursor contains only whitespace.

Tab key indents

If this is checked, Kate will indent the current line equal to the nearest above line with content when you press the Tab key, if the part of the line preceding the cursor contains only whitespace.

Keep extra spaces

With this behaviour checked, Kate will leave whitespace behind the cursor after indenting.

The Select Page

This page provides options for fine tuning the select behaviour of Kate

Select Options

Persistent Selections

When Persistent Selections is enabled, key input will not cause the selection to be removed/diminished.

Note

This option partly conflicts with the Overwrite Selection option. If both are enabled, pasting text or pressing any other keys than the arrow keys will cause the selection to be overwritten.

Overwrite Selection

If this is enabled, any text insertion, whether typed or pasted will cause the selected text to be deleted and replaced with the inserted text.

The Edit Page

This page contains miscellaneous options for fine-tuning the behaviour of the Kate editor component.

Editor Options

Word Wrap

Word Wrap as used here means dynamically format the text by breaking lines at an appropriate place, rather than soft wrapping lines in the editor for easier reading.

If enabled, Kate will insert a line break as defined by the End of Line setting for the document when the line extends the length set in Wrap Words At option described below.

Wrap Words At

This option decides the max length of lines if the Word Wrap option is enabled.

Replace Tabs with Spaces

If enabled, Kate will replace inserted Tab characters with a number of single whitespace characters as defined in Tab Width.

Remove trailing spaces

If enabled, Kate will remove any whitespace at the rear end of a line each time the cursor is moved off that line.

Tab/Indent Width

Sets the tab width, which is also used to decide the amount of indentation when Auto Indent is enabled, or indentation is otherwise called for.

Depending on the Indent settings indentation may be caused by pressing the Tab and Backspace keys, and activating the Edit Indent menu entry will call for indent as well.

Auto Brackets

If this is enabled, Kate will automatically insert a right bracket immediately to the right of the cursor when a left bracket is inserted from the keyboard. The supported bracket types are (, {, [and <

Group undos

If enabled, Kate will group any number of similar editing actions (for example typing, backspacing, pasting) in one entry in the undo history, so they can all be undone at once.

Show Tabs

If enabled, Kate will draw a small dot at the start of a Tab character in the editor to indicate its presence.

Smart Home

This will make Kate move the cursor to the first non-whitespace character of the current line rather than to the absolute beginning, when the Home key (or other key assigned to that function) is pressed.

Wrap Cursor

If enabled, moving the cursor past the end of a line will cause it to continue to the next/previous line if any.

If not enabled, the cursor cannot be moved right of the beginning of the line, but it may be moved past the end of line, and when text is inserted Kate will automatically insert whitespace up to that position. This is sometimes very handy for programmers, for example.

The Keyboard Page

Here you can configure the keyboard shortcuts for the internal commands of the Kate editor component. These includes commands for moving around in the document and selecting text. For keys related to copying and pasting text, see The Configure Keys Dialogue

You may change the keys for a command, or add an alternate key.

Procedure 8.1. To change the key(s) for a command, follow this procedure:

  1. Select the command for which you want to configure the keys.

  2. Choose the None option in the pane below the list if you don't want a key for this command.

    Choose the Default option to use the default key(s) for the command

    Choose the Custom option to select a custom key for the command, or set an alternate one.

  3. If you choose the Custom option, the key entering button at the right of the pane will be enabled. To set a key, press it. The KDE Define Shortcut Dialogue will appear. In this dialogue:

    1. Choose whether to set the default or alternate key. Default does not mean that you change the application default for this action, rather it sets the custom standard key for it.

    2. Press the desired key sequence, it will be visualised for you in the dialogue for your confirmation.

      If you are of an adventurous nature, try playing around with the Multikey option. Using it will allow you to have Emacs-like key sequences (one key enters a group, the next performs the action), apart from the fact that instead of just doing the job, KDE will pop up a menu to choose from in an undefined and most likely inappropriate place. You will now be in no doubt as to whether pressing the next key in the sequence will work, or you have to type the menu accelerator (both will work).

The Spelling Page

This page allows you to configure how KSpell behaves with Kate

The Highlighting Page

This page allows you to fine tune the colour and syntax type selection of Kate



For more in depth information on the syntax highlighting system, see ??

The page consists of two tabs, one for setting the Default styles and one for managing the Highlight Modes. Both tabs display a list of contexts in which the default colours and font are used to visualise the look of each style. The context name is painted using the current properties of the context.

The list has four or five columns, each with the following purpose:

Context

Displays the context name, painted using the style properties for the context.

Bold

The state of this checkbox decides if the context should be rendered using a boldface font.

Italic

The state of this checkbox decides if the context should be rendered using italic font.

Normal

This button displays the colour for drawing the style in normal mode, when the text is not selected that is. To change the colour, click the button.

Selected

This button displays the colour for drawing the style when the text is selected. To change the colour, click the button.

Using Default

This checkbox, only available in the Highlight Modes tab shows if the style is using its default values. It will automatically become unchecked if you change any properties of the style. Check it to reset a style to using defaults.

The Default Styles Tab

To change any of the default styles, set its properties as desired.

The Highlight Modes Tab

Here you can change the most important properties of each available highlight mode. First, use the Highlight dropdown to choose a mode to work on.

Highlight modes are initially chosen based on the MIME type and extension of the file. To change the list for the current selection, edit the File Extensions and Mime Types entries. Alternatively, press the wizard button to the right of the Mime Types entry. This will show a dialogue displaying all available MIME types to choose from. Using it will edit the MIME types as well as the file extensions.



The MIME type chooser dialogue displays a tree of available MIME types, with a description and the patterns for the MIME type. To include a MIME type, check the box beside it.

You can change the style properties of any context as described above.

At the bottom of the tab, below the highlight properties, you see a button labelled Download. Pressing it will attempt to connect to the Kate website and fetch a list of available syntax highlight modes which you can update or add.

The Plugins Group

This group contains pages related to plugins. Apart from the Manager configuration page, some plugins provide individual configuration options. For information on these, see the documentation for the individual plugins.

The Plugin Manager Page

This page provides the means of loading/unloading plugins, and minimal information about individual plugins.

To load an unloaded plugin, select it in the Available Plugins pane and use the arrow buttons to move it to the Loaded Plugins pane.

To unload a loaded plugin, select it in the Loaded Plugins pane and use the arrow buttons to move it to the Available buttons pane.

To view a minimal description and information about a plugin, select it and the information will be available below the lists.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Chapter 9. Credits and Licence
Credits and Licence
Prev
Next

Chapter 9. Credits and Licence

Kate. Program copyright 2000, 2001, 2002 by the Kate developer team.

The Kate team:

Christoph Cullmann

Project Manager & Core Developer

Anders Lund

Core Developer, Perl syntax highlighting, documentation

Joseph Wenninger

Core Developer, syntax highlighting

Michael Bartl

Core Developer

Phlip

The project compiler

Waldo Bastian

The cool buffer system

Matt Newell

Testing...

Michael McCallum

Core Developer

Jochen Wilhemly

KWrite Author

Michael Koch

KWrite port to KParts

Christian Gebauer

Unspecified

Simon Hausmann

Unspecified

Glen Parker

KWrite Undo History, KSpell integration

Scott Manson

KWrite XML syntax highlighting support

John Firebaugh

Various Patches

Many other people have contributed:

Matteo Merli

Highlighting for RPM Spec-Files, Diff and more

Rocky Scaletta

Highlighting for VHDL

Yury Lebedev

Highlighting for SQL

Chris Ross

Highlighting for Ferite

Nick Roux

Highlighting for ILERPG

John Firebaugh

Highlighting for Java, and much more

Carsten Niehaus

Highlighting for LaTeX

Per Wigren

Highlighting for Makefiles, Python

Jan Fritz

Highlighting for Python

Daniel Naber

Small bugfixes, XML plugin

Documentation copyright 2000,2001 Seth Rothberg

Documentation copyright 2002, 2003 Anders Lund

Conversion to British English: John Knight

This documentation is licensed under the terms of the GNU Free Documentation License.

This program is licensed under the terms of the GNU General Public License.

Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Appendix A. Working with Syntax Highlighting
Working with Syntax Highlighting
Prev
Next

Appendix A. Working with Syntax Highlighting

Conversion to British English: Malcolm Hunter

Overview

Syntax Highlighting is what makes the editor automatically display text in different styles/colours, depending on the function of the string in relation to the purpose of the file. In program source code for example, control statements may be rendered bold, while data types and comments get different colours from the rest of the text. This greatly enhances the readability of the text, and thus helps the author to be more efficient and productive.


A perl function, rendered with syntax highlighting.

A perl function, rendered with syntax highlighting.



The same perl function, without highlighting.

The same perl function, without highlighting.


Of the two examples, which is easiest to read?

Kate comes with a flexible, configurable and capable system for doing syntax highlighting, and the standard distribution provides definitions for a wide range of programming languages, markup and scripting languages and other text file formats. In addition you can provide your own definitions in simple XML files.

Kate will automatically detect the right syntax rules when you open a file, based on the MIME Type of the file, determined by its extension, or, if it has none, the contents. Should you experience a bad choice, you can manually set the syntax to use from the Documents->Highlight Mode menu.

The styles and colours used by each syntax highlight definition, as well as which MIMEtypes it should be used for, can be configured using the Highlight page of the Config Dialogue.

Note

Syntax highlighting is there to enhance the readability of correct text, but you cannot trust it to validate your text. Marking text for syntax is difficult depending on the format you are using, and in some cases the authors of the syntax rules will be proud if 98% of text gets correctly rendered, though most often you need a rare style to see the incorrect 2%.

Tip

You can download updated or additional syntax highlight definitions from the Kate website by clicking the Download button in the Highlight Page of the Config Dialogue.

The Kate Syntax Highlight System
The Kate Syntax Highlight System

The Kate Syntax Highlight System

This section will discuss the Kate syntax highlighting mechanism in more detail. It is for you if you want to know know about it, or if you want to change or create syntax definitions.

How it Works

Whenever you open a file, one of the first things the Kate editor does is detect which syntax definition to use for the file. While reading the text of the file, and while you type away in it, the syntax highlighting system will analyse the text using the rules defined by the syntax definition and mark in it where different contexts and styles begin and end.

When you type in the document, the new text is analysed and marked on the fly, so that if you delete a character that is marked as the beginning or end of a context, the style of surrounding text changes accordingly.

The syntax definitions used by the Kate syntax highlighting system are XML files, containing

  • Rules for detecting the role of text, organised into context blocks

  • Keyword lists

  • Style Item definitions

When analysing the text, the detection rules are evaluated in the order in which they are defined, and if the beginning of the current string matches a rule, the related context is used. The start point in the text is moved to the final point at which that rule matched and a new loop of the rules begins, starting in the context set by the matched rule.

Rules

The detection rules are the heart of the highlighting detection system. A rule is a string, character or regular expression against which to match the text being analysed. It contains information about which style to use for the matching part of the text. It may switch the working context of the system either to an explicitly mentioned context or to the previous context used by the text.

Rules are organised in context groups. A context group is used for main text concepts within the format, for example quoted text strings or comment blocks in program source code. This ensures that the highlighting system does not need to loop through all rules when it is not necessary, and that some character sequences in the text can be treated differently depending on the current context.

Context Styles and Keywords

In some programming languages, integer numbers are treated differently than floating point ones by the compiler (the program that converts the source code to a binary executable), and there may be characters having a special meaning within a quoted string. In such cases, it makes sense to render them differently from the surroundings so that they are easy to identify while reading the text. So even if they do not represent special contexts, they may be seen as such by the syntax highlighting system, so that they can be marked for different rendering.

A syntax definition may contain as many styles as required to cover the concepts of the format it is used for.

In many formats, there are lists of words that represent a specific concept. For example in programming languages, the control statements is one concept, data type names another, and built in functions of the language a third. The Kate Syntax Highlighting System can use such lists to detect and mark words in the text to emphasise concepts of the text formats.

Default Styles

If you open a C++ source file, a Java™ source file and an HTML document in Kate, you will see that even though the formats are different, and thus different words are chosen for special treatment, the colours used are the same. This is because Kate has a predefined list of Default Styles, that are employed by the individual syntax definitions.

This makes it easy to recognise similar concepts in different text formats. For example comments are present in almost any programming, scripting or markup language, and when they are rendered using the same style in all languages, you do not have to stop and think to identify them within the text.

Tip

All styles in a syntax definition use one of the default styles. A few syntax definitions use more styles that there are defaults, so if you use a format often, it may be worth launching the configuration dialogue to see if some concepts are using the same style. For example there is only one default style for strings, but as the perl programming language operates with two types of strings, you can enhance the highlighting by configuring those to be slightly different.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

The Highlight Definition XML Format
The Highlight Definition XML Format

The Highlight Definition XML Format

Overview

This section is an overview of the Highlight Definition XML format. It will describe the main components and their meaning and usage, and go into detail with the detection rules.

The formal definition, aka the DTD is stored in the file language.dtd which should be installed on your system in the folder $KDEDIR/share/apps/kate/syntax.

Main components of Kate Highlight Definitions

The General Section

The General Section contains information on the comment format of the described language, and defines whether keywords are case sensitive.

Highlighting

The Highlighting section contains all data required to analyse and render the text. This includes:

ItemDatas

Contains ItemData elements, each defining a style.

Keyword lists

Each list has a name, and may contain any number of items.

Contexts

Contains contexts, which again contain the syntax detection rules.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Highlight Detection Rules
Highlight Detection Rules

Highlight Detection Rules

This section describes the syntax detection rules.

Each rule can match zero or more characters at the beginning of the string they are asked to test. If the rule matches, the matching characters are assigned the style or attribute defined by the rule, and a rule may ask that the current context is switched.

The attribute and context attributes are common to all rules.

A rule looks like this:

<RuleName attribute="(identifier)" context="(identifier|order)" [rule specific attributes] />

The attribute identifies the style to use for matched characters by name or index, and the context identifies the context to use from here.

The attribute can be identified either by name, or by its zero-based index in the ItemDatas group.

The context can be identified by:

  • An identifier, currently only its zero-based index in the contexts group.

  • An order telling the engine to stay in the current context (#stay), or to pop back to a previous context used in the string (#pop).

    To go back more steps, the #pop keyword can be repeated: #pop#pop#pop

Some rules can have child rules which are then evaluated if and only if the parent rule matched. The entire matched string will be given the attribute defined by the parent rule. A rule with child rules looks like this:

<RuleName (attributes)>
  <ChildRuleName (attributes) />
  ...
</RuleName>

Rule specific attributes varies and are described in the following list.

The Rules in Detail

DetectChar

Detect a single specific character. Commonly used for example to find the ends of quoted strings.

<DetectChar char="(character)" (common attributes) />

The char attribute defines the character to match.

Detect2Chars

Detect two specific characters in a defined order.

<Detect2Chars char="(character)" char1="(character)" (common attributes) />

The char attribute defines the first character to match, char1 the second.

AnyChar

Detect one character of a set of specified characters.

<AnyChar String="(string)" (common attributes) />

The String attribute defines the set of characters.

StringDetect

Detect an exact string.

<StringDetect String="(string)" [insensitive="TRUE|FALSE;"] (common attributes) />

The String attribute defines the string to match. The insensitive attribute defaults to FALSE and is fed to the string comparison function. If the value is TRUE insensitive comparing is used.

RegExpr

Matches against a regular expression.

<RegExpr String="(string)" [insensitive="TRUE|FALSE;"] [minimal="TRUE|FALSE"] (common attributes) />

The String attribute defines the regular expression.

insensitive defaults to FALSE and is fed to the regular expression engine.

minimal defaults to FALSE and is fed to the regular expression engine.

Because the rules are always matched against the beginning of the current string, a regular expression starting with a caret (^) indicates that the rule should only be matched against the start of a line.

See Regular Expressions for more information on those.

Keyword

Detect a keyword from a specified list.

<keyword String="(list name)" (common attributes) />

The String attribute identifies the keyword list by name. A list with that name must exist.

Int

Detect an integer number.

<Int (common attributes) />

This rule has no specific attributes. Child rules are typically used to detect combinations of L and U after the number, indicating the integer type in program code.

Float

Detect a floating point number.

<Float (common attributes)
/>

This rule has no specific attributes.

HlCOct

Detect an octal point number representation.

<HlCOct (common attributes) />

This rule has no specific attributes.

HlCHex

Detect a hexadecimal number representation.

<Int (common attributes) />

This rule has no specific attributes.

HlCStringChar

Detect an escaped character.

<HlCStringChar (common attributes)
/>

This rule has no specific attributes.

It matches letteral representations of invisible characters commonly used in program code, for example \n (newline) or \t (TAB).

The following characters will match if they follow a backslash (\): abefnrtv"'?. Additionally, escaped hexadecimal numbers like for example \xff and escaped octal numbers, for example \033 will match.

RangeDetect

Detect a string with defined start and end characters.

<RangeDetect char="(character)"  char1="(character)" (common attributes) />

char defines the character starting the range, char2 the character ending the range.

Useful to detect for example small quoted strings and the like, but note that since the hl engine works on one line at a time, this will not find strings spanning over a line break.

LineContinue

Matches at end of line.

<LineContinue (common attributes) />

This rule has no specific attributes.

This rule is useful for switching context at end of line.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Appendix B. Regular Expressions
Regular Expressions
Prev
Next

Appendix B. Regular Expressions

Anders Lund

Conversion to British English: Malcolm Hunter
This Appendix contains a brief but hopefully sufficient and
covering introduction to the world of regular
expressions. It documents regular expressions in the form
available within Kate, which is not compatible with the regular
expressions of perl, nor with those of for example
grep.

Introduction

Regular Expressions provides us with a way to describe some possible contents of a text string in a way understood by a small piece of software, so that it can investigate if a text matches, and also in the case of advanced applications with the means of saving pieces or the matching text.

An example: Say you want to search a text for paragraphs that starts with either of the names “Henrik” or “Pernille” followed by some form of the verb “say”.

With a normal search, you would start out searching for the first name, “Henrik” maybe followed by “sa” like this: Henrik sa, and while looking for matches, you would have to discard those not being the beginning of a paragraph, as well as those in which the word starting with the letters “sa” was not either “says”, “said” or so. And then of cause repeat all of that with the next name...

With Regular Expressions, that task could be accomplished with a single search, and with a larger degree of preciseness.

To achieve this, Regular Expressions defines rules for expressing in details a generalisation of a string to match. Our example, which we might literally express like this: “A line starting with either ‘Henrik’ or ‘Pernille’ (possibly following up to 4 blanks or tab characters) followed by a whitespace followed by ‘sa’ and then either ‘ys’ or ‘id” could be expressed with the following regular expression:

^[ \t]{0,4}(Henrik|Pernille) sa(ys|id)

The above example demonstrates all four major concepts of modern Regular Expressions, namely:

  • Patterns

  • Assertions

  • Quantifiers

  • Back references

The caret (^) starting the expression is an assertion, being true only if the following matching string is at the start of a line.

The stings [ \t] and (Henrik|Pernille) sa(ys|id) are patterns. The first one is a character class that matches either a blank or a (horizontal) tab character; the other pattern contains first a subpattern matching either Henrik or Pernille, then a piece matching the exact string sa and finally a subpattern matching either ys or id

The string {0,4} is a quantifier saying “anywhere from 0 up to 4 of the previous”.

Because regular expression software supporting the concept of back references saves the entire matching part of the string as well as sub-patterns enclosed in parentheses, given some means of access to those references, we could get our hands on either the whole match (when searching a text document in an editor with a regular expression, that is often marked as selected) or either the name found, or the last part of the verb.

All together, the expression will match where we wanted it to, and only there.

The following sections will describe in details how to construct and use patterns, character classes, assertions, quantifiers and back references, and the final section will give a few useful examples.

Patterns
Patterns

Patterns

Patterns consists of literal strings and character classes. Patterns may contain sub-patterns, which are patterns enclosed in parentheses.

Escaping characters

In patterns as well as in character classes, some characters have a special meaning. To literally match any of those characters, they must be marked or escaped to let the regular expression software know that it should interpret such characters in their literal meaning.

This is done by prepending the character with a backslash (\).

The regular expression software will silently ignore escaping a character that does not have any special meaning in the context, so escaping for example a “j” (\j) is safe. If you are in doubt whether a character could have a special meaning, you can therefore escape it safely.

Escaping of cause includes the backslash character it self, to literally match a such, you would write \\.

Character Classes and abbreviations

A character class is an expression that matches one of a defined set of characters. In Regular Expressions, character classes are defined by putting the legal characters for the class in square brackets, [], or by using one of the abbreviated classes described below.

Simple character classes just contains one or more literal characters, for example [abc] (matching either of the letters “a”, “b” or “c”) or [0123456789] (matching any digit).

Because letters and digits have a logical order, you can abbreviate those by specifying ranges of them: [a-c] is equal to [abc] and [0-9] is equal to [0123456789]. Combining these constructs, for example [a-fynot1-38] is completely legal (the last one would match, of cause, either of “a”,“b”,“c”,“d”, “e”,“f”,“y”,“n”,“o”,“t”, “1”,“2”,“3” or “8”).

As capital letters are different characters from their non-capital equivalents, to create a caseless character class matching “a” or “b”, in any case, you need to write it [aAbB].

It is of cause possible to create a “negative” class matching as “anything but” To do so put a caret (^) at the beginning of the class:

[^abc] will match any character buta”, “b” or “c”.

In addition to literal characters, some abbreviations are defined, making life still a bit easier:

\a

This matches the ASCII bell character (BEL, 0x07).

\f

This matches the ASCII form feed character (FF, 0x0C).

\n

This matches the ASCII line feed character (LF, 0x0A, Unix newline).

\r

This matches the ASCII carriage return character (CR, 0x0D).

\t

This matches the ASCII horizontal tab character (HT, 0x09).

\v

This matches the ASCII vertical tab character (VT, 0x0B).

\xhhhh

This matches the Unicode character corresponding to the hexadecimal number hhhh (between 0x0000 and 0xFFFF). \0ooo (i.e., \zero ooo) matches the ASCII/Latin-1 character corresponding to the octal number ooo (between 0 and 0377).

. (dot)

This matches any character (including newline).

\d

This matches a digit. Equal to [0-9]

\D

This matches a non-digit. Equal to [^0-9] or [^\d]

\s

This matches a whitespace character. Practically equal to [ \t\n\r]

\S

This matches a non-whitespace. Practically equal to [^ \t\r\n], and equal to [^\s]

\w

Matches any “word character” - in this case any letter or digit. Note that underscore (_) is not matched, as is the case with perl regular expressions. Equal to [a-zA-Z0-9]

\W

Matches any non-word character - anything but letters or numbers. Equal to [^a-zA-Z0-9] or [^\w]

The abbreviated classes can be put inside a custom class, for example to match a word character, a blank or a dot, you could write [\w \.]

Note

The POSIX notation of classes, [:<class name>:] is currently not supported.

Characters with special meanings inside character classes

The following characters has a special meaning inside the “[]” character class construct, and must be escaped to be literally included in a class:

]

Ends the character class. Must be escaped unless it is the very first character in the class (may follow an unescaped caret)

^ (caret)

Denotes a negative class, if it is the first character. Must be escaped to match literally if it is the first character in the class.

- (dash)

Denotes a logical range. Must always be escaped within a character class.

\ (backslash)

The escape character. Must always be escaped.

Alternatives: matching “one of

If you want to match one of a set of alternative patterns, you can separate those with | (vertical bar character).

For example to find either “John” or “Harry” you would use an expression John|Harry.

Sub Patterns

Sub patterns are patterns enclosed in parentheses, and they have several uses in the world of regular expressions.

Specifying alternatives

You may use a sub pattern to group a set of alternatives within a larger pattern. The alternatives are separated by the character “|” (vertical bar).

For example to match either of the words “int”, “float” or “double”, you could use the pattern int|float|double. If you only want to find one if it is followed by some whitespace and then some letters, put the alternatives inside a subpattern: (int|float|double)\s+\w+.

Capturing matching text (back references)

If you want to use a back reference, use a sub pattern to have the desired part of the pattern remembered.

For example, it you want to find two occurrences of the same word separated by a comma and possibly some whitespace, you could write (\w+),\s*\1. The sub pattern \w+ would find a chunk of word characters, and the entire expression would match if those were followed by a comma, 0 or more whitespace and then an equal chunk of word characters. (The string \1 references the first sub pattern enclosed in parentheses)

Lookahead Assertions

A lookahead assertion is a sub pattern, starting with either ?= or ?!.

For example to match the literal string “Bill” but only if not followed by “ Gates”, you could use this expression: Bill(?! Gates). (This would find “Bill Clinton” as well as “Billy the kid”, but silently ignore the other matches.)

Sub patterns used for assertions are not captured.

See also Assertions

Characters with a special meaning inside patterns

The following characters have meaning inside a pattern, and must be escaped if you want to literally match them:

\ (backslash)

The escape character.

^ (caret)

Asserts the beginning of the string.

$

Asserts the end of string.

() (left and right parentheses)

Denotes sub patterns.

{} (left and right curly braces)

Denotes numeric quantifiers.

[] (left and right square brackets)

Denotes character classes.

| (vertical bar)

logical OR. Separates alternatives.

+ (plus sign)

Quantifier, 1 or more.

* (asterisk)

Quantifier, 0 or more.

? (question mark)

An optional character. Can be interpreted as a quantifier, 0 or 1.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Quantifiers
Quantifiers

Quantifiers

Quantifiers allows a regular expression to match a specified number or range of numbers of either a character, character class or sub pattern.

Quantifiers are enclosed in curly brackets ({ and }) and have the general form {[minimum-occurrences][,[maximum-occurrences]]}

The usage is best explained by example:

{1}

Exactly 1 occurrence

{0,1}

Zero or 1 occurrences

{,1}

The same, with less work;)

{5,10}

At least 5 but maximum 10 occurrences.

{5,}

At least 5 occurrences, no maximum.

Additionally, there are some abbreviations:

* (asterisk)

similar to {0,}, find any number of occurrences.

+ (plus sign)

similar to {1,}, at least 1 occurrence.

? (question mark)

similar to {0,1}, zero or 1 occurrence.

Greed

When using quantifiers with no maximum, regular expressions defaults to match as much of the searched string as possible, commonly known as greedy behaviour.

Modern regular expression software provides the means of “turning off greediness”, though in a graphical environment it is up to the interface to provide you with access to this feature. For example a search dialogue providing a regular expression search could have a check box labelled “Minimal matching” as well as it ought to indicate if greediness is the default behaviour.

In context examples

Here are a few examples of using quantifiers

^\d{4,5}\s

Matches the digits in “1234 go” and “12345 now”, but neither in “567 eleven” nor in “223459 somewhere

\s+

Matches one or more whitespace characters

(bla){1,}

Matches all of “blablabla” and the “bla” in “blackbird” or “tabla

/?>

Matches “/>” in “<closeditem/>” as well as “>” in “<openitem>”.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Assertions
Assertions

Assertions

Assertions allows a regular expression to match only under certain controlled conditions.

An assertion does not need a character to match, it rather investigates the surroundings of a possible match before acknowledging it. For example the word boundary assertion does not try to find a non word character opposite a word one at its position, instead it makes sure that there is not a word character. This means that the assertion can match where there is no character, i.e. at the ends of a searched string.

Some assertions actually does have a pattern to match, but the part of the string matching that will not be a part of the result of the match of the full expression.

Regular Expressions as documented here supports the following assertions:

^ (caret: beginning of string)

Matches the beginning of the searched string.

The expression ^Peter will match at “Peter” in the string “Peter, hey!” but not in “Hey, Peter!

$ (end of string)

Matches the end of the searched string.

The expression you\?$ will match at the last you in the string “You didn't do that, did you?” but nowhere in “You didn't do that, right?

\b (word boundary)

Matches if there is a word character at one side and not a word character at the other.

This is useful to find word ends, for example both ends to find a whole word. The expression \bin\b will match at the separate “in” in the string “He came in through the window”, but not at the “in” in “window”.

\B (non word boundary)

Matches wherever “\b” does not.

That means that it will match for example within words: The expression \Bin\B will match at in “window” but not in “integer” or “I'm in love”.

(?=PATTERN) (Positive lookahead)

A lookahead assertion looks at the part of the string following a possible match. The positive lookahead will prevent the string from matching if the text following the possible match does not match the PATTERN of the assertion, but the text matched by that will not be included in the result.

The expression handy(?=\w) will match at “handy” in “handyman” but not in “That came in handy!

(?!PATTERN) (Negative lookahead)

The negative lookahead prevents a possible match to be acknowledged if the following part of the searched string does match its PATTERN.

The expression const \w+\b(?!\s*&) will match at “const char” in the string “const char* foo” while it can not match “const QString” in “const QString& bar” because the “&” matches the negative lookahead assertion pattern.



Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Prev
Next
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Appendix C. Installation
Installation
Prev

Appendix C. Installation

Kate is part of the KDE project http://www.kde.org/.

Kate can be found in the kdebase package on ftp://ftp.kde.org/pub/kde/, the main FTP site of the KDE project.

In order to compile and install Kate on your system, type the following in the base directory of the Kate distribution:

% ./configure
% make
% make install

Since Kate uses autoconf and automake you should have no trouble compiling it. Should you run into problems please report them to the KDE mailing lists.

Prev
Home


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team

Next
 


Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team