Text Editor Indenting & Highlighting

Do you hate reading code that is poorly indented or lacks syntax highlighting?  Here are some common text editor fixes:

GEdit AutoIndent

Gedit has an autoindent feature (Edit -> Preferences -> Editor -> Enable automatic indenting), but it only works if it has been turned on before you started writing code.  If you inherit code with poor indenting, do this:

  • Install VIM
  • Go to menu Tools > Manage External Tools to open Manage External Tools Dialog
  • Click on + button to add a new tool
  • Add the following script for your new tool in the textbox
#!/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
  • Set the ShortCut Key by putting your cursor into the ShortCut Key textbox and hitting your desired shortcut keys
  • Set the remaining options as desired
  • Next time you open poorly indented code within gedit, hit your shortcut keys for auto-indentation and gedit will indent your code for you.

Reference

Vim Auto-Indent & Syntax Highlighting

Edit your ~/.vimrc file to contain the following:

:syntax on
:set autoindent
:set cindent

Stop Being So Hardcore and Use an Integrated Development Environment (IDE)

Eclipse is one of the best IDEs for Java and it has plugins for Perl & Python Development.  You can use the debugger to step through code and examine the contents of variables without the need for print statements, etc.  It will automatically format, highlight, and indent your code.  Depending on which language you are developing in, it will provide tooltips describing how to use different code keywords and methods. There are hotkeys so that you can click on a method call and it will take you directly to the method definition.

Eclipse Website

Perl development in Eclipse requires the Epic Plugin. First install Eclipse, then install Epic. Epic will automatically highlight all your syntax errors with tooltip descriptions without having to run or save your code. It also has autocomplete, so you don’t have to fully type all your method and variable names. Epic debugger shows the contents of variables without the need for print statements, and allows you to execute custom code that doesn’t exist in your original program. This is helpful when you want to alter the contents of variables while debugging or trying out new code on the fly.

Epic_Ecliplse_syntax_check

Screenshot of automatic syntax error highlighting

Epic Plugin For Eclipse