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?

\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. :)


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.

  • 1
    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

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.


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

Your Answer

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

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