Am using Geany editor in ubuntu 13.10, Is there any shortcut key to align code (auto-alignment) in Geany editor?
For example : in Eclipse - Ctrl+Shift+F to invoke the Auto Formatter
For C, C++, C++/CLI, C#, and Java
You can achieve a similar behavior with Artistic Style 2.04.
Download the newest version, current 2.04 (do not use apt-get
to install because then you will get the older version 2.03 and this version will not work for this scenario because it do not accept piped output)
Install Artistic Style -> follow the install doc (/astyle/doc/install.html) in the download (make
then make install
)
Add a custom command to Geany:
bash -c "astyle --indent-classes -Y"
To customize this look at the Artistic Style documentation
Select an text area and press Ctrl+1 to run the first Geany custom command
For HTML
You can use tidy, tidy can also compile your html code if you use geany.
Install tidy: sudo apt-get install tidy
Create a custom command (example):
bash -c "tidy -xml --indent auto --indent-spaces 2 --quiet yes 2> /dev/null; true"
More info:
For Python
Python Source Formatter/Pretty Printer (not tested)
html
files, I used bash -c "tidy --quiet yes -m --output-xhtml no --output-html yes --wrap 0 --tidy-mark no --indent auto %f > /dev/null; true" (Geany replaces the
%f` with the name + extension of the file). I think 2
is deprecated.
For XML Go to Tools>Plugin manager and activate the plugin called XML PrettyPrinter. If that plugin is not available then search for it using apt or synaptic.
Once install, run by clicking Tools>PrettyPrinter XML.
You can use manual alignment using a pattern to align your code. It's slower but works for any language. There's a tclscript to do that posted here https://blog.jayvee-store.com/2017/06/18/code-alignment-in-geany/
Here is one way to do it using the vi editor:
Open the file in vi editor through terminal:
vi sample.cpp
Change the mode to visual mode by pressing v
.
Select the portion of the text you want to align by using the Up and Down arrow keys.
Press +
.
Save and close:
:wq!