Breaking spaces in vim
Paul Cochrane đȘđș
Posted on May 1, 2024
Originally published on peateasea.de.
Some text editing software packages seem to insert non-breaking spaces into files willy-nilly. This can be a pain if you donât want them. Also, theyâre very hard to find becauseâto the eyeâtheyâre indistinguishable from a normal space. What to do?
If youâre like me and use vim as your day-to-day editor and want to break free from non-breaking spaces, you can replace them in the entire document (from normal mode) like so:
:%s/<Ctrl-V>u00a0/ /g
or more compactly like so:
:%s/<Ctrl-V>xa0/ /g
For those who might be interested in the details, hereâs whatâs happening:
- when in normal mode, commands are prefixed with a colon
:
- the
%
means that the following command will be carried out for all lines in the buffer or file. -
s
denotes the start of a substitution. - the
/
characters delimit both the string to search for and the string to replace it with. -
<Ctrl-V>
means to enter the^V
control character by pressing theCtrl
key andv
together. -
u00a0
is the unicode hex sequence (in vim) for a non-breaking space. The^V
combined with the unicode hex sequence then produce a non-breaking space. - the trailing
g
means to carry out the substitution âgloballyâ i.e. for all occurrences on the current line (the%
then handles the case for all lines).
Happy hacking!
đ đȘ đ
đ©
Paul Cochrane đȘđș
Posted on May 1, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.