Last active
October 18, 2019 10:43
-
-
Save ArtBIT/bbfadbad3accbd0cae7a03d5a4e39bc4 to your computer and use it in GitHub Desktop.
Use vim's ex mode inside of unix pipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\vim - -u NONE -es '+1' "+$*" '+%print' '+:qa!' | tail -n +2 | |
# Commented version | |
# \vim `# use unaliased version of vim` \ | |
# - `# read from stdin` \ | |
# -u NONE `# do not process .vimrc` \ | |
# -es `# start in :ex mode, do not start visual interface` \ | |
# '+1' `# go to the first line` \ | |
# "+$*" `# process commands passed as arguments` \ | |
# '+%print' `# print each and every line to stdout` \ | |
# '+:qa!' `# quit vim` \ | |
# | tail -n +2 # ignore first two lines | |
# Examples | |
# Delete empty lines | |
# cat file.txt | vimpipe 'g/^$/d' | ... | |
# Convert all markdown titles to Title Case | |
# cat book.md | vimpipe 'g/^#/s/\<\(\w\)\(\w*\)\>/\u\1\L\2/g' | sponge book.md | |
# We've removed 42 pages, so we need to reduce Page number by 42 | |
# cat book.md | vimpipe ':g/Page \d/norm $42^X' | sponge book.md | |
# cat formula.txt | vimpipe 'g/x=/norm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment