Vim - insert anything between each letter
4 answers
Here's a quick and slightly more interactive way to do it, everything is normal.
With the cursor at the beginning of the line, press:
-
i_<Esc>x
to insert and remove the separator character. (We do this for a side effect.) -
gp
to return the separator. -
.
, hold it until the job is done.
Unfortunately, we cannot use a counter with .
here, because it simply inserts the "count" delimiters in place.
+1
source to share
:%s/\(\p\)\p\@=/\1_/g
-
:
runs the command. -
%
searches the entire document. -
\(\p\)
will match and freeze the character for printing. You could replace\p
with\w
if you just wanted to match characters, eg. -
\p\@=
performs a audit trail to ensure that a match (first) is\p
followed by another\p
. This second, i.e.\p\@=
is not part of the match. It is important. - In the replacement part,
\1
fills in the matching (first) value\p
, and_
a literal. - The last flag
g
is the standard for all flags.
+2
source to share