JohnBeckett (talk | contribs) (Change to TipImported template + use pre + comment to person who cleaned tip) |
(Move categories to tip template) |
||
Line 8: | Line 8: | ||
|version=7.0 |
|version=7.0 |
||
|rating=6/3 |
|rating=6/3 |
||
⚫ | |||
+ | |category2= |
||
}} |
}} |
||
'''git grep <pattern>''' searches for a pattern in a currently selected git branch. This adds ''':G <pattern>''' command to run the command from within Vim. |
'''git grep <pattern>''' searches for a pattern in a currently selected git branch. This adds ''':G <pattern>''' command to run the command from within Vim. |
||
Line 54: | Line 56: | ||
---- |
---- |
||
⚫ |
Revision as of 09:21, 25 April 2008
created June 18, 2006 · complexity basic · author Timo Hirvonen · version 7.0
git grep <pattern> searches for a pattern in a currently selected git branch. This adds :G <pattern> command to run the command from within Vim.
func GitGrep(...) let save = &grepprg set grepprg=git\ grep\ -n\ $* let s = 'grep' for i in a:000 let s = s . ' ' . i endfor exe s let &grepprg = save endfun command -nargs=? G call GitGrep(<f-args>)
You can also limit searching to files matching a pattern (git will do the pattern matching):
:G <pattern> -- '*.c'
Additions
The following addition will run git grep on the word under the cursor when Ctrl+X G is pressed.
func GitGrepWord() normal! "zyiw call GitGrep('-w -e ', getreg('z')) endf nmap <C-x>G :call GitGrepWord()<CR>
Comments
Thanks for cleaning this tip. I have just converted it to use our TipImported template, and have used <pre>...</pre> for the code (more robust than a space indent in the long term).
I removed the "Possibly needs its own tip" html comment on GitGrepWord() because I see no reason to split this quite small tip. Also, we are holding discussions in plain view (like this comment) to make it easier for people trying to clean up the imported tips (see the discussion guidelines for why we don't use the talk page).
I think this tip should very briefly mention what git is (particularly since it's not a traditional tool).
FYI Ephemeral comments, such as this, will be deleted later, although we like to keep the ==Comments== section to encourage people to comment here rather than on the talk page.
--JohnBeckett 00:34, 8 December 2007 (UTC)