Skip to content

Instantly share code, notes, and snippets.

@ArtBIT
Last active October 18, 2019 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArtBIT/bbfadbad3accbd0cae7a03d5a4e39bc4 to your computer and use it in GitHub Desktop.
Save ArtBIT/bbfadbad3accbd0cae7a03d5a4e39bc4 to your computer and use it in GitHub Desktop.
Use vim's ex mode inside of unix pipe
\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