Getting rid of those pesky non-breaking spaces (U+00A0) on MacOS X

A problem that's been bugging me for quite some time was that for no obvious reasons, source code I entered broke on space characters. Removing the space characters and re-entering them usually fixed the problem.

Finally, iex (the interactive Elixir shell) gave me a clue to what was really going on:

iex(11)> [ 65 ]
** (SyntaxError) iex:11: unexpected token: " " (column 5, codepoint U+00A0)


DuckDuckGoing for U+00A0 quickly revealed that U+00A0 is a non-breaking space (or nbsp). To show the offender in vim, put this in your .vimrc:

" show those darn non-breaking spaces   aka U+00A0
set list
set listchars=nbsp:.


But to really get rid of the problem, you can just remap the combination Alt+Space (which inserts the nbsp) to a plain ol' space (shamelessly copied from StackExchange):
- create the directory /Library/KeyBindings/
- create a new file DefaultKeyBinding.dict in this directory
- add the following entry to this file:
{
    "
" = (insertText:, " ");
}



245 Words

2016-02-18T09:24:00.003-08:00