Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/f...

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/v...



> you can then use "%!ls" to replace the contents of the buffer with directory listing and edit the commands you want.

I often used :r !ls for that, thanks for the tip + it's shorter


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.


huh! I've been working on posix systems for 20 years and I didn't know that...


You just improved my life. Thank you.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: