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

Make :Ag not match file names, only the file content #346

4 of 9 tasks
maximbaz opened this issue Mar 22, 2017 · 17 comments
4 of 9 tasks

Make :Ag not match file names, only the file content #346

maximbaz opened this issue Mar 22, 2017 · 17 comments


Copy link

  • Category
    • Question
    • Bug
    • Suggestion
  • OS
    • Linux
    • macOS
    • Windows
    • Etc.
  • Vim
    • Vim
    • Neovim

Since there is a command :Files that can search files by name, I'd like to configure :Ag to only look at the file contents, not at the file names.

I'll demostrate my case below, my question is: can this be achieved today, maybe with some configuration?

To see why this is an annoying issue, create a file called demo.txt, put 20 lines each having a random number, and on the 21st line write demo. Then use :Ag demo to search for this string.

Expected: you find only one occurrence.
Actual: you also find 20 irrelevant occurrences.


Copy link

Try this:

command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, {'options': '--delimiter : --nth 4..'}, <bang>0)

Copy link

It looks like magic, but works beautifully, thanks @junegunn! 🎉

Copy link

I'm trying to figure out how to run that command on startup. Any tips?

Copy link

Put it in your .vimrc @mbylstra

Copy link

mbylstra commented Feb 23, 2018

🤦‍♂️ I thought I had to prepend it with autocmd which wasn't working. Thanks!

Copy link

Is it possible to combine this with my current Ag tweaks?
I have the following:

command! -bang -nargs=* Ag
  \ call fzf#vim#ag(<q-args>,
  \                 {'options': '--delimiter : --nth 4..'}, " Can't add this
  \                 <bang>0 ? fzf#vim#with_preview('up:60%')
  \                         : fzf#vim#with_preview('right:50%:hidden', '?'),
  \                 <bang>0)

Copy link

@junegunn could you please help, is it possible to combine preview options with search only by files with Ag?

Copy link

* fzf#vim#with_preview([[options], preview window, [toggle keys...]])

So you have to write

fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'up:60%')

Copy link

@junegunn Thank you so much, you've saved my day!

Copy link

jssee commented Oct 11, 2018

@junegunn i used the method you described above but im experiencing some strange behavior.

i want to have 2 options:

  1. use the default :Ag behavior of searching all file names and content.
  2. use Ag to only search the current file contents.

Im noticing that with my current config, this only works some in some projects, but not others. and on occasion, it will only allow me to use option 2 once in a project, and every time afterwards it goes back to the default behavior. do you have any idea why this is?

here is my config:

nnoremap <Leader>sa :Ag<CR>
nnoremap <Leader>ss :Ag!<CR>

command! -bang -nargs=* Ag
  \ call fzf#vim#ag(<q-args>,
  \                 <bang>0 ? fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'up:60%')
  \                         : fzf#vim#with_preview('right:50%:hidden', '?'),
  \                 <bang>0)

EDIT: added video to demonstrate issue

Copy link

Try this:

command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, {'options': '--delimiter : --nth 4..'}, <bang>0)

Thanks for this! Can anyone care to explain (briefly) what this exactly does?

Copy link

aos commented May 8, 2019

Try this:

command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, {'options': '--delimiter : --nth 4..'}, <bang>0)

Thanks for this! Can anyone care to explain (briefly) what this exactly does?

Basically, the {'options'...} part is passed into fzf. If you look at the man page for fzf, you'll notice you can pass a delimiter when searching, in this case our delimiter is colon :. Then we tell it to only search from the 4th item onwards... these are the file contents only.

If you look at the results of :Ag, it uses : as the separator for each result.

Copy link

Can anyone help me write the equivalent for Ripgrep? This:

command! -bang -nargs=* Rg call fzf#vim#rg(<q-args>, {'options': '--delimiter : --nth 4..'}, <bang>0)

Gives me the error
E117: Unkown function: fzf#vim#rg

Copy link

fabiomcosta commented Aug 5, 2019

@danamkaplan fzf#vim#rg function doesn't exists, as the error message says, so you have to use the fzf#vim#grep function.

I got it working with the following command:

command! -bang -nargs=* Rg
  \ call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case ".shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'}, <bang>0)

Got that from

\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case ".shellescape(<q-args>), 1, <bang>0)',
and then added the same argument that has been provided to Ag.

Copy link

Oh just noticed this has also been suggested at #714 (comment)

Copy link

avral commented Aug 29, 2019


yous added a commit to yous/dotfiles that referenced this issue Oct 16, 2019
Copy link

buschco commented Jul 8, 2020

Try this:

command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, {'options': '--delimiter : --nth 4..'}, <bang>0)

This made my Preview window disappear. How can I bring it back with this options?

I think I figured it out:

command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}), <bang>0)

eliasnorrby added a commit to eliasnorrby/dotfiles that referenced this issue Jan 27, 2021
I become bothered by the :Rg command matching filenames in the list of
search results returned by ripgrep. It has some uses, but most of the
time it makes it harder to find a good match (try searching for
'keybindings' in this repo for example).

I've set up three mappings calling different variants of the Rg command:

<leader>// : ripgrep results filtered by fzf, not matching filenames
<leader>/? : reload ripgrep results when query is updated
<leader>/f : call the standard Rg function (with filename matching)

- junegunn/fzf#1109 (comment)
- junegunn/fzf.vim#346 (comment)
github-actions bot pushed a commit to eliasnorrby/dotfiles that referenced this issue Mar 25, 2021
# [4.0.0](v3.0.0...v4.0.0) (2021-03-25)

### Bug Fixes

* **arch:** remove opacity digits from xresources ([82fa1b0](82fa1b0)), closes [#dd292d3](
* **arch:** use correct package for xinput ([c63c076](c63c076))
* **bspwm:** update class used for tmux rule ([a4bd3a3](a4bd3a3))
* **fzf:** change binding for sort toggle ([2f0e0d0](2f0e0d0))
* **fzf:** do not use sudo for yay ([3bfab25](3bfab25))
* **fzf:** fix fuzzy args on MacOS ([5a8f1a1](5a8f1a1))
* **fzf:** source keybindings depending on os ([b3be4c1](b3be4c1))
* **gcloud:** eliminate subshells from env.zsh ([ae66e51](ae66e51))
* **git:** add main to gbpurge exclusion ([55d0b79](55d0b79))
* **intellij:** disable easymotion ([df4830f](df4830f))
* **intellij:** fix windowing on arch ([d497130](d497130))
* **java:** call java version alias separately ([c3b8549](c3b8549))
* **java:** move java aliases to macos block ([ba17866](ba17866))
* **provision:** add check to aur package install ([43efba3](43efba3))
* **provision:** add missing gcloud key root configs ([b5999b3](b5999b3))
* **provision:** fix mktemp spelling ([ac9d1e4](ac9d1e4))
* **provision:** remove do_defaults from setup-linux ([7a14498](7a14498))
* **provision:** set npm prefix in extra-packages ([a329819](a329819))
* **provision:** use coc-nvim's flags on extension install ([076affe](076affe))
* **provision:** use new cask upgrade command ([bc78304](bc78304))
* **scripts:** juggle find arguments ([66350b0](66350b0))
* **ssh:** add macos config file ([ab78e6e](ab78e6e))
* **tmux:** remove load average symbol ([f498251](f498251))
* **vim:** update coc eslint config key ([0d55559](0d55559))
* **work:** patch vpn settings for macos ([8080b21](8080b21))
* **xkb:** add shebang to ([c2021c9](c2021c9))
* **xkb:** kill xcape before calling ([607cb94](607cb94))

### Features

* **alacritty:** add glyph offsets on arch ([a82c501](a82c501))
* **alacritty:** bind paste ([9b68142](9b68142))
* **alacritty:** create tmux_alacritty wrapper ([622c9f1](622c9f1))
* **alacritty:** make theme setter work on all platforms ([c0ade4a](c0ade4a))
* **alacritty:** make use of alacritty config imports ([6e1dc93](6e1dc93)), closes [#38](#38)
* **alacritty:** use ~ for config imports ([31dad08](31dad08)), closes [#38](#38)
* **alacritty:** use a brighter bright black ([0a09db3](0a09db3))
* **alacritty:** use mononoki font ([aa384ca](aa384ca))
* **arch:** add additional keyserver ([2d5e09c](2d5e09c))
* **arch:** add focus_or_run script ([eec2ca1](eec2ca1))
* **arch:** add Xresources ([68358be](68358be))
* **arch:** set mouse sensitivity with xinput ([c805c91](c805c91))
* **bspwm:** launch dunst on startup ([f0736d1](f0736d1))
* **bspwm:** open chrome on desktop 6 ([f1015f6](f1015f6))
* **bspwm:** set active color to cyan ([3e04baa](3e04baa))
* **cli:** conditionally link different boomrcs ([8a6c3b1](8a6c3b1))
* **dunst:** add topic config ([b6ce8de](b6ce8de))
* **dunst:** rewrite default config ([b7a8468](b7a8468))
* **feh:** create topic config ([6cfba4d](6cfba4d))
* **fzf:** add pf alias for fuzzy pacman search ([b91bb02](b91bb02))
* **fzf:** enlarge pacman preview window ([71f4043](71f4043))
* **fzf:** filter chromium's history ([941a8fe](941a8fe))
* **fzf:** remove file path completion binding ([1ca4f5c](1ca4f5c))
* **fzf:** source completion ([9afad20](9afad20))
* **picom:** add background blurring ([86a6a3d](86a6a3d))
* **picom:** add shadows ([36a78c7](36a78c7))
* **picom:** enable vsync ([7871c05](7871c05))
* **picom:** experiment with fading ([59a950a](59a950a))
* **picom:** run with --experimental-backends ([d6127a3](d6127a3))
* **picom:** slightly reduce alacritty transparency ([e3fac8a](e3fac8a))
* **picom:** use the glx backend ([5fa0c24](5fa0c24))
* **polybar:** hide polybar in bspwm fullscreen ([545e44a](545e44a))
* **polybar:** modify example config ([95f51db](95f51db))
* **polybar:** update module icons ([a6b999a](a6b999a))
* **provision:** add optional condition to links ([2c8f15f](2c8f15f))
* **provision:** add rename option to topic links ([742657a](742657a))
* **provision:** become for pacman ([4934760](4934760))
* **provision:** install ansible roles in post ([a8d9d8c](a8d9d8c))
* **provision:** install aur packages ([c9cae53](c9cae53))
* **rofi:** add topic config ([1fe4167](1fe4167))
* **rofi:** launch rofi with super + space ([5085388](5085388))
* **rofi:** use dank mono font ([7c06945](7c06945))
* **sxhkd:** focus or run alacritty ([e2e6d21](e2e6d21))
* **sxhkd:** focus or run chromium ([040ff9c](040ff9c))
* **sxhkd:** map hyper + {1-9} to tmux windows ([254af0f](254af0f))
* **tmux:** choose copy tool based on platform ([91a4d50](91a4d50))
* **vim:** make cursorline light blue ([d0560cb](d0560cb))
* **vim:** use unnamedplus for clipboard ([5cd5c30](5cd5c30))
* **vscode:** conditionally set vscode_home ([93cae5f](93cae5f))
* **xkb:** add topic config ([cfa6b7f](cfa6b7f))
* **xkb:** map right alt to hyper key (mod3) ([0c41084](0c41084))
* **zsh:** remove '/' from WORDCHARS ([4b95c63](4b95c63))
* add become key to topic config ([798738f](798738f))
* **alacritty:** use some transparency ([7e42ee5](7e42ee5))
* **arch:** add and autostart dropbox ([659dcd9](659dcd9))
* **arch:** add topic base/arch ([ae6be72](ae6be72))
* **arch:** add topic config ([e191329](e191329))
* **arch:** create wrapper script for spotify ([05faf26](05faf26)), closes [/](
* **arch:** enable kafka topic ([c213e5d](c213e5d))
* **arch:** handle focus of withdrawn windows ([afe0962](afe0962))
* **arch:** improve ([0546b90](0546b90))
* **arch:** make aur buider a system user ([ec28d99](ec28d99))
* **bspm:** remove example config defaults ([796b3c4](796b3c4))
* **bspwm:** add 1password desktop rule ([689eac8](689eac8))
* **bspwm:** add checks for dependencies ([47ed18e](47ed18e))
* **bspwm:** add desktop rule for slack ([2eed97a](2eed97a))
* **bspwm:** add intellij desktop rule ([0b0b33e](0b0b33e))
* **bspwm:** add topic config ([07f76be](07f76be))
* **bspwm:** add topic wm/bspwm ([f8a6c2b](f8a6c2b))
* **bspwm:** make use of multiple monitors ([f8126d4](f8126d4))
* **bspwm:** reduce window gap to 10 ([d66c0f5](d66c0f5))
* **bspwm:** update for triple monitor setup ([16d0cfd](16d0cfd))
* **bspwm:** update window rules ([d2a125b](d2a125b))
* **bspwmrc:** configure monitors with xrandr ([01b1ab2](01b1ab2))
* **dotnet:** add lang/dotnet topic ([4decabc](4decabc))
* **dunst:** only show notifications on main monitor ([9db7f7b](9db7f7b))
* **emacs:** set font based on _os ([c1fa2b0](c1fa2b0))
* **fzf:** add fuzzy argument selection ([ebd53b7](ebd53b7))
* **gcloud:** source path and completion ([4568545](4568545))
* **git:** add gl and glnr aliases ([1f83273](1f83273))
* **git:** add gprd function ([641cf78](641cf78))
* **git:** add grv alias ([801f574](801f574))
* **hammerspoon:** add rider app mapping ([72ecb57](72ecb57))
* **hammerspoon:** add umlauts to app mode ([b7c2c04](b7c2c04))
* **intellij:** add compile project mapping ([b654e0c](b654e0c))
* **intellij:** add go mapping for file outline ([bfcde52](bfcde52))
* **intellij:** add hide coverage mapping ([9d74f44](9d74f44))
* **intellij:** add keybinds for navigating changes ([22aae08](22aae08))
* **intellij:** add mapping to create class ([d5fdf21](d5fdf21))
* **intellij:** add mapping to insert semicolon ([bc0e519](bc0e519))
* **intellij:** add mappings for hippie completion ([b651f3f](b651f3f))
* **intellij:** default to no line numbers ([f925564](f925564))
* **intellij:** harmonize ]d / ]e mappings ([66ba046](66ba046))
* **intellij:** map double space to GotoFile ([dd77421](dd77421))
* **intellij:** refine line number toggles ([6adb51f](6adb51f))
* **intellij:** revamp window closing mappings ([c4272d3](c4272d3))
* **intellij:** sort sections alphabetically ([16acda6](16acda6))
* **intellij:** switch to intellij ultimate ([7136da5](7136da5))
* **intellij:** try to mimic unimpaired's ]<space> ([350c5be](350c5be))
* **java:** rework JAVA_HOME env ([6de7264](6de7264))
* **kubernetes:** add aliases.zsh ([c87e801](c87e801))
* **macos:** add balenaetcher ([c350b2e](c350b2e))
* **macos:** enable kafka topic ([19b6660](19b6660))
* **node:** add npm to pacman_packages ([9e643fe](9e643fe))
* **node:** create a dir for global npm packages ([e80888d](e80888d))
* **picom:** add topic config ([1073b6a](1073b6a))
* **picom:** launch picom on login ([ebbec14](ebbec14))
* **picom:** make emacs transparent ([a9280bd](a9280bd))
* **polybar:** add alsa module ([4a79612](4a79612))
* **polybar:** add suspend to power menu ([c1ccbd9](c1ccbd9))
* **polybar:** add topic config ([1371137](1371137))
* **polybar:** add topic panel/polybar ([b972739](b972739))
* **polybar:** add vpn modules ([ef3f6c7](ef3f6c7))
* **polybar:** blacklist num lock indicator ([1a8b444](1a8b444))
* **polybar:** hide the tray ([88fead9](88fead9))
* **polybar:** join vpn modules ([bbd34ad](bbd34ad))
* **polybar:** try to make tray behave ([83657d1](83657d1))
* **polybar:** use desktop %name% for labels ([cc48586](cc48586))
* **polybar:** use mononoki font ([14ab7a2](14ab7a2))
* **polybar:** use systemctl poweroff ([ff7634e](ff7634e))
* **provision:** add custom setup script for linux ([15230d6](15230d6))
* **provision:** add platform check to update-all ([6090cea](6090cea))
* **provision:** add support for pacman packages ([4538dfc](4538dfc))
* **provision:** check for executables in post-install ([1be0e93](1be0e93))
* **provision:** create ssh config dirs ([cd75749](cd75749))
* **provision:** ensure list of dirs exist ([80b82c8](80b82c8))
* **provision:** install coc extensions in post ([c3a4aa6](c3a4aa6))
* **provision:** make setup-linux executable ([d3ee543](d3ee543))
* **scripts:** add ([80823a1](80823a1))
* **scripts:** add work to git changes dirs ([e4fc645](e4fc645))
* **shell:** remove newline from _os helper ([a031eab](a031eab))
* **ssh:** add topic config ([b57b658](b57b658))
* **ssh:** include configs in config.d ([10e6e1a](10e6e1a))
* **ssh:** remove lifetime of unlocked keys ([af79d33](af79d33))
* **ssh:** use keychain ([8ce01b6](8ce01b6))
* **sxhkd:** add 1password keybind ([46b64a1](46b64a1))
* **sxhkd:** add binding to launch konsole ([641c5e3](641c5e3))
* **sxhkd:** add intellij keybind ([42a2e19](42a2e19))
* **sxhkd:** add slack keybind ([c370db2](c370db2))
* **sxhkd:** add topic config ([f76c89b](f76c89b))
* **sxhkd:** add topic keyboard/sxhkd ([e8f6602](e8f6602))
* **sxhkd:** add wallpaper swap keybind ([5b391bf](5b391bf))
* **sxhkd:** launch emacs with hyper + s ([347d84d](347d84d))
* **sxhkd:** launch ranger with hyper + r ([b74fc27](b74fc27))
* **sxhkd:** launch spotify with hyper + u ([6dd0847](6dd0847))
* **sxhkd:** quit apps with super + q ([7ac3118](7ac3118))
* **sxhkd:** use super + p to pin window ([2c47aa1](2c47aa1))
* **tmux:** add binding to highlight last link ([d4de5ba](d4de5ba))
* **tmux:** add scratch and dotfiles bindings ([6906b40](6906b40))
* **tmux:** add session list to status and keybinds ([ff3518a](ff3518a))
* **tmux:** disable active pane highlighting ([46d2999](46d2999))
* **tmux:** do not use session id for switching ([e4ba48a](e4ba48a))
* **tmux:** move session prompt to keybind ([8668943](8668943))
* **tmux:** relocate status elements ([0477fe6](0477fe6))
* **tmux:** skip the initial rename session prompt ([8fdbf62](8fdbf62))
* **vim:** add coc-groovy to coc-extensions ([4a3d3a3](4a3d3a3))
* **vim:** add CursorColumn highlight ([b172cb0](b172cb0))
* **vim:** add keybind to search project for selection ([dc90052](dc90052))
* **vim:** add keybind to toggle diff of windows ([af16609](af16609))
* **vim:** add scrollbind toggle ([4142c57](4142c57))
* **vim:** add tabular plugin ([ef9bb8e](ef9bb8e))
* **vim:** add vlog alias ([a82daa6](a82daa6))
* **vim:** brighten fzf's border ([8f53e36](8f53e36))
* **vim:** disable double cmdheight ([b479208](b479208))
* **vim:** enable coc-explorer file icons ([300c608](300c608))
* **vim:** map leader , to :History ([856ef05](856ef05))
* **vim:** update project-wide search functions ([9cef954](9cef954)), closes [/]( [/](
* **vim:** use editorconfig for shfmt settings ([67f34a6](67f34a6)), closes [#32](#32)
* **vim:** use standard tabline ([f0bf112](f0bf112))
* **work:** add base/work topic ([41adbdd](41adbdd))
* **work:** add vpn connection scripts ([a7d9c89](a7d9c89))
* **work:** add vpn_disconnect and provision sudo ([00ff1d0](00ff1d0))
* **zsh:** add chx and ns aliases ([5c754cb](5c754cb))
* **zsh:** add fuzzy ascii art font picker ([90525d6](90525d6))
* **zsh:** add sudoedit alias ([d74e781](d74e781))
* **zsh:** only attach to tmux on macos ([e38eaac](e38eaac))
* **zsh:** only use gls on macos ([2f5969a](2f5969a))
* **zsh:** remove . from WORDCHARS ([53ee31a](53ee31a))
* **zsh:** remove line numbers from fzf preview ([a4754c9](a4754c9))
* **zsh:** start ssh-agent on launch ([8181d45](8181d45))
* **zsh:** switch yq implementation on arch ([438f929](438f929))
* add linux.config.yml ([c891af2](c891af2))
* add pacman_packages to topics ([069ae0c](069ae0c))

* refactor!: rename root.config.yml ([c9cead7](c9cead7))


* Instead of a singular root.config.yml, use
<os>.config.yml's. This will force an update to the CLI.
samhh added a commit to samhh/dotfiles that referenced this issue Jun 10, 2021
flavono123 added a commit to flavono123/dotfiles that referenced this issue Jun 13, 2022
teedang19 pushed a commit to teedang19/dotfiles that referenced this issue Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests