Here is another workaround: you can use vim to indent automatically and automatically format your code from within Gedit.
First make sure vim is installed. Then add the βexternal toolβ to Gedit from the βtoolsβ menu and use the following code:
#!/bin/sh CMD_FILE_NAME=.formatcommand; TMP_FILE_NAME=.tempvimfile; touch $CMD_FILE_NAME&&echo "gg=G :wq! "$TMP_FILE_NAME > $CMD_FILE_NAME&&(vim $GEDIT_CURRENT_DOCUMENT_NAME -s $CMD_FILE_NAME > /dev/null 2>/dev/null)&&rm $CMD_FILE_NAME; cat $TMP_FILE_NAME rm $TMP_FILE_NAME
Also make sure that:
- "Save" is set to "Current Document".
- Input is set to Nothing.
- "Exit" is set to "Replace current document."
You can also customize the hotkey, I prefer Alt + Shift + F, like Netbeans. Now, when you press the hot key, the current file will be saved and automatically formatted.
This will work in any programming language / script, given the correct file extension
If you don't get the indent, insert filetype indent on in your ~/.vimrc file and it will work.
For more details see my personal blog.
Hussein El Motayam Jun 07 2018-12-06T00: 00Z
source share