In order to get the most of your code editor, you should first configure it to your liking and learn how to use its features. I’ve collected some of the configurations, as well as tips and tricks to make your coding experience a bit smoother. You are encouraged to dive into the features yourself in addition to what is listed here.
I have divided this page into 4 groups:
- Important – Definitely do this! You will reduce the likelihood of mistakes and will provide functional help.
- Recommended – These will help most of you, but are not crucial.
- Optional – We all have our favorite quirks and tricks. These are some things that I’ve noticed that might be helpful for some of you.
- Usage – some hints and trips how to better use your code editor.
Important: indentation guide and line length marker
- Showing indentation guides
Go to Editor -> Display
Enable “Show indentation guides” - Setting the maximum line length
Go to Editor -> Display
Change the Column marker from 72 to 80
Recommendation: Automatic closing parenthesis
When used, after writing open parenthesis, a set of closing ones will be automatically created for you. In case of a code block, indentation will also be automatically done..
Recommended: Setting tab to be 4 spaces
To indent our code, we use the tab key. It creates an invisible symbol or symbols in our code, that will represent indentation.
The problem here is the symbol \t or tab, which can act differently depending on in which editor or viewer we are opening the code file. It can be 2, 4 or even 8 spaces. In order for our code to look identical everywhere, we should replace it with 4 spaces automatically.
Go to: Editor -> Indentation
Change identation type: Type -> Spaces
Recommended: Improving visibility of exceeding line length requirement
Use this if you are having trouble keeping with the line length requirement – e.g. the vertical line isn’t visible enough for you.
Go to Editor -> Display
Change the type Line -> Background
Change the color to a more aggressive one
Recommendation: additional compilation flags
By default, the compiler will only show a certain amount of warnings when possible issues occur. To increase the list of things the compiler will tell you, we should add additional flags.
There are two ways to edit the compiler flags:
- The guaranteed always to work method is to select Tools -> Configuration files -> Filetype Configuration -> Programming Languages -> filetypes.c.
- Alternatively you can open up a .c code file (i.e. hello world) and select Build -> Set build commands; and edit the compile and build line.
NB! Be careful editing these lines! Accidentally missing a space or inserting a flag in the wrong place (in between two-parameter argument, out of order) can break compilation process!
Flags that might be of interest. Note that this is a very basic list and you will later want to add to these flags or use some additional flags temporarily based on what you will be doing.
-Wextra | Additional warnings such as unused parameters to functions etc |
-Wconversion | Warnings on implicit type casting – gives a better understanding when you might lose information when going from one variable type to another, i.e. losing the decimal places when going from floating point to integer |
-g | debugging symbols – used by various debugging tools |
-Werror | Treats all warnings as errors. This has more of a psychological effect so you wouldn’t ignore warnings. We will often train ourselves to ignore less relevant warnings and thus miss the important ones that break our programs. |
This is how the configuration file would look like when opened as a file.
Note that if you opened it through the geany build menu, the FT_00_CM would be the compile line and FT_01_CM would be the build line.
Optional: Dark theme (and others)
Files and installation instructions: https://github.com/geany/geany-themes
Optional: Make terminal follow the opened file path
Geany has a built in terminal. It is in the bottom part of the editor, mixed with the compilation log and other tools. By default, it will always show your user’s home folder. In order to make using it more convenient, you can make it change to the location of your currently opened code file.
Go to: Terminal
Tick: Follow path of the current file
Optional: Additional plugins
I’d highly recommend taking a look at other plugins for Geany to provide additional features. Some examples:
- auto-mark – This highlights the word currently selected by the cursor throughout the open document. Using it, it’s easy to find usage of the same variable or function.
- extra selection – This allows you to edit multiple lines at the same time. You can choose multiple rows and then edit the contents of them in one go.
- debugger or scope-debugger – Allows you to step through the code step-by-step, observe variable values, function call stack etc. Read more on Using a debugger with Geany
Usage: snippets
Geany has built in snippets for C (and some other languages). E.g. you can autocomplete if and else statements, for, while and do while loops and the switch statement.
To use a snippet, you can type the keyword. E.g. type for and immediately press the tab key after it. This will create the template for a for loop into your code.
Existing snippets can be viewed, altered or added using Tools -> Configuration Files -> snippets.conf.
Usage: keyboard shortcuts
To emphasize on using keyboard shortcuts, I’ve highlighted some of the more useful ones. There are many others that you can find in Geany settings, as well as change the key combinations to your liking.
Key combination | Action |
ctrl + n | New file |
ctrl + s | Save file |
ctrl + o | Open file |
F9 | Compile code into a program |
F5 | Execute the program |
tab | Indents the code by one (1 or more lines of code) |
shift + tab | Decreases indentation of the code by one (1 or more lines of code) |
ctrl + e | Toggle commenting of code |
ctrl + d | Makes a duplicate of active code line(s) |
ctrl + backspace | Deletes the word to the left of the cursor |
ctrl + delete | Deletes the word to the right of the cursor |