Search code examples
tabscode-formattingbluej

Use hard tabs instead of spaces in BlueJ


In BlueJ, if a file is using hard tabs BlueJ will automatically convert the entire file to use spaces instead of hard tabs. I'm looking for a way to tell BlueJ not to convert hard tabs into spaces.


Solution

  • According to Replacing Tabs with Spaces (posted by Michael Kölling, developer of BlueJ), tabs are converted to spaces under the default settings the first time you enter a tab.

    If your preference is set to use spaces (i.e. the TAB key is bound to the 'indent' function, not to the 'insert-tab' function) -- this is the default -- then the first hit of a TAB key in a newly opened file will replace all TABs in that file with spaces.

    In other words, if you get a file that contains TABs, editing this file with the BlueJ standard settings should remove TABs from that file. (I did not want to change the TABs on file-open, because I did not like the idea of the file changing on disc if you do not actively edit it.)

    To change this setting so that you can enter an actual TAB character, go to Options > Key Bindings, then select Edit Functions from the Categories drop down list. There are two changes you'll have to make.

    1. Scroll down to indent. By default it should be set to the Tab key. This setting is what's inserting soft spaces by default. Click on Tab under Key Bindings, then click the 'Delete Key' button.

    2. Scroll down to insert-tab. Delete the existing key binding and add the Tab key here so that pressing that key will insert a TAB character.

    Here's what the screen looks like with the default settings.

    BlueJ Key Bindings

    There you can see that the Tab key is set to the 'indent' function, which inserts soft spaces. Making the changes above will prevent that from happening.