VARIOUS ED(1) COMMANDS WIP: Expanding page to include other CLI tools Text manipulation ---------------------------------------------------------------------- Read file into another ...................................................................... `ed somefile' `r someotherfile' Insert line empty line between range of lines ...................................................................... ,---- | 1,5s/$/\ <RET> | <RET> `---- Line splitting ...................................................................... Split a line using a substitution and multi-line power combo! First, pack your substitution command's patterning matching part with the pattern where you want your new, split line to begin. Then, hang a back slash off the substitution command's replacement text part. Knock that enter key on your 'board to get a new line. Throw down an ampersand to grab that matched patt. Finally end the replacement with a forward slash. And if you're feeling fancy, add a quick p on your way to hitting Return. ,---- | ,pn | 1 this line should split at the first word 'split' | s/split/\ | &/p | split at the first word 'split' | ,pn | 1 this line should | 2 split at the first word 'split' `---- A small variation is to put the ampersand before the backslash. That'll make the split begin right after the matched pattern. Finding out stuff about files ---------------------------------------------------------------------- See number of lines in files in a directory: `find src/* -type f -exec wc -l '{}' \;' Get characters at position ...................................................................... {work in progress} Sometimes an error will say "Unexpected non-whitespace character after JSON at position 123 ..." To find the section of text, use: `tail -c +123 somefile' Number of lines in files in directory ...................................................................... `find . -type f -exec wc -l {} \;' Good for assessing distribution of code in a project. For unknown codebases, can be a helpful plumb. See enclosing function ...................................................................... `?^function?,/^}/pn' Can be adapted to print lines from current position up to a point of interest. `.,/end/pn' Duplicate selection ...................................................................... `s/selection/&&' Workflow ...................................................................... I always close a function or closure right after it is opened: ,---- | a | function() { | | } | . | - | c `----