6

I'm messing around with vim one liners, and I'm unable to escape a . character in a vim ex mode append command.

Basically,

vim -En '+a|Hello World' '+p' '+q!' -

prints "Hello World"

But,

vim -En '+a|.' '+p' '+q!' -

prints nothing at all. The . on a line by itself ends the append command, so I can't print it.

This unfortunately means I can't write a vim -E command script allowing me to chain commands. I want something like this, where the first vim call constructs the Ex commands, and the second interprets them

vim -En '+a|aConvoluted Hello World
.
Qp
QZQ
' | vim -En

But the first call fails: everything from the . on is ignored.

Any way to escape the dot? (It's a bit of a code golf, so it's all got to be vim only)

Golf rules for those who are interested:

No characters from the set b,c,d,e,f,k,p,r,s,t,{,},$,&,;,/,:,@,#,,,(,),<,>,! All uppercase characters are allowed.

2
  • did you try \. ?
    – Jeff Schaller
    Jul 2, 2017 at 21:45
  • Fraid so :(. You have to drop the single quotes and escape the pipe or bash goes crazy, but vim still doesn't care. +a\|\. prints nothing, +a\|\\. prints \.
    – dhakim
    Jul 2, 2017 at 22:24

1 Answer 1

1

This may be a bit contrived but it outputs a single period for me:

vim -En '+a|.x' '+s/x//' '+p' '+q!' -

(You mentioned golf so maybe this won't work for you since it adds a relatively large number of characters. Be sure to detail any specific constraints if you have any.)

1
  • This is a good one, adds a letter then removes it. If there's a cleaner way to remove letters, it might satisfy the rules I'm under.
    – dhakim
    Jul 6, 2017 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.