3 ms·
Once I realized that vim can be used to process data from stdin and output it to stdout for another program...it changed the way I use unix environments forever
by cookiengineer 5y ago
Once I realized that vim can be used to process data from stdin and output it to stdout for another program...it changed the way I use unix environments forever.
Every time I am too lazy to cut or awk for a one-time bash script, I just use vim's visual mode.
Need a quick list of things to do or write a bash script to get shit done? "ls -l | vim -" is your friend.
Need to be more efficient in processing git bisects, patches or merges? Use a git alias for vimdiff.
- kevincox 5y agoHow can vim write to stdout? I use the stdin frequently as a better `less` but haven't use stdout.
- evanreichard 5y ago“:w !command” (e.g. “:w !wc -l”) Another fun one is “:%! command”, which pipes the current content to command, and replaces it with the output. (E.g. “:%!jq ‘.’” - to pretty print json). Pretty useful to quickly iterate when building a complicated command with multiple pipes.
- GianFabien 5y agoI tend to use: "vi | !!ls" -- same result. Also find paste, and cut commands very useful with tabular outputs.
- adamredwoods 5y agoI should try vim for that, I currently use lnav which is amazing for tracing logs and large outputs. I did try vimdiff but was unable to grasp it first try. https://lnav.org/ https://lnav.org/
- agentwiggles 5y agoI found this kind of usage of vim extremely helpful when doing Advent of Code in 2020. I saved myself a lot of boring string processing code by using vim for quick fixups on the input files. A little judicious usage of visual mode and the g command can definitely save a lot of time.