RSS Amplifier

dhilst · Jul 3, 2018

Interactive grep with Vim

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

Did you know that you can use grep from inside vim? Give it a try :grep nologin /etc/passwd , then you open the quickfix with :cw where you can navigate through the results. I use grep a lot, usually in this format grep -rn <PATTERN> . --include *.<EXTENSION> . This is fast, and powerfull, and with vim I can jump directly to the results. The problem is that typing this everytime is anoying. So I…

Did you know that you can use grep from inside vim? Give it a try :grep nologin /etc/passwd, then you open the quickfix with :cw where you can navigate through the results.

I use grep a lot, usually in this format grep -rn <PATTERN> . --include *.<EXTENSION>. This is fast, and powerfull, and with vim I can jump directly to the results. The problem is that typing this everytime is anoying. So I wrote a simple command to help me out. It will ask for a pattern and grep with defined arguments.

In this example I was greping ansible playbooks, so I used the *.yml extension.

:command! -nargs=0 G exec 'grep -rn  ' input('Grep for: ') '. --include \*.yml'

Cheers

Read on dhilst.github.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.