0

I am trying to script some file changes using ex per this answer.

The issue that I'm running into is that ex seems to assume that every command is preceded by a colon, so while I can do something like:

/^foo()
a
test insertion
.
w!
q

I can't do:

/^foo()
>iB
O
if (bar())
.
w!
q

because it chokes on the second and third lines, as nearly as I can tell because :>iB and :O both return errors in vim.

What am I doing wrong? How can I indent the current braces block and/or insert above the current line within ex?

0

ex seems to assume that every command is preceded by a colon […]

Actually, you are assuming that vi commands and ex commands are the same thing. The character sequences that you type in full-screen mode to vi are not the command language of ex.

To insert above instead of append below, use insert instead of append.

To shift the current line left and right, use > and < on their own. To shift a block, prefix them with a line range that specifies the block.

Further reading

  • Thank you. The append was just what I needed, and the links are helpful. I have found the use of > to be inconsistent, though. It works from the console, but when I try to pass in a series of commands (a la {{ex $FILENAME << END_EX_COMMANDS}}) it fails. I can do .> and +4> but not > or +.>>. – Dan Apr 4 at 13:55

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.