Grep ignore temporary vim files

What is the best way to ignore temporary vim files when doing a search using grep?

+4
source share
3 answers
grep --exclude=*~ 

I believe this should work.

+15
source

I find Ack to replace my grepping need. No need to worry about excluding a bunch of default file types or directories. You can always customize the .ackrc file to add more file types or change the default default behavior.

+8
source

You did not say this, but I suspect that you are grepping through a directory tree.

This may not be the most elegant solution, but you can use the "find" output.

I often find myself recursively grepping a directory tree as follows:

 grep <needle> `find . \( -name '*.cpp' -o -name '*.h' \) -print` 

You could do something like:

 grep <needle> `find . \! -name '.??*swp' -print` 
+2
source

Source: https://habr.com/ru/post/1339427/


All Articles