문제

Fugitive.vim allows me to run git grep commands; unfortunately, the results are not stored in a quickfix-list, so I need to run :cw after a :Ggrep in order to have an easily parseable result list.

I would like to type :Ggr "def my_function" instead of:

:Ggrep "def my_function"
:cw

How can I define this :Ggr command in my .vimrc file?

EDIT

Once the :Ggr command is defined, I can map to git grep on the word under the cursor, which is really awesome:

nnoremap <C-F> :Ggr <cword><CR>
도움이 되었습니까?

해결책

This works for me:

:command -nargs=+ Ggr execute 'silent Ggrep!' <q-args> | cw | redraw!

다른 팁

You can use the <args> symbol to insert the arguments given to your custom command:

:command -nargs=+ Ggr execute 'Ggrep' <q-args> | cw

Note: As the :Ggrep command doesn't have the -bar argument, it cannot be chained, so :execute has to be used.

Already mentioned in one of the comments, but I thought the plugin-recommended solution on the fugitive.vim site deserved its own answer:

autocmd QuickFixCmdPost *grep* cwindow

(from: https://github.com/tpope/vim-fugitive)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top