Skip to content

Instantly share code, notes, and snippets.

@glts
Last active December 17, 2015 23:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glts/5693322 to your computer and use it in GitHub Desktop.
Save glts/5693322 to your computer and use it in GitHub Desktop.
A grep with Vim regular expressions
#!/bin/bash
vgrep() {
local re=${1:-^}
local files=()
for arg in "${@:2}"; do
[ -f "${arg}" ] && files+=( "${arg}" )
done
if [ -z "${files[*]:1}" ]; then
vim -Ni NONE -nes <<<"argdo g/${re////\\/}/p" -- "${files[@]}"
else
vim -Ni NONE -nes <<END -- "${files[@]}" 2>&1 | sed -e '1d' -e 's/\r$//'
argdo g/${re////\\/}/verbose echo expand('%').':'.getline('.')
verbose echo "\n"
END
fi
}
@glts
Copy link
Author

glts commented Jun 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment