12

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

4 Answers 4

16

For C, C++, C++/CLI, C#, and Java

You can achieve a similar behavior with Artistic Style 2.04.

  1. 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)

  2. Install Artistic Style -> follow the install doc (/astyle/doc/install.html) in the download (make then make install)

  3. Add a custom command to Geany:

    enter image description here

    enter image description here

    bash -c "astyle --indent-classes -Y"

    To customize this look at the Artistic Style documentation

  4. Select an text area and press Ctrl+1 to run the first Geany custom command

    enter image description here

For HTML

You can use tidy, tidy can also compile your html code if you use geany.

  1. Install tidy: sudo apt-get install tidy

  2. 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)

6
  • thanks for your Answer,above solution will work only for C, C++, C#, and Java Source Code as per Artistic desc.please let me know this will work for HTML,Python?
    – Sudheera
    Jun 11, 2014 at 4:36
  • @Sudheera updated answer
    – TuKsn
    Jun 11, 2014 at 8:35
  • It worked for JavaScript as well.
    – Subin
    Mar 25, 2016 at 6:38
  • For my 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.
    – Clément
    Apr 22, 2017 at 4:32
  • On Windows, use cmd /c "astyle --indent-classes -Y"
    – mppfiles
    May 17, 2019 at 23:32
2

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.

1
  • works like charm!!
    – roman204
    Jun 18, 2020 at 6:52
0

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/

0

Here is one way to do it using the vi editor:

  1. Open the file in vi editor through terminal:

    vi sample.cpp
    
  2. Change the mode to visual mode by pressing v.

  3. Select the portion of the text you want to align by using the Up and Down arrow keys.

  4. Press +.

  5. Save and close:

    :wq!
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .