Copyright © 2000, 2001 Seth Rothberg
Copyright © 2002, 2003, 2005 Anders Lund
Copyright © 2005 Dominik Haumann
Het is toegestaan dit document te kopiëren, te verdelen en/of te wijzigen onder de voorwaarden van de GNU vrije-documentatie-licentie, versie 1.1 of een latere versie, gepubliceerd door de Free Software Foundation; zonder invariante paragrafen, zonder vooromslagteksten, en zonder achteromslagteksten. Een kopie van de licentie vindt u hier: de paragraaf "GNU vrije-documentatielicentie".
Kate is een editor voor programmeurs voor KDE 2.2 en hoger.
Deze handleiding beschrijft Kate versie 2.5.0
Inhoudsopgave
Lijst van voorbeelden
Welkom bij Kate, een editor voor programmeurs voor KDE versie 2.2 en hoger. Enkele van Kate's vele mogelijkheden zijn de in te stellensyntaxis-accentuering voor (programmeer)talen van C en C++ tot HTML en bash-scripts, de mogelijkheid om projecten te maken en te onderhouden, een interface voor meerdere documenten (MDI) en een ingebouwde terminal.
Kate is echter meer dan een editor voor programmeurs. De mogelijkheid om meerdere bestanden tegelijkertijd te openen maakt Kate ideaal om de vele configuratiebestanden van UNIX® aan te passen. Dit document werd geschreven in Kate.
Het bewerken van deze handleiding...
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.
You can start Kate from the or from the command line.
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 . Move your cursor up the menu to the menu item. A list of available editors will appear. Choose .
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.
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
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 license information.
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.
This section will describe some of the items on the 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 labeled 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 menu. This menu offers you your first glimpse into Kate's power and flexibility. In this section we'll look at four items:
Toggles the toolbar on and off.
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 and holding the button down. Drag the the window into Kate's editing window and release the when you have positioned the Filelist/Fileselector window as you prefer.
If you have grabbed the two parallel lines successfully your mouse pointer will turn into two crossed arrows as you drag.
Toggles the Fileselector on and off. This menu item is the same as with one difference. Toggling it on launches the window with the Fileselector on top.
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.
Many of Kate's keystroke commands (shortcuts) are configurable by way of the Settings menu. By default Kate honors 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 | |
Ctrl+F | |
F3 | |
Ctrl+B | Set a Bookmark |
Ctrl+C | Copy the marked text to the clipboard. |
Ctrl+N | New document |
Ctrl+P | |
Ctrl+Q | Quit - close active copy of editor |
Ctrl+R | |
Ctrl+S | Save your file. |
Ctrl+V | Paste. |
Ctrl+X | Delete the marked text and copy it to the clipboard. |
Ctrl+Z | |
Ctrl+Shift+Z |
Offers detailed documentation on all menu commands, configuration options, tools, dialogs, 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 menu topic to view this manual.
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 dialog, and in many other dialogs as well.
To employ What's This help, press Shift-F1 or use the -> 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.
Some dialogs have a Button. Pressing it will start the KHelpCenter and open the relevant documentation.
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.
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 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
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.
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 visualized by a small green led in the focused frame.
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 directories) 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.
The File Selector is a directory viewer, allowing you to open files from a displayed directory in the current frame.
From top down, the file selector consist of the following elements:
This contains standard navigations tool buttons:
Pressing it will cause the directory view to cd to your home directory.
This will cause the directory view to cd to the immediate parent of the currently displayed directory if possible.
Causes the directory view to cd to the previously displayed directory in the history. This button is disabled, if there is no previous item.
Causes the directory view to cd to the next directory in the history. This button is disabled, if there is no next directory.
This button will cause the directory view to cd to the directory of the currently active document if possible. This button is disabled, if the active document is a new, unsaved file, or the directory in which it resides can not be decided.
Here you can type the path of a directory to browse. The URL entry is maintaining a list of previously typed paths, to choose one use the arrow button on the right of the entry.
The URL entry has directory auto-completion, the completion method can be set using the menu of the text entry.
This is a standard KDE directory view.
The Filter entry allows you to enter a filter for the files
displayed in the directory view. The filter is using standard globs,
patterns must be separated by whitespace. 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.
The built in Terminal Emulator is a copy of the KDE Konsole terminal application, for your convenience. It is available from the -> menu item or theF7, and will get the focus whenever displayed. Additionally, if the Sync Konsole with active document option is enabled, it will cd 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 menu, for more information, see the Konsole manual.
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:
This is where the text of your document is located.
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 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 in the icon border next to that line.
The display of the icon border can be toggled using the -> menu item.
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 -> menu item.
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
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
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 -> menu item or the keyboard shortcut (defaults to Ctrl+C).
To Deselect the current selection, use the -> menu item, or the keyboard shortcut (default is Ctrl+Shift+A), or click with the in the editor.
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 -> menu item. The default keyboard shortcut is F4
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 Dialog.
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 Dialog.
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.
To copy text, select it and use the -> 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 -> menu item.
Additionally, text selected with the mouse may be pasted by clicking the
mouse button at the desired position.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.
The Find and Replace Text dialogs in Kate are very much the same, except the Replace Text dialog offers the means of entering a replacement string along with a few extra options.
The dialogs offer the following common options:
This is where to enter the search string. The interpretation of the string depends on some of the options described below.
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.
If enabled, the search will be case insensitive.
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.
If checked, the search will start at the beginning of the first line in the document, otherwise it will start at cursor position.
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 Dialog offers some additional options:
This is where to enter the replacement string.
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.
If checked, a small dialog will prompt you for what to do for each time a match is found. It offers the following options:
Activate this to replace the current match (which is selected in the editor).
Activate to skip the current match, and try to find another one.
Activate to cancel prompting, and just replace all matches.
Activate this skip the current match and end the searching.
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
To find text, launch the Find Text Dialog with Ctrl+For from the -> menu item,enter a search string, set the options as desired and hit . 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 Dialog is hidden, but stay tuned, finding further matches is very easy:
To find the next match in the search direction, use the -> command or press F3.
To find the next match in the opposite direction, use the -> command or press Shift+F3.
If no match is found before reaching the document border, you will be prompted for permission to cross that.
To replace text, launch the Replace text Dialog using the -> 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 button.
If you are using a regular expression to find the text to replace, you can employ backrefences to reuse text captured in parenthesized subpatterns of the expression.
See Bijlage B, Regular Expressions for more on those.
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 -> (Ctrl+B) command.
Clicking in the Icon Border next to that line.
Bookmarks are available in the menu. The individual bookmarks are available as menu items, labeled 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.
If the Reopen Files option in the Config Dialog is enabled (or if Kate was started by the session manager), your bookmarks will be restored when the document is reopened.
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 checkbox in the edit page of the configuration dialog.
To set the maximum line width (maximum characters per line), use the option in the edit page of the configuration dialog.
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.
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
The Comment and Uncomment commands, available from the 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 -> menu item or the related keyboard shortcut sequence, default is Ctrl+#.
To remove comment markers, use the -> menu item or the related keyboard shortcut, default is Ctrl+Shift+#.
This tool, available from the -> 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:
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 Dialog and type into the
input box the word time
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 dialog and type char:
[number]
in the entry box, then hit
.
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.
Voorbeeld 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 Dialog,
enter s/myclass/MyClass/i
, hit the
button, save the file and compile –
successfully without the error.
Voorbeeld 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 dialog, and type into the entry box:
%s/Miss Jensen/Ms Jones/
and hit return, you
are done.
Voorbeeld 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 realize that this is not nice code, and decide that you
want to use the const
keyword for all
“address of” arguments, those characterized 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 Dialog, and enter:
s/\s+(\w+)\s+(&)/ const \1 \2/g
and hit the
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.
This is extremely powerful, and though the actions can be undone by calling the command several times (as required) I recommend you practice a bit before using this command for serious editing if you are not familiar with sed or perl regular expressions.
This command starts a new document in the editing window. In the on the left the new file is named Untitled.
This command does not open a file. It launches KDE's open file dialog box which waits for you to select the files you want to open.
The open file dialog box works like a simple version of Konqueror. Use your 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 button to open the file.
Select multiple files by holding down the Ctrl or the Shift key along with the . Ctrl+ click selects one file at a time. Shift+ click selects a contiguous set of files.
Clicking on a directory name in the file selection window opens that directory 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 dialog 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.
This command allows you to open a file from a submenu that contains a list of recently edited files.
This command saves your file. Use it often. If the file is Untitled then becomes .
Name and rename files with this command. It launches the save file dialog box. This dialog works just as the open file dialog 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 button.
This command saves all open files.
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
This command launches the open with dialog box that allows you to select another application to open the active file. Your file will still be open in Kate.
Print the active file.
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.
This command closes all the files you have open in Kate.
Opens another instance of Kate. The new instance will be identical to your previous instance.
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 menu contains a host of commands, all to work with the currently active document.
Menu Entries
Undo the last editing command (typing, copying, cutting etc.)
If grouped undo is enabled, this may undo several editing commands of the same type, like typing in characters.
Redo the last undo step.
Removes selected text if any, and places a copy of the removed text in the clipboard.
Copies selected text, if any, to the clipboard.
Copies the first item in the clipboard into the editor at cursor position.
If Overwrite Selection is enabled, the pasted text will overwrite the selection, if any.
Selects all text in the editor.
Deselects the selected text in the editor if any.
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”.
Launch the Find Dialog to allow you to search for text in the edited document.
Go to the nearest downwards match of the last text or regular expression searched for, starting from cursor position
Go to the nearest upwards match of the last text or regular expression searched for, starting from cursor position
Launch the Replace Dialog to replace one or more instances of a defined text with something else.
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 Dialog.
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 Dialog.
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.
Remove comment marker(s) from the current line, or a possible selection, according to the syntax rules for the document.
Launches the Go To Line Dialog, allowing you to enter the number of a line to find in the document
The 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
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 behavior may change in future versions of Kate.
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 behavior may change in future versions of Kate.
The menu allows you to manually decide which syntax rules to use for highlighting and 'ing the active document. The menu groups the available syntax rule sets into logical groups.
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:
On UNIX® systems, end of line is a single newline character.
On DOS (and Windows®) systems, end of line is represented by a carriage return followed by a newline.
On Mac® systems, end of line is represented by a by a carriage return.
The menu allows you to manage settings specific to the active editor, and to manage frames.
Menu Items
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
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
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 Menu as well as in the File List.
See also Working with the Kate MDI
This is a toggle item. Setting it on checked will make the side of the active editor, and vice versa.
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.
Move focus to the next frame; the order is following order of creation rather than that of visual logic. This behavior may change in a future version of Kate
See also Working with the Kate MDI
Move focus to the previous frame; the order is following order of creation rather than that of visual logic. This behavior may change in a future version of Kate
See also Working with the Kate MDI
The 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.
The menu contains commands of two categories:
The menu allows you to change the properties of the main window, such as showing/hiding toolbars and boxes, and provides access to the configuration dialogs.
Toggles the display of the main toolbar.
Toggle the display of the Kate Filelist
Toggle the display of the Kate File Selector
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 dialog the shell session will be cd'd to the directory of the active document, if it is a local file.
Display the the familiar KDE Keyboard Shortcut Configuration Dialog.
Display the the familiar KDE Toolbar Configuration Dialog.
Launch the Main Configuration Dialog
The menu provides access to the online help available for Kate; as well as to the usual about dialogs.
As well as the standard KDE 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.
Roept het handboek van Kate op (dit document).
Verandert de muiscursor in de combinatie pijltje en vraagteken. Het klikken op items in Kate zal een tekstballon tonen (als er een beschikbaar is voor dat specifieke item) met een omschrijving van de functie van dat item.
Opent het bugrapport-dialoogvenster waar u een een bug kunt melden of een “suggestie” kunt indienen die deze toepassing beter, handiger of nuttiger zou kunnen maken.
Deze optie zal informatie over de versie en de auteurs tonen.
Dit zal de KDE-versie en andere standaardinformatie tonen.
Kate offers several means of tweaking the application to behave as desired. The most important ones are:
The main configuration tool, allowing you to configure the Kate application, the editor component and the usage of plugins.
Allows you to change often used settings, and to launch the configuration dialogs.
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 Control Center, and may be configured clicking the right mouse and choosing from the sub menu.
The Kate configuration dialog 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 dialog into logical groups.
This group contains pages to configure the main Kate application
Global options for Kate
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 on the left by default) or by selecting the document from the 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.
These options determine how and if Kate will restore your editing session when launched anfer 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).
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 reestablished
If this option is enabled, Kate will attempt to restore your frames exactly as you left them.
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.
If this option is enabled, the windows will be fully repainted while dragging the frame splitters. A nice way to use some extra CPU cycles :). If unchecked, a so-called “rubber band” (indicating the new size of the frame) will be used instead.
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
Unsurprisingly, this allows you to decide how long the files menu should grow.
This group contains all pages related to the editor component of Kate
This page allows you to change the background and selection background colors of the editor. Initially, Kate will use the colors as set in the KDE Configuratiecentrum -> page.
To change a color, press the associated button and select the desired color in the color chooser.
Choosing the background color may render Syntax Highlighted text unreadable. You should use a light color for the background, and a dark color for the selection background.
Otherwise, you will probably need to change the Default Styles.
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.
As it is not currently possible to use individual fonts for documents, nor to change the font for printing from the print dialog, be careful. A fixed-width font is strongly recommended.
This page allows you to change the behavior of indentation.
Indent Options
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.
If checked, Kate will indent with spaces rather than tabs.
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.
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.
With this behavior checked, Kate will leave whitespace behind the cursor after indenting.
This page provides options for fine tuning the select behavior of Kate
Select Options
When Persistent Selections is enabled, key input will not cause the selection to be removed/diminished.
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.
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.
This page contains miscellaneous options for fine-tuning the behavior of the Kate editor component.
Editor Options
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.
This option decides the max length of lines if the Word Wrap option is enabled.
If enabled, Kate will replace inserted Tab characters with a number of single whitespace characters as defined in Tab Width.
If enabled, Kate will remove any whitespace at the rear end of a line each time the cursor is moved off that line.
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 menu entry will call for indent as well.
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 <
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.
If enabled, Kate will draw a small dot at the start of a Tab character in the editor to indicate its presence.
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.
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.
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 Dialog
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:
Select the command for which you want to configure the keys.
Choose the option in the pane below the list if you don't want a key for this command.
Choose the option to use the default key(s) for the command
Choose the option to select a custom key for the command, or set an alternate one.
If you choose the option, the key entering button at the right of the pane will be enabled. To set a key, press it. The KDE Define Shortcut Dialog will appear. In this dialog:
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.
Press the desired key sequence, it will be visualized for you in the dialog for your confirmation.
If you are of an adventurous nature, try playing around with the 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).
This page allows you to fine tune the color 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 and one for managing the . Both tabs display a list of contexts in which the default colors and font are used to visualize 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:
Displays the context name, painted using the style properties for the context.
The state of this checkbox decides if the context should be rendered using a boldface font.
The state of this checkbox decides if the context should be rendered using italic font.
This button displays the color for drawing the style in normal mode, when the text is not selected that is. To change the color, click the button.
This button displays the color for drawing the style when the text is selected. To change the color, click the button.
This checkbox, only available in the 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.
Here you can change the most important properties of each available highlight mode. First, use the 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 and entries. Alternatively, press the wizard button to the right of the entry. This will show a dialog 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 dialog 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 labeled . 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.
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.
This page provides the means of loading/unloading plugins, and minimal information about individual plugins.
To load an unloaded plugin, select it in the pane and use the arrow buttons to move it to the pane.
To unload a loaded plugin, select it in the pane and use the arrow buttons to move it to the pane.
To view a minimal description and information about a plugin, select it and the information will be available below the lists.
Kate. Programma copyright 2000, 2001, 2002 - 2005 het Kate-ontwikkelingsteam.
Het Kate-team:
(cullmann AT kde.org)
Projectbeheerder & kernontwikkelaar
(anders AT alweb.dk)
Kernontwikkelaar, Perl syntaxis-accentuering, documentatie
(kde AT jowenn.at)
Kernontwikkelaar, syntaxis-accentuering
(michael.bartl1 AT chello.at)
Kernontwikkelaar
(phlip_cpp AT my-deja.com)
De project-compiler
(bastian AT kde.org)
Het schitterende buffersysteem
(newellm AT proaxis.com)
Tests...
(gholam AT xtra.co.nz)
Kernontwikkelaar
(digisnap AT cs.tu-berlin.de)
Auteur van KWrite
(koch AT kde.org)
Omzetting van KWrite voor KParts
(gebauer AT bigfoot.com)
Niet opgegeven
(hausmann AT kde.org)
Niet opgegeven
(glenebob AT nwlink.com)
Ongedaan-maken-geschiedenis van KWrite, integratie van KSpell
(sdmanson AT alltel.net)
XML-syntaxisaccentuering in KWrite
(jfirebaugh AT kde.org)
Verscheidene patches
(dhdev AT gmx.de)
Ontwikkelaar, syntaxis-accentuering
Vele anderen hebben bijgedragen:
(merlim AT libero.it)
Syntaxis-accentuering voor RPM Spec-bestanden, Diff en meer
(rocky AT purdue.edu)
Syntaxis-accentuering voor VHDL
Syntaxis-accentuering voor SQL
Syntaxis-accentuering voor Ferite
Syntaxis-accentuering voor ILERPG
Syntaxis-accentuering voor Java en nog veel meer
Syntaxis-accentuering voor LaTeX
Syntaxis-accentuering voor Make-bestanden, Python
Syntaxis-accentuering voor Python
Kleine bugfixes, XML-plugin
Documentatie copyright 2000,2001 Seth Rothberg (sethmr AT bellatlantic.org)
Documentatie copyright 2002, 2003, 2005 Anders Lund (anders AT alweb.dk)
Op- of aanmerkingen over de vertalingen van de toepassing en haar documentatie kunt u melden op http://www.kde.nl/bugs.
Dit document is vertaald in het Nederlands door Niels Reedijk.
Dit document is vertaald in het Nederlands door Tom Albers.
Dit document is vertaald in het Nederlands door Rinse de Vries.
De vertaling werd nagelezen door Rinse de Vries.
De vertaling werd nagelezen door Natalie Koning.
Deze documentatie valt onder de bepalingen van de GNU vrije-documentatie-licentie.
Deze toepassing valt onder de bepalingen van de GNU General Public License.
Inhoudsopgave
Syntax Highlighting is what makes the editor automatically display text in different styles/colors, 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 colors 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.
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 -> menu.
The styles and colors 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 Dialog.
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%.
You can download updated or additional syntax highlight definitions from the Kate website by clicking the button in the Highlight Page of the Config Dialog.
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.
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 analyze 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 analyzed 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, organized into context blocks
Keyword lists
Style Item definitions
When analyzing 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.
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 analyzed. 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 organized 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.
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 emphasize concepts of the text formats.
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 colors 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 recognize 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.
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 dialog 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.
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 directory
$
.KDEDIR
/share/apps/kate/syntax
Main components of Kate Highlight Definitions
The General Section contains information on the comment format of the described language, and defines whether keywords are case sensitive.
The Highlighting section contains all data required to analyze and render the text. This includes:
Contains ItemData elements, each defining a style.
Each list has a name, and may contain any number of items.
Contains contexts, which again contain the syntax 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
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.
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.
Detect one character of a set of specified characters.
<AnyChar String="(string)" (common attributes) />
The String
attribute defines the set of
characters.
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.
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.
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.
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.
Detect a floating point number.
<Float (common attributes) />
This rule has no specific attributes.
Detect an octal point number representation.
<HlCOct (common attributes) />
This rule has no specific attributes.
Detect a hexadecimal number representation.
<Int (common attributes) />
This rule has no specific attributes.
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.
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.
Usefull 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.
Matches at end of line.
<LineContinue (common attributes) />
This rule has no specific attributes.
This rule is usefull for switching context at end of line.
Inhoudsopgave
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.
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 generalization 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 consists of literal strings and character classes. Patterns may contain sub-patterns, which are patterns enclosed in parentheses.
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
\\
.
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
but “a”, “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 \.]
The POSIX notation of classes, [:<class
name>:]
is currently not supported.
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.
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 are patterns enclosed in parentheses, and they have several uses in the world of regular expressions.
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+
.
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)
See also Back references.
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
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.
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.
When using quantifiers with no maximum, regular expressions defaults to match as much of the searched string as possible, commonly known as greedy behavior.
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 dialog providing a regular expression search could have a check box labeled “Minimal matching” as well as it ought to indicate if greediness is the default behavior.
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>”.
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.
Kate is een onderdeel van het KDE-project http://www.kde.org/.
Kate is een onderdeel van de module kdebase. Deze module kunt u vinden op de FTP-site van het KDE-project: ftp://ftp.kde.org/pub/kde/.
Er zijn een aantal stappen nodig om Kate op uw systeem te compileren en te installeren. Voer de volgende commando's uit in de hoofdmap van de broncode van Kate:
%
./configure
%
make
%
make install
Aangezien Kate autoconf en automake gebruikt, zouden er bij de compilatie geen problemen mogen voorkomen. Indien u toch problemen tegenkomt, meldt u ze dan in de betreffende KDE-mailinglists.
Would you like to make a comment or contribute an update to this page?
Send feedback to the KDE Docs Team