I needed to insert a space between months and years in text in a document while using Vim, a version of the Vi editor for Windows systems. The text was as shown below:
With Vi, regular expressions can be used to search for and replace text. In this case I could use
December1999 Edition November1999 Edition October1999 Edition ... March1996 Edition February1996 Edition January1996 Edition
:.,$ s/199\(\d) Edition/ 199\1/to perform the substitution.
To search from the line I was on to the end of the document I can use
.,$. With the substitute
s command, you can search
and replace text with commands of
s/old text/new text. You can use the
option, if you don't want the case of letters to be considered, i.e. if you
wish "A" and "a" to be treated the same, then you can use
text/i. You can use the
g option, if you wish to replace
all occurrences of
old text on the line, for cases where the
text may occur multiple times on the same line, e.g.
text/g. You can use whatever delimiter you wish to separate the
parts of the command, e.g. you can use
s:old text:new text:.
\d in the command indicates that I am only looking for
digits, i.e. 0 to 9. By enclosing the
\d in parentheses, i.e.
(\d), I can have the editor "remember" whatever it
found between the parentheses. Then I can have it insert what it has
remembered in the replacement text by using
\1. If I had
used multiple parentheses at various parts in the search text, then the
second string I wanted remembered would be indicated with a
In this case the last digit of the year was all I wanted the editor to
remember and insert appropriately in the substitutiong text.
If you wish to search an entire document, you can use
to represent the first line of the file through the last line, or you
can just use
% to represent the entire file.
:% s/199\(\d) Edition/ 199\1/