On most POSIX systems you can use fc(1) to edit a command in
your $EDITOR. In vi(1) and friends you can then use "%!ls"
to replace the contents of the buffer with directory listing
and edit the commands you want.
Note that in general this is not a one-to-one replacement. `%!cmd` sends the current buffer contents to `cmd`’s stdin and replaces the buffer with `cmd`’s output. In the case of ‘ls’ this works since it doesn’t take anything on stdin
In Emacs, you can do this by invoking shell-command-on-region, by default bound to C-u M-| - iirc if no region is active it replaces the buffer, but I rarely use it that way so I might be wrong about that. At worst, C-x h C-u M-| gets you there.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/f...
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/v...