Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using the Neo keyboard layout, which uses all kinds of modifier keys to input all kinds of characters (e.g. Greek letters and mathematical symbols). It also has shift+Mod3+space mapped to Unicode 0A, no-break space. From time to time it happens that I mistakenly press these buttons (while entering a space between other symbols with the same modifier keys).

Unfortunately [Lua|Xe]TeX obeys these spaces as unbreakable spaces both in normal text and in mathmode (using fontspec and unicode-math). However my editor (vim) shows the symbol like a normal space, so it is impossible to see where I made a mistake.

Is there an easy way to tell [Lua|Xe]TeX to treat no-break spaces like normal spaces?

share|improve this question

4 Answers 4

up vote 10 down vote accepted
\newunicodechar{ }{ }

In the first argument you put a NO-BREAK SPACE (U+00A0), in the second a normal space. A better definition would be

\newunicodechar{ }{~}

(again the space is NO-BREAK SPACE), so this unbreakable space will stretch or shrink wit the other spaces in the line. Of course use the first one if you want a normal space, ça va sans dire. :)

share|improve this answer

You can also do the following:

Go into Command mode in vim by hitting ESC, so what you enter appears in a special command-line at the bottom of the screen.


Enter / directly followed by what you want to search for and hit enter to search in forward direction.

To search in backwards direction, use ? instead of /.

To repeat the search in forward direction just hit n and to repeat the search in backwards direction, hit N.

To have the searchresults highlighted use :set hls (high-light search) or add set hls to your vimrc to switch it on permanently.


Again in command mode the syntax is: :[where] s/Searchpattern/Substitution/[Flags]

:22,150 s/a/z/ c this substitutes (the first appearance of) a with z from line 22 to 150 and the c at the end means, that vim will ask you each time before applying the substitution.

:1,$ s/a/z/ a will make the same substitution from the first to the last line of the document and the a at the end means to substitute without asking.

:% s/a/z/ g % is a shortcut for 1,$ and g means that vim will apply the substitution globally — substitute all appearances it finds in a line, else it might only substitute the first appearance.

These regular expressions are utterly powerful.

To find out more about this try :help substitute (you can leave the help via :q).

:set hls

:%s/ / /gc

share|improve this answer

Sometimes you might want to use an actual no-break space. So turning them into normal spaces altogether might not be the best idea. In that case Adityas solution is a good start. But I don’t like my indentation displayed as ^I.

The following colours the no-break spaces in gvim:

hi NoBreakSpace guibg=LightGoldenrod1 guifg=black
syn match NoBreakSpace / / containedin=ALL
syn match NoBreakSpace / / containedin=ALL

You can also do something similar to set list by using the conceal feature and replace the displayed character in normal mode with

hi Conceal guibg=LightGoldenrod1 guifg=black
syn match WhiteSpace / / containedin=ALL conceal cchar=⍽
syn match WhiteSpace / / containedin=ALL conceal cchar=¦
setl conceallevel=2 concealcursor=nv

in .vim/after/ftplugin/tex/<somename>.vim.

This will also display $\alpha^{+1}$ as α⁺¹. If you don’t like these other concealments you can disable them with

let g:tex_conceal = ""

in your .vimrc. Compare :help tex-conceal.

share|improve this answer

Another solution will be to change vim setup so that you can see the non-breakable space.

set listchars=nbsp:¬
set list

You can set appropriate syntax highlighting for NonText to highlight the non-breakable space.

share|improve this answer
Great. Though I'll use ␣, as it has less chance of being actually used in the (math) text. –  Caramdir May 16 '11 at 22:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.