This will be a bit convoluted, but, try:
:map q :%s/Name. /\^V^V^M&/g^M
Each ^x
is produced by pressing CtrlVCtrlx, so the actual sequence here is:
- CtrlV CtrlV for the first
^V
,
- CtrlV CtrlV for the second
^V
,
- CtrlV Enter for the first
^M
.
- And again for the last
^M
.
From man ex
:
Lines may be split by substituting new-line characters into them. The
newline in repl must be escaped by preceding it with a '\'. Other
metacharacters available in pat and repl are described below.
And from An Introduction to Display Editing with Vi:
You can use the map command from vi (typically in your EXINIT)
with a command of the form:
:map lhs rhsCR
mapping lhs into rhs. There are restrictions: lhs should be one
keystroke (either 1 character or one function key) since it must be
entered within one second (unless notimeout is set, in which case
you can type it as slowly as you wish, and vi will wait for you to
finish it before it echoes anything). The lhs can be no longer than
10 characters, the rhs no longer than 100. To get a space, tab or
newline into lhs or rhs you should escape them with a ^V. (It
may be necessary to double the ^V if the map command is given
inside vi, rather than in ex.) Spaces and tabs inside the rhs
need not be escaped.
So:
- We need to prefix the newline given to
:s
with a \
.
- If we were typing the command in
vi
, then we'd press CtrlV CtrlM to get the newline in the command. That means we have to make the mapping so that it would be as if we had pressed CtrlV CtrlM.
- We need CtrlV CtrlV just to get one
^V
to the command. But we need two, so that it would be as if we'd typed CtrlV.
The reduction would be like this:
^V^V^V^V^V^M
typed
- Which the
map
command will receive as ^V^V^M
- Which will be interpreted while executing the map as
^V^M
- To get a literal
^M
.
After all that, the output still won't be what you wanted:
Name1
Name2
Name3 Name4
😭
:map
command so you are not using it. 2.q
is a very useful operator, you should probably reconsider mapping it. – romainl Apr 30 '16 at 9:52