As Kamil made me realise it the NBSP functionality do will not serve me in nearly 95% of time. So I can disable it and for the 5% remaining, I will have to implement a distinct patch to allow me to insert this character for all the applications which will need.
Foreword : to be sure to speak of the same thing I want to present to you what is for me the difference between a PTS console and a TTY console. PTS are for me the GUI consoles (graphical) that we open from the Desktop Environment and TTY are for me the CLI (command line) that we open with the combination of Ctrl-Alt-Fn (n representing the session number and generally between 1 and 7, 7 reserved by default to the X11 graphical session).
Disable NBSP character from X11 environment
So based on my own searches (see above), I can disable NBSP character from my X11 environment. As X11 is a graphical environment, the disabling must be executed in graphical environment.
So I propose to implement it in an autostart script (for me from XFCE DE) :
user@host:~$ cat <<EOF > $HOME/.config/autostart/setxkbmap_no_nbsp.desktop
[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=No NBSP
Comment=Disable NBSP key
Exec=/usr/bin/setxkbmap -option "nbsp:none"
OnlyShowIn=XFCE;
StartupNotify=false
Terminal=false
Hidden=false
EOF
Redirect NBSP shortkey for Libre Office Writer
Sometimes from Libre Office Writer I need to insert NBSP character, but as it is disabled (see above), I must still find a way to insert this character.
I propose to use the Ctrl-Shift-space to do the replace.
So for the macro (Available here : Tools → Macros → Organize Macros → LOdev Basic → My macros > Standard > Module1 > Edit) :
REM ***** BASIC *****
' Based on : https://ask.libreoffice.org/t/special-characters/1089/3
Sub InsertNBSP
Dim oDoc as variant
oDoc = ThisComponent
Dim oCurrentController as variant
oCurrentController = oDoc.getCurrentController()
Dim oTextViewCursor as variant
oTextViewCursor = oCurrentController.getViewCursor()
Dim oText as variant
If IsEmpty(oTextViewCursor.Cell) Then
oText=oTextViewCursor.Text
Else
oText=oTextViewCursor.Cell.Text
End If
' NBSP unicode : https://www.compart.com/en/unicode/U+00A0
oText.insertString(oTextViewCursor,_
chr(clng("&H00A0&")),false)
End Sub
Nota : notice that the NBSP unicode code is U+00A0 and furthermore in my case the resulting code is written at $HOME/.config/libreoffice/4/user/basic/Standard/Module1.xba
And for the key bindding (Tools → Customize… → Keyboard), we will use Ctrl-Shift-space to bind with the macro's function named InsertNBSP
Nota : in my case the resulting association is written at $HOME/.config/libreoffice/4/user/registrymodifications.xcu
Reveal some characters from vim (included NBSP)
Based on this source I found a way to reveal all important characters in vim (which is my text editor of predilection) colourized in green (in my case). This is useful in TTY console because nothing prevent to type NBSP.
Important: depending on whether we access the shell from PTS or TTY console, we can use the unicode characters (in the first case) or partially (in the second case, but apparently it is possible to make the TTY support the full unicode - not tested).
Prerequisite : before add the following configuration lines, ensure that vim is yet installed
# See more here : https://vimhelp.org/options.txt.html#%27listchars%27
user@host:~$ mkdir .vim
user@host:~$ echo -e "set list\nset listchars=tab:\>\ ,trail:·,nbsp:?" >> $HOME/.vim/vimrc
Notes:
- tab will revealing all tabs to differentiate with spaces group and they will be replaced by greater than (>)
- trail will revealing all trailing spaces in the end of a line and they will be replaced by middle dot (·) ; to type this unicode see below
- nbsp will revealing all NBSP characters which will not be useful in the majority of cases (not to saying never) and they will replaced by question mark (?)
- although that is not recommended in reason of the fact that will working only from PTS console (unless we manage to integrate full unicode support from TTY) it is possible to use some unicode characters more meaningful or exotic ; for example tab could be composed by ⇥ and nbsp by "☠" (see below)
Use unicode character from PTS console
Important : this method works from my configuration, but I do not know if it works everywhere
To type the tab character (see other codes below) :
Unicode characters from PTS :
Disable NBSP character from TTY shell console
The last case not treated is the TTY console. As @Kamil suggested me it is possible to disable the NBSP from it in adding the following lines to the $HOME/.bashrc file :
user@host:~$ echo -e "bind '\"\302\240\":\" \"'" >> $HOME/.bashrc
To conclude
For now we can disable NBSP character from X11 so also PTS bash shell and vim in PTS with setxkbmap -option "nbsp:none"
(to make is persistent I implement it in a autostart script located in $HOME/.config/autostart
). We can also disable from TTY bash shell with bind '"\302\240":" "'
in $HOME/.bashrc
. We can be warned to the usage of NBSP (and other problematic characters) with vim in TTY with listchars
configuration in $HOME/.vim/vimrc
. Finally we can always add some wanted NBSP characters in Libre Office Writer (which depends too of the X11, so NBSP is prevented), in redirecting the NBSP shortkey to another key combination.
For the end word I would say that all different environment cases are not treated but I think what is said here is a good start point to find a way for this other cases.
vim
is a text editor and LibreOffice Writer is a text editor, still you want to disable nbsp in one but not in the other, as if accidental nbsps didn't happen for you in Writer or as if you never needed nbsp invim
. Consider disabling nbsp withsetxkbmap
like you did; additionally set up another keystroke to type npsp, one that is less likely to be activated accidentally. Then you will use the new keystroke in any editor iff you really need nbsp.