Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get :Ag results to populate the quickfix list #586

Closed
5 of 11 tasks
trevordmiller opened this issue Feb 23, 2018 · 13 comments
Closed
5 of 11 tasks

How can I get :Ag results to populate the quickfix list #586

trevordmiller opened this issue Feb 23, 2018 · 13 comments

Comments

@trevordmiller
Copy link

  • Category

    • Question
    • Bug
    • Suggestion
  • OS

    • Linux
    • macOS
    • Windows
    • Etc.
  • Vim

    • Vim
    • Neovim
  • Make sure that you have the latest version of fzf and fzf.vim

  • Check if your problem is reproducible with a minimal configuration

I've read in a few places that you can use :Ag and then CTRL-A to populate the quickfix list with the results (like how the native :grep does). But I can't get it to work. I've tried with:

  • :Ag => enter > fuzzy search => CTRL-A
  • :Ag {search} => enter => CTRL-A
  • :Ag {search} => enter => fuzzy search => CTRL-A

How can I get :Ag results to populate the quickfix list?

@jesseleite
Copy link
Contributor

jesseleite commented Feb 24, 2018

@trevordmiller I literally just figured this out today! Was gonna write a blogpost about it, but haven't got to it yet. You have to customize a bit in your vimrc, but it's pretty simple (see here).

First, you might have to map CTRL-A to select all, because it's actually ALT-A by default. On macs, ALT-A will usually output a å.

Second, you'll need to map and add the CTRL-Q function to populate quickfix from :Ag.

Once these are done, you should be able to CTRL-A CTRL-Q to mark all items and populate quickfix with them. You can also use TAB to mark individual items, then CTRL-Q to populate quickfix with just those items.

Hope it helps!

@trevordmiller
Copy link
Author

@jesseleite Thank you! That would be nice if no extra config was required though - not sure why ALT-A was chosen if it doesn't work on macs...

@junegunn
Copy link
Owner

See #54

@junegunn
Copy link
Owner

junegunn commented Feb 24, 2018

Especially this comment: #54 (comment)

Also, https://stackoverflow.com/questions/18923765/bash-keyboard-shortcuts-in-iterm-like-altd-and-altf

@trevordmiller
Copy link
Author

@junegunn Ok so I am using iTerm2 so I enabled Esc+ - now alt-a selects the items...but how do I populate them in the quickfix without custom config? I don't see this documented anywhere in the README or :h fzf-vim.

@trevordmiller
Copy link
Author

trevordmiller commented Feb 24, 2018

Ok I finally figured it out - it's:

  • :Ag {search}enter
  • you can type to filter results down
  • enter to go to individual item

Or you can select multiple items:

  • alt-a to select items (if using iTerm2 on macOS, you need Esc+ turned on for alt/option keys)
  • ald-d to deselect items
  • tab or shift-tab can be used to toggle individual selected items
  • enter to populate quickfix list with selected items

It would be great if this could be added to the documentation :) Thanks!

@jesseleite
Copy link
Contributor

Oh wait you an populate quickfix without any custom config?

@trevordmiller
Copy link
Author

@jesseleite Yep. Select items using tab, alt-a, or alt-d then hit enter :)

@jesseleite
Copy link
Contributor

Wow I feel stupid... how did I miss enter to populate quickfix when multiple items are selected 😅 Gonna drop my CTRL-Q mapping 👌

Also regarding alt outputting å, I'm using Hyper and just found that I can put modifierKeys: { altIsMeta: true } in my config to be able to ALT-A and ALT-D.

So my whole custom config is unnecessary, unless I want CTRL instead of ALT 😂 Not sure how I feel yet. I usually avoid ALT mappings because they feel awkward. Also, CTRL/CMD+A is usually the standard select all mapping in other apps. But I understand what Junegunn is saying about navigating to beginning of line too.

Anyway, thanks for sharing!

@eliasdaler
Copy link

@trevordmiller thanks for the tip!

Is is possible to make a script which will do this automatically? E.g. make a search function which will do:

  • :Ag some-string
  • wait for results
  • Alt-A
  • Enter

I want to be able to type:

:Ag some-string

and have it populate quickfix list automatically

@gauteh
Copy link

gauteh commented Aug 6, 2018

@eliasdaler Wouldn't that defeat the purpose of FZF? If you are not filtering manually afterwards? vim-grepper can do that. Though the only thing missing from FZF grepping (compared to vim-grepper for me) now is a way to get operators for grepping for current word or visual selection.. maybe that already exists as well?

@traviswaelbro
Copy link

@eliasdaler the only thing missing from FZF grepping is a way to get operators for grepping for current word or visual selection.

You should be able to use Vim's built-in mapping (<Ctrl-R><Ctrl-W>) for pasting current word into any of the FZF commands.

As for pasting visual selection, the best way I've found so far is to yank the visual selection, then paste from the yank register (<Ctrl-R><Ctrl-">).

You should be able to set up either of these into a custom mapping to run whatever FZF command for text under cursor or text in yank (or any other) register.

@javidjamae
Copy link

@traviswaelbro For the yank register I use <Ctrl-R>". I tried <Ctrl-R><Ctrl-"> and it doesn't work.

Here is the mapping I use to search for the yank register:

map <leader>" :Ag! "<C-r>"" -Q<CR>
  1. I map <leader>", which for me is , then "
  2. I use Ag! so it searches but doesn't switch the current buffer to the first result by default
  3. I paste the yank register into quotes
  4. I use -Q to search for the exact text, not a regular express

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants