1

When I start vi/vim as ex, I can use the -c option to provide the set of ex commands to apply to a file:

echo Yes | ex -sc 's/Y/y/|%p|q!' /dev/stdin
yes

But how can I use normal mode commands like the ~ (switch case command) with ex?

  • 1
    If you want to switch case you could use :h g~ (e.g. :norm! g~2W) and not use visual mode. – statox Sep 18 '18 at 7:04
  • Thanks, @statox. Indeed running normal mode command is what I was looking for. However, could you post an answer with the full command? I tried a couple of variations around echo 'Élève' | ex -sc ':norm! g~|%p|q!' /dev/stdin but it doesn't work. – Sylvain Leroux Sep 18 '18 at 8:44
3

Based on a comment by @statox, I found a solution:

echo 'Élève' | ex -sc 'norm! g~w' -c '%p|q!' /dev/stdin
éLÈVE

The norm command allows executing Normal mode commands. And I had to use two -c option since, after norm, the rest of the line is considered part of the normal-mode command to execute.

  • 1
    Yup I couldn't answer your comment in time but that's what I meant :) Don't forget to mark your answer as accepted when you can so that the question has an answer. Also for this kind of manipulation, I would rather use sed or perl substitution command rather than vim. – statox Sep 18 '18 at 10:11

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.