This is a problem that is making me crazy so any help is welcomed :-)

That happens to me mainly when typing scripts with Vim in Mac but I think I got the problem somethimes when typing some commands in the shell but I am not sure. To make the things more complicated, I can't describe a use case case when it happens... just happens :-( !

Everything starts when I try to run a bash scripts I have written using vim and then I get an error like

./script.sh: line 120: [[ 0: command not found

Next step I debug the script adding

set -x

and I see

+ '[[ 0' -eq 1 ']]'
./script.sh: line 120: [[ 0: command not found

and If I check the source code I see something like

if [[ $doSth -eq 1 ]]

so it seems that what is between '[[' and $'doSth' is not a space.

Ok, let's show the hidden characters using

:set list

and what I get

if [[ $doSth -eq 1 ]]$

so nothing weird. Finally what I did was to see the ASCII characters below the cursor with

:set laststatus=2
:set statusline=%<%f%h%m%r%=%b\ 1x%B\ \ %l,%c%V\ %P

and here I started to see some light:

  • The ASCII for a real space is 32
  • The ASCII for that character that seems a space is 160

The problem is easy to solve: I remove it and type an space again but .... what is going on?

I run:

  • iTerm
  • Then tmux
  • Then vim

So I guess something in the way get wrong but I have no idea what is going on so any help will be more than welcomed :-)

  • 1
    Dec 160, is the non-breaking space. I have seen this error mostly from copy-pasting from e.g. word, which likes to replace characters by "more appropriate and nicer looking ones" (which unfortunately causes such issues). You can also use ga on such a character Jun 28 at 7:29
  • 1
    On a Mac, a non-breaking space is inserted with Option-Space. See this answer for ways to disable that key mapping, not sure if one of those answers will work for you directly... You can try an inoremap on Vim, but I'm not sure of the exact syntax you'd need, I'm not on a Mac here so I couldn't test the exact issue you're having to test a solution within Vim itself...
    – filbranden
    Jun 28 at 7:43
  • 1
    Welcome to Vi and Vim! As @filbranden notes, Option+Space inserts a non-breaking space on a Mac. With that information, I'm not convinced the questions as stands is relevant or belongs here. My recommendation would be to close it with our "typo" close reason.
    – D. Ben Knoble
    Jun 28 at 20:22
  • Thanks a lot for your help, I think I have all the info for facing with annoyance feature :-)
    – islegmar
    Jun 29 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.