mhinz / vim-grepper Goto Github PK
View Code? Open in Web Editor NEW:space_invader: Helps you win at grep.
License: MIT License
:space_invader: Helps you win at grep.
License: MIT License
Sometimes newlines don't get parsed correctly. I wish I could give steps to reproduce but I would have to investigate more. Opening in case someone experiences the same problem and can provide more information.
Possibly related? neovim/neovim#1574
Imagine I have two files. One of them opened in current window.
1.txt
foo
2.txt
foo
Then I'm searching something with Ag command.
I'd like that foo
in buffer that contains 1.txt would be highlighted after search is ended. And when switching to next quickfix item which would be 2.txt foo
also be immediately highlighted.
I've thought and asked about it and I think that this is doable. You need only two things
The first can be done in two ways I think. One is you can make search program output line, column of the match start and match only. This way you would know end column by adding match length to column.
Second is search for color codes in lines and because this color codes would wrap the match you can extract match itself.
I've following configuration:
command! -nargs=* -complete=file GG Grepper! -tool git -open -switch -query <args>
command! -nargs=* -complete=file Ag Grepper! -tool ag -open -switch -query <args>
nnoremap <Leader>* :<C-u>execute "GG " . expand("<cword>") <Bar> cw<CR>
nnoremap <Leader>gs :Grepper! -tool git -open -switch<CR> " mnemonic is git search
nnoremap <Leader>ag :Grepper! -tool ag -open -switch<CR>
After I use <Leader>*
command, s key gets overwritten.
Here is the output of :verbose nmap s
pressing s in normal mode, tries to make new buffer, from word under the cursor
Hello again,
I'm trying to building my own command around :Grepper
, however I don't know how I should escape a query when feeding it to the -query
flag. I have tried shellescape
and escape
but none worked. When I try to grep something using the built-in operator, it seems that the query is shellescaped.
Any insight is appreciated.
It'd be nice to be able to position the quick fix window that opens up exactly how you want it.
I tried creating a mapping to not open the quick fix window with the flag 'noopen' and then open it with how I want, say 'bot copen' but this doesn't work because vim-grepper calls 'cclose' if nopen is set which closes the quickfix window right after its open where I want it.
Is there any way to get around this? For now I just changed the command that opens the quick fix window from 'copen' to 'bot copen'. copen
I'm about to make :Grepper
more flexible, so that <plug>(Grepper)
can be removed.
After this change it will be possible to have multiple mappings to :Grepper
with different configurations. I'm aiming for:
nnoremap <leader>sg :10Grepper! -open -noswitch -tool git
nnoremap <leader>sa :5Grepper -tool ag
Both mappings will open with search prompt with the provided configuration.
:Grepper -search foo
will skip the prompt and start a search right away with the default tool. That's useful for people who need the advanced file completion of commands. They could map something like:
nnoremap <leader>sa :Grepper -tool ag -search<space>
Then they would call it like this: <leader>sa
, foo /thi<tab>/is/a/direc<tab>
. The search prompt itself supports simple file completion, but unfortunately it can't be as good as the built-in file completion for commands, so this will be useful to some people.
It would be nice if prompt mode had the equivalent of -complete=file
. Since it currently doesn't, I'm searching in command mode instead:
" :Rg or double-backslash for Grepper command
command! -nargs=+ -bang -complete=file Rg GrepperRg <args>
nmap \\ :Rg<Space>
Vim now supports async jobs.
Here is an example on using it. https://github.com/prabirshrestha/async.vim
I launch Grepper -tool ag -open -switch
in neovim 45b37 (<1 week) and then I launch a search for which I know for sure there are results. The research failed because it is interrupted by an error:
ERR: Skipping ./files-0/tmp/socket2: Error opening file: No such device or address
Erreur détectée en traitant function <SNR>96_on_stderr :
ligne 1 :
E900: Invalid job id
It happens systematically.
While I am searching text containing "(" (like function name), I get following error.
git grep -n> do(/bin/bash: -c: line 0: syntax error near unexpected token (' /bin/bash: -c: line 0:
git grep -n do( 2>&1| tee /tmp/vwNfw38/2'
I think "(" should be escaped somehow, or entire text should be covered by quotation marks.
Hi Marco, thank you for such a useful plugin, it's definitely the best grep plugin out there.
Is it possible to add directory completion in prompt? We can use <C-P>
or <C-N>
to toggle tools and reserver <TAB>
for completing directory, just like when using the -query
flag?
:vimgrep
is actually the only grep I need async for. What do you think?
https://github.com/ervandew/ag provides a neat feature, which converts simple regular expressions back and forth, e.g. \<
/\>
to \b
.
This allows you to use e.g. the Vim flavour in the prompt, and it will be converted for the external program(s).
See https://github.com/ervandew/ag/blob/master/autoload/ag.vim#L195
It seems to be done only with -open
(
vim-grepper/autoload/grepper.vim
Lines 450 to 452 in 57f7669
The following pattern could be used (because the title
arg is new):
try
call setqflist(getqflist(), 'r', qftitle)
catch /E118/
endtry
I'm using the following configuration in order to customize the tools available for grepping:
let g:grepper = {
\ 'tools': ['ag', 'csearch'],
\ 'dispatch': 1,
\ 'open': 1,
\ 'switch': 0,
\ 'jump': 0,
\ 'ag': {
\ 'grepprg': 'ag --nogroup --nocolor --column',
\ 'grepformat': '%f:%l:%c:%m',
\ },
\ 'csearch': {
\ 'grepprg': '~/gocode/bin/csearch -n',
\ 'grepformat': '%f:%l:%m',
\ }}
Then, using the command :Grepper
only shows ag
and hitting TAB
doesn't change to csearch
.
Also, when running the command :Grepper -tool csearch
fails with an error No such tool: csearch
. With :Grepper -tool ag
works fine.
Grepper version d66c5fb
When I press escape while typing a query, the query is run like I pressed enter instead of cancelled. I think it should be cancelled.
When I search I can see Job Control is being used, but my view still ends up locking.
It might be the quickfix window though locking it when results come back. Have you seen this happen when you have large results sets? Like 10k?
I know that greppers allows you to create custom commands as wrapper but it would be nice if you could create your own operators as well. For example, I'd like a custom operator that adds the literal -Q
flag to a search.
awesome plugin!
Probably user error -- but I can't figure out how to specify args that are passed directly to the tool. For instance, with ag, I'd like to have a mapping that searches only .txt files:
nnoremap <leader>st :Grepper! -tool ag -cword! -G"^.+\.txt$" <cr>
..where the -G argument is passed directly to ag. The thing above doesn't seem to work - is there a way to specify tool specific options like this?
currently I'm using
let w:testing = 1
but it would be great to have a proper way to do that 😜
Thanks for this plugin! I was using https://github.com/ervandew/ag before.
I think it would be nice to automatically use <cword>
when no input for a search term was provided.
I have the following mapping and would like to just press Enter again to use <cword>
(the word under the cursor):
n ,a * :Grepper -tool ag -noopen -noswitch<CR>
The workaround (which is sensible) is to use <ctrl-r><ctrl-w>
, but an empty input could be handled in the same way?!
A custom completion for :Grepper
with the available options would be nice to have.
It would be nice to have an option to open files from quickfix list. I'd like to open file in current buffer or in a new tab.
Is there a way to achieve this? Sorry if it is obvious and I've overlooked something. I didn't find anything in the docs.
When I do gsw
, it jumps to the first match. Is it possible to stop the jump?
I tried :
nmap gs <plug>(GrepperOperator)!
It doesn't work
After reading the documentation I failed to find anything related to this feature I'd like to have. My apologies if I missed it and it is indeed documented.
So, I have fairly large project and your plugin is really useful when refactoring and quick searching for things am not sure of their location. However, I do have libraries/
directory which is filled with some annoying stuff which always makes my quickfix window unreadable. It would be incredibly useful if we could globally specify ignore list for search, but also have an option to specify ignore before starting a search.
Thanks!
It would be sweet with a feature that fall back to the next tool in the tools list when the first one fails or have no matches.
My use case is that I prefer to use git grep
over ag
but when not in a git dir I want ag
to do the searching since git grep
fails and ag
is the next tool in my tools list.
Any chance we can get the search terms highlighted? I'd imagine it'd be something like:
let @/="foo"
With both jump
and open
I've found that jumping should be done after opening, otherwise I've ended up in the quickfix list.
That might be related to (i.e. caused by) #44?!
<escape>
to cancel the search<ctrl-c>
does.Hi,
I think I found a bug with <tab>
mapping in cli mode. Here's how I can consistently reproduce it:
,g
to get into vim-grepper modetab
a couple times:
)tab
produces E492: Not an editor command: $$$mAgIc###
I use vanilla vim 7.4 patch 768.
Thanks
Hi,
I so badly wanted a plugin like this for a long, long time. Thank you for working on it!
I'm curious, is there a way to get operator pending mode working? I skimmed the source, but couldn't find this.
Basically, with gs
being the vim-grepper mapping, I want to use the plugin like this gsiw
to grep for the "inner word". Another example often used in practice is gsi"
.
Thanks
In Neovim while current buffer file type is coffee, any search attempt results 0 matches.
In Vim it is ok.
I use kchmck/vim-coffee-script plugin for coffeescript
To be consistent with other command windows like q:
, vim-grepper should only execute the search if the user hits enter. If the users quits the window with :q, the search should be cancelled.
Step to repro:
:Grepper
:q
(I'm using version b8f52fc)
Would be great with support for ripgrep: https://github.com/BurntSushi/ripgrep
First of all, thanks a lot for sharing this, the plugin looks awesome and I think it has a bright future ahead.
Now, I have a question. I'm quite used to hit tab to autocomplete the path of my search location. My typical flow is: :Ag "Search query" some<tab>where/in/my/pro<tab>ject/<CR>
.
With vim-grepper
, I have to type the whole path: gs -> "Search query" somewhere/in/my/project<CR>
, because hitting <tab>
changes the search program. How could I get the path to autocomplete?
Thanks and keep up the great work! 👍
vim8 and windows 10
pt is installed.
Trying to
:GrepperPt something<CR>
returns nothing although there is 'something' in the file.
Next thing is:
:GrepperPt<CR>
Error detected while processing function <SNR>77_on_exit:
line 10
E108: No such variable: "s:id"
Calling :GrepperRg
with a string beginning with a hyphen leads to an error:
:GrepperRg '-foo'
1 || Unknown flag: '-f'
2 ||-
3 || Usage: rg [options] -e PATTERN ... [<path> ...]
4 || rg [options] <pattern> [<path> ...]
5 || rg [options] --files [<path> ...]
6 || rg [options] --type-list
7 || rg [options] --help
8 || rg [options] --version
[Quickfix List] rg --no-heading --vimgrep -i '-foo' 1,1 All
Nothing special is in my vimrc for that example. I get the same result when running the command without the quotes, and when using <Plug>(GrepperOperator)
maps.
Adding --
to the rg command is a workaround:
let g:grepper.rg = { 'grepprg': 'rg --no-heading --vimgrep -i --' }
When I've used ag.vim I've used to multiline quickfix items, because with plugin, that makes quickfix editable, it gave me ability to do project wide search and replace easily without worrying to much about how good my regex is (because I could've used regex to search for something and then macros or cgn
to actually replace what I need).
Then I've started to use this plugin and noticed that quickfix items always contain one line only. I've search for it and found that it's supposedly hard to display multiline quckfix items. But then ag.vim somehow have done that. I've searched through the code of ag.vim and haven't found anything unusual about how they treat quickfix menu.
Could you add this to your plugin?
I use sift
almost exclusively in CLI. It seems the default Grepper configuration for sift
includes .
as a search path indicator. For all I see this setting makes restricting the search operation to a subdirectory quite difficult. Due to that I made a simple setup with the dot removed (as it is not mandatory when running sift
via command line):
let g:grepper = {
\ 'next_tool': '<C-j>',
\ 'tools': ['sift', 'siftp'],
\ 'sift': {
\ 'grepprg': 'sift -n --binary-skip $*',
\ 'grepformat': '%f:%l:%m',
\ 'escape': '\+*?^$%#()[]' }
\ }
command! -nargs=* -complete=file Sift Grepper -tool sift -query <args>
nnoremap gs <Plug>(GrepperOperator)
xnoremap gs <Plug>(GrepperOperator)
It seems to work well enough with 'vanilla' Vim (7.4, patches 1-1529, pi-rho PPA @ Ubuntu 14.04).
The same config yields the E40: can't open error file
error with Neovim (0.1.3-dev from 'official' PPA) if I provide only the search pattern and not the path:
Error detected while processing function <SNR>214_on_exit:
line 4:
E40: Can't open errorfile /tmp/user/1000/nvimknG5hR/2
No matches found.%
If I provide the path (either a directory name or just the dot) it works fine.
The behaviour persists if I load vim
and nvim
with only my vim-plug settings (only set nocompatible
, filetype plugin indent on
, and standard vim-plug startup).
There's a Neovim error I should take care of first most likely (and I just started using it), but perhaps you have some idea what might cause such behaviour on Grepper's part?
Thank you in advance for any answer and also for all the work on your plugins 😄
What is the proper way to add custom greppers? Prior to e1a48d0 I was using this configuration:
let g:grepper = {
\ 'tools': ['git', 'sift', 'ag', 'pt', 'ack', 'grep'],
\ 'sift': {
\ 'grepprg': 'sift -i -n --no-color --no-group $* .',
\ 'grepformat': '%f:%l:%m',
\ 'escape': '\+*^$()[].',
\ }}
...and it worked as expected. After that commit (and b1c1904), I see the following when invoking Grepper:
grepper: Ignoring unknown key "sift".
Don't understand: sift
...and the following error when hitting <Tab>
at the Grepper prompt:
##Error detected while processing function grepper#parse_command..<SNR>213_start..<SNR>213_prompt..<SNR>213_tool_escape..<SNR
>213_option:
line 5:
E716: Key not present in Dictionary: sift
E15: Invalid expression: s:options[s:options.tools[0]]
Error detected while processing function grepper#parse_command..<SNR>213_start..<SNR>213_prompt..<SNR>213_tool_escape:
line 4:
E715: Dictionary required
Error detected while processing function grepper#parse_command..<SNR>213_start..<SNR>213_prompt..<SNR>213_prompt..<SNR>213_option:
line 5:
E716: Key not present in Dictionary: sift
E15: Invalid expression: s:options[s:options.tools[0]]
Error detected while processing function grepper#parse_command..<SNR>213_start..<SNR>213_prompt:
line 20:
E171: Missing :endif
Error detected while processing function grepper#parse_command..<SNR>213_start:
line 14:
E171: Missing :endif
I've set up the following mappings, as suggested by the documentation:
nmap gs <plug>(GrepperOperator)
xmap gs <plug>(GrepperOperator)
Up to and including commit c244743 the behaviour when using those mappings is as outlined in the documentation. That is, the motion selection is used to populate the search prompt.
Beginning with commit 7640a44, the behaviour changes. The search query appears to be executed as soon as the mapping is used, bypassing the presentation of the search prompt to the user. This causes problems in my use case, where git grep is the default search tool. If I'm in a file that is not part of a git repo and I use those mappings, git grep is executed by default, and the search will always return zero results.
I'm running the latest nightly build of neovim, and haven't had the chance to see if the issue is present in vim as well.
Thanks for your help!
Hey, thanks for the great plugin! I'm finding it really useful.
Up until now, I've been using :Ggrep from Tim Pope's vim-fugitive plugin when grepping through a git repo. With that plugin, regardless of the present working directory (provided that it's somewhere within the git repo), :Ggrep will search through the whole repo for the search term. vim-grepper seems to follow the default git grep behaviour of searching the current directly and below.
Is there a way to modify the behaviour of git grep in vim-grepper to have it search the whole repository regardless of which directory in the repo we are currently in?
In case the tool returns an error, vim-grepper should display it and not consider it to be matches.
When leaving out the "query" with "ag", you will get the following line in the quickfix list, and the message "Found 1 matches." is displayed:
|| ERR: What do you want to search for?
I think the quickfix/location list should not get filled at all, and vim-grepper should display the error using echohl
/ echom
. This might not be easy with the synchronous Vim method, but Neovim's on_exit
gets the status / exit code of the tool.
...and stays %f:%l:%c:%m,%f:%l:%m
after the first run of grepper.
Proposed patch
diff --git a/autoload/grepper.vim b/autoload/grepper.vim
index 08e1509..e0b0c9a 100644
--- a/autoload/grepper.vim
+++ b/autoload/grepper.vim
@@ -407,8 +407,8 @@ endfunction
" s:store_errorformat() {{{1
function! s:store_errorformat(flags) abort
let prog = s:get_current_tool(a:flags)
- let s:errorformat = has_key(prog, 'grepformat') ? prog.grepformat : &errorformat
- let &errorformat = s:errorformat
+ let s:errorformat = &errorformat
+ let &errorformat = has_key(prog, 'grepformat') ? prog.grepformat : &errorformat
endfunction
" s:restore_errorformat() {{{1
I would like just the simple mapping to search for the current word in the current buffer - I've tried:
nnoremap <leader>sf :Grepper -tool ag -cword -noprompt $* %<cr>
...which doesn't produce errors when invoked, but tells me "no matches" which of course is nonsense because the current word is by definition in the current file (the buffer is saved). How can I debug what's going wrong here?
If I'm on Grepper's commandline and type a search term, and then cycle to the next_tool it's populating the search with a previous term and not preserving my current search. Even if you don't type anything and have a blank commandline, cycling will populate the previous search term as well. Please let me know if that doesn't make sense or you need a demonstration.
These are my applicable Neovim settings, if they should matter in this case:
Plug 'mhinz/vim-grepper'
let g:grepper = {
\ 'tools': ['ag', 'git', 'grep'],
\ 'open': 1,
\ 'switch': 1,
\ 'jump': 0,
\ 'next_tool': '<C-G>',
\ }
nnoremap <C-G> :Grepper -tool ag<CR>
nnoremap <Leader>* :Grepper -tool ag -cword!<CR>
nmap gG <plug>(GrepperOperator)
xmap gG <plug>(GrepperOperator)
command! -nargs=* -complete=file Ag Grepper -tool ag -query <args>
Adding quickfix mappings without an option to disable them makes this plugin interact poorly with plugins like https://github.com/stefandtw/quickfix-reflector.vim.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.