What’s alt+spacebar character and how to disable it

keyboardtext input

I am writing code in various text editors with Finnish keyboard layout. Sometimes I press alt+spacebar accidentally when writing symbols. E.g.

  if(foobar || foobar2) {

… there is a high change I type pipe+pipe+magical alt-spacebar character.

The thing is, this alt+spacebar character is invisible like space, but behaves differently. Mainly it breaks code syntax in various occasions. However, because the character is invisible it is hard to track down.

What is this alt+spacebar character?

Is it possible to disable it so that when you press alt+spacebar it would type in a normal space?

Best Answer

optionspace inserts a non-breaking space (NBSP, U+00A0) by default.

What I've done I've set my editor highlight the non-breaking space, so that I see when I accidentally enter it.

You could remap to a normal space by creating ~/Library/KeyBindings/ and saving a property list like this as DefaultKeyBinding.dict:

{
    "~ " = (insertText:, " ");
}