I'm trying to mock an editor as part of writing feature tests for a CLI that I'm working on. I need to mock an editor which is opened and quit directly without saving, as well as an editor which modifies content in some way, then saves and exits.

For the first test, I'm doing this:

export EDITOR='vi -c :q!'

which seems to work.

But I'm having a hard time writing the second test. I've tried something along these lines:

export EDITOR='vi -c ":Loremipsum" -c ":wq"'

(I have the Loremipsum plugin installed, but any other command which appended text would be equally fine).

The file that's opened in this way doesn't actually get modified, so I can tell I'm doing something wrong. I'm not wrapping my head around the documentation for the -c flag, and I can't find any clear examples of its syntax. What am I doing wrong?


OK, nevermind, I got it. I was confusing Ex mode and normal mode syntax, The colons weren't necessary.

export EDITOR='vi -c Loremipsum -c wq'

did exactly what I wanted it to.

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.