13

Some word processing programs have a menu for entering special characters, including non-breaking spaces. It is also possible to copy the character created in the word processing program and paste it into other places, such as a terminal or a website text field. However, it is inconvenient to need to use a word processing program just to generate a non-breaking space in the first place.

How can I use my keyboard directly to enter a non-breaking space?

closed as off-topic by jasonwryan, Anthon, garethTheRed, slm Sep 10 '14 at 10:53

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • In what? A webpage, terminal...? – jasonwryan Sep 10 '14 at 8:16
  • 5
    This question appears to be off-topic because it is about entering text in webpages... – jasonwryan Sep 10 '14 at 8:21
  • 1
    So ? Would it be different in a terminal ? And BTW, wouldn't it be different on other OSes ? – greg0ire Sep 10 '14 at 8:22
  • 1
    @jasonwryan After reading both answers, does this still look off-topic to you ? – greg0ire Sep 10 '14 at 18:12
  • 1
    I have to agree with @greg0ire: the reason why he needs an unbreakable space is not that relevant, it's about keyboard input. – Demurgos Nov 5 '16 at 9:14
13

Once upon a time I told my debian fairy that I want compose instead of caps lock and typing compose space space now gives me the super solid unbreakable space:

compose space space ! compose space space ! compose space space ! compose space space ! compose space space ! compose space space ! compose space space ! compose space space !

For debianish systems have a look into /etc/default/keyboard, I have the following assigment there: XKBOPTIONS="compose:caps".

Alternatively, if you're using KDE, the "advanced" tab, of the kcmshell4 kcm_keyboard command lets you configure what key to map to compose.

This setting affects the text terminals too... at least in debian...

  • 1
    Didn't work for me, probably because I need to restart my session, but the workaround I edited in your question allows me to use compose, and compose space space does work! Thanks a lot! – greg0ire Sep 10 '14 at 9:10
6

Try Shift-space. If this doesn't work with your configuration, you can modify it by specifying

key <SPCE> { [ space, nobreakspace ] };

in XKB symbol settings.

My explanations on how to change XKB settings.

Note also that applications should not do line breaking under certain conditions, such as before a question mark, even after a normal space (as described in the Unicode Line Breaking Algorithm), so that the non-breaking space could be unnecessary; unfortunately, most applications do not follow this behavior. The non-breaking space U+00A0 is just an explicit non-breaking space; it doesn't mean that a normal space character is always breaking.

  • Looks nice, I won't try it right now, but +1 – greg0ire Sep 10 '14 at 18:10
  • There shouldn’t be a need to make a custom mapping for <SPCE>. Setxkbmap has several options for producing non-breaking space with the spacebar. For example, non-breaking space on Shift+Space on standard US layout: setxkbmap -option nbsp:level2 us. – Guildenstern Mar 13 at 1:20

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