Create a gist now

Instantly share code, notes, and snippets.

@glts /vgrep.sh
Last active Dec 17, 2015

What would you like to do?
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment