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
This comment has been minimized.
Companion article at http://glts.github.io/2013/06/08/using-vim-as-grep.html.