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
?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityBased 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.
sed
or perl
substitution command rather than vim.
:h g~
(e.g.:norm! g~2W
) and not use visual mode.echo 'Élève' | ex -sc ':norm! g~|%p|q!' /dev/stdin
but it doesn't work.