Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Context actions

You can execute the context action command on the current word at the cursor position or the available selection.
This word or selection can be used as an argument to the command. The context action is invoked by a menu entry
in the popup menu of the editor and also a keyboard shortcut (see the section called Keybindings).

The command can be specified in the preferences dialog and also for each filetype (see "context_action_cmd" in
the section called Filetype configuration). When the context action is invoked, the filetype specific command is
used if available, otherwise the command specified in the preferences dialog is executed.

The current word or selection can be referred with the wildcard "%s" in the command, it will be replaced by the
current word or selection before the command is executed.

For example a context action can be used to open API documentation in a browser window, the command to open
the PHP API documentation would be:

firefox "http://www.php.net/%s"

when executing the command, the %s is substituted by the word near the cursor position or by the current
selection. If the cursor is at the word "echo", a browser window will open(assumed your browser is called firefox)
and it will open the address: http://www.php.net/echo.

Autocompletion
Geany can offer a list of possible completions for symbols defined in the tags and for all words in a document.

The autocompletion list for symbols is presented when the first few characters of the symbol are typed
(configurable, see Editor Completions preferences, default 4) or when the Complete word keybinding is pressed
(configurable, see Editor keybindings, default Ctrl-Space).

When the defined keybinding is typed and the Autocomplete all words in document preference (in Editor
Completions preferences) is selected then the autocompletion list will show all matching words in the document,
if there are no matching symbols.

If you don't want to use autocompletion it can be dismissed until the next symbol by pressing Escape. The
autocompletion list is updated as more characters are typed so that it only shows completions that start with the
characters typed so far. If no symbols begin with the sequence, the autocompletion window is closed.

The up and down arrows will move the selected item. The highlighted item on the autocompletion list can be
chosen from the list by pressing Enter/Return. You can also double-click to select an item. The sequence will be
completed to match the chosen item, and if the Drop rest of word on completion preference is set (in Editor
Completions preferences) then any characters after the cursor that match a symbol or word are deleted.

Word part completion


By default, pressing Tab will complete the selected item by word part; useful e.g. for adding the
prefix gtk_combo_box_entry_ without typing it manually:

 gtk_com<TAB>
 gtk_combo_<TAB>
 gtk_combo_box_<e><TAB>
 gtk_combo_box_entry_<s><ENTER>
 gtk_combo_box_entry_set_text_column
The key combination can be changed from Tab - See Editor keybindings. If you clear/change the key combination
for word part completion, Tab will complete the whole word instead, like Enter.

Scope autocompletion
E.g.:

struct
{
int i;
char c;
} foo;

When you type foo. it will show an autocompletion list with 'i' and 'c' symbols.

It only works for languages that set parent scope names for e.g. struct members. Currently this means C-like
languages. The C tag parser only parses global scopes, so this won't work for structs or objects declared in local
scope.

User-definable snippets
Snippets are small strings or code constructs which can be replaced or completed to a more complex string. So
you can save a lot of time when typing common strings and letting Geany do the work for you. To know what to
complete or replace Geany reads a configuration file called snippets.confat startup.

Maybe you need to often type your name, so define a snippet like this:

[Default]
myname=Enrico Tröger

Every time you write myname <TAB> in Geany, it will replace "myname" with "Enrico Tröger". The key to start
autocompletion can be changed in the preferences dialog, by default it is TAB. The corresponding keybinding is
called Complete snippet.

Paths

You can override the default snippets using the user snippets.conf file. Use the Tools->Configuration Files-
>snippets.conf menu item. See also Configuration file paths.

This adds the default settings to the user file if the file doesn't exist. Alternatively the file can be created manually,
adding only the settings you want to change. All missing settings will be read from the system snippets file.

Snippet groups

The file snippets.conf contains sections defining snippets that are available for particular filetypes and in general.

The two sections "Default" and "Special" apply to all filetypes. "Default" contains all snippets which are available
for every filetype and "Special" contains snippets which can only be used in other snippets. So you can define
often used parts of snippets and just use the special snippet as a placeholder (see the snippets.conf for details).

You can define sections with the name of a filetype eg "C++". The snippets in that section are only available for
use in files with that filetype. Snippets in filetype sections will hide snippets with the same name in the "Default"
section when used in a file of that filetype.

Substitution sequences for snippets

To define snippets you can use several special character sequences which will be replaced when using the snippet:

\n or Insert a new line


%newline (it will be
% replaced by the
used EOL char(s):
LF, CR/LF, or
CR).
\t or %ws Insert an
% indentation step,
it will be replaced
according to the
current
document's indent
mode.
\s \s to force
whitespace at
beginning or end
of a value ('key=
value' won't work,
use 'key=\svalue')
%cursor% Place the cursor at
this position after
completion has
been done. You
can define
multiple %cursor
% wildcards and
use the
keybinding Move
cursor in
snippet to jump to
the next defined
cursor position in
the completed
snippet.
%...% "..." means the
name of a key in
the "Special"
section. If you
have defined a
key "brace_open"
in the "Special"
section you can
use %brace_open
% in any other
snippet.
Snippet names must not contain spaces otherwise they won't work correctly. But beside that you can define almost
any string as a snippet and use it later in Geany. It is not limited to existing contructs of certain programming
languages(like if, for, switch). Define whatever you need.

Template wildcards

Since Geany 0.15 you can also use most of the available templates wildcards listed in Template wildcards. All
wildcards which are listed as available in snippets can be used. For instance to improve the above example:
[Default]
myname=My name is {developer}
mysystem=My system: {command:uname -a}

this will replace myname with "My name is " and the value of the template preference developer.

Word characters

You can change the way Geany recognizes the word to complete, that is how the start and end of a word is
recognised when the snippet completion is requested. The section "Special" may contain a key "wordchars" which
lists all characters a string may contain to be recognized as a word for completion. Leave it commented to use
default characters or define it to add or remove characters to fit your needs.

Snippet keybindings
Normally you would type the snippet name and press Tab. However, you can define keybindings for snippets
under the Keybindings group insnippets.conf:

[Keybindings]
for=<Ctrl>7
block_cursor=<Ctrl>8

Note

Snippet keybindings may be overridden by Geany's configurable keybindings.

Inserting Unicode characters


You can insert Unicode code points by hitting Ctrl-Shift-u, then still holding Ctrl-Shift, type some hex digits
representing the code point for the character you want and hit Enter or Return (still holding Ctrl-Shift). If you
release Ctrl-Shift before hitting Enter or Return (or any other character), the code insertion is completed, but the
typed character is also entered. In the case of Enter/Return, it is a newline, as you might expect.

In some earlier versions of Geany, you might need to first unbind Ctrl-Shift-u in the keybinding preferences, then
select Tools->Reload Configurationor restart Geany. Note that it works slightly differently from other GTK
applications, in that you'll need to continue to hold down the Ctrl and Shift keys while typing the code point hex
digits (and the Enter or Return to finish the code point).

Search, replace and go to


This section describes search-related commands from the Search menu and the editor window's popup menu:

 Find
 Find selection
 Find usage
 Find in files
 Replace
 Go to tag definition
 Go to tag declaration
 Go to line

See also Search preferences.


Toolbar entries
There are also two toolbar entries:

 Search bar
 Go to line entry

There are keybindings to focus each of these - see Focus keybindings. Pressing Escape will then focus the editor.

Search bar
The quickest way to find some text is to use the search bar entry in the toolbar. This performs a case-insensitive
search in the current document whilst you type. Pressing Enter will search again, and pressing Shift-Enter will
search backwards.

You might also like