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

Sudheera
  • 223
  • 1
  • 2
  • 6

4 Answers4

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)

TuKsn
  • 4,440
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.

tom
  • 21
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!
    
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/