Skip to main content
15 votes
Accepted

How to interactively search/grep with VIM?

I'm not sure this is what you're looking for, but maybe you could try fzf and fzf.vim. If you use vim-plug as a plugin manager, all you should have to do to install them, is to add these lines in ...
user9433424's user avatar
  • 6,148
12 votes
Accepted

How to load files as a quickfix window at start-up

Vim has a startup option -q to read a quickfix file. So we have options (depending on your shell): cmd > results vim -q results Or my favorite vim -q <(cmd)
D. Ben Knoble's user avatar
  • 26.6k
7 votes
Accepted

Exclude folder when searching files in working directory

Try the following: set wildignore=*/node_modules/* I just played a little with wildignore, so I don't know if it works in all cases. E.g. if you do a :vimgrep /pattern/ node_modules/** It will ...
Ralf's user avatar
  • 9,277
6 votes
Accepted

my ag shortcut chokes on spaces

Why It's Broken The problem is that you've used -bar in your command definition. This attribute is used to specify that you can use a | after an invocation of your new command e.g.: :Ag search_term | ...
Rich's user avatar
  • 32.2k
5 votes

Find all files matching a glob pattern and add it to the quickfix window

You can use the pattern \%^ to match the start of of the file. Using this, you could populate the quickfix list with the first line of all your markdown files, even empty ones. :vimgrep "\%^"...
Jake Grossman's user avatar
5 votes

Changing how the quickfix list displays matches

What I'd like to do is "add a column" to the quickfix list that displays that "type" (so, for @CHECK it would be CHECK, and so on) An input file and the desired quickfix window ...
user938271's user avatar
  • 5,987
5 votes
Accepted

Calling vimgrep so that results from the current file are on top?

You can sort the resulting quickfix list to give priority to current buffer, then run uniq() on it. Sadly you need to handle sorting quickfix items almost completely. For example the following will ...
Sato Katsura's user avatar
  • 4,019
4 votes
Accepted

How to use vimgrep recursively for specific file extensions?

You can use {} to specify different extensions: nnoremap <leader>f :vimgrep /<c-r><c-w>/j **/*.{c,h,txt} <bar> :copen <CR> Some suggestions: Use nnoremp unless you ...
Peter Rincker's user avatar
4 votes

Find all files matching a glob pattern and add it to the quickfix window

An alternative idea: don't use the quickfix list for a simple list of files. That's what the argument list is for! You have a lot of commands for navigating it (:help :args), and it's very versatile ...
D. Ben Knoble's user avatar
  • 26.6k
4 votes

Function That Substitutes Across Multiple Files

You are missing something. After looking up the vimgrep documentation (:h vimgrep) you need the file(s). vimgrep /" . a:search . "/gj **/* The new script could be like this: function! ...
ENRIQUE GARCIA's user avatar
4 votes

How to create qf or location list from results of shell command

To answer your question more directly, you can use :help :cexpr or :help :cgetexpr in combination with :help system() to populate the quickfix: :cexpr system("find . -iname \*.py | xargs grep -n '...
romainl's user avatar
  • 41.2k
3 votes

How to load files as a quickfix window at start-up

If you'd like to invoke the command from inside Vim and populate the quickfix window with its output, you can use :cexpr together with system() or systemlist(). :cexpr system('...
filbranden's user avatar
  • 29k
3 votes
Accepted

How to always append parameters for a Ggrep command?

While I don't think it's possible out of the box, you can work your way around this: command! -nargs=1 GGrep Ggrep <q-args> -- './*' ':(exclude)*.map' Then use the GGrep command instead of ...
nobe4's user avatar
  • 16.1k
3 votes

Convert absolute path to one relative to another absolute one

I'm not entirely sure this does what you want, because you didn't provide tests in the form of expected inputs/outputs, but in case you're interested in a Vim script solution, here's a starting point: ...
user938271's user avatar
  • 5,987
3 votes

Function That Substitutes Across Multiple Files

If you replace execute by echo in your function you'll see that the executed command is vimgrep /hi/gj | copen | cfdo %s/ hi/hello/gc | cfdo update But :h :vimgrep says that the command must be ...
statox's user avatar
  • 50.1k
3 votes
Accepted

How to avoid getting search results from files that are in a directory that contains a folder named "xyz" in its path

Use the Cfilter plugin that comes with vim: :packadd cfilter :Cfilter! /xyz/ (more at :help cfilter-plugin) See :colder and :cnewer to move between different versions of the quickfix list.
D. Ben Knoble's user avatar
  • 26.6k
3 votes

How to avoid getting search results from files that are in a directory that contains a folder named "xyz" in its path

:vimgrep can take multiple file globs. In simple cases that means you can potentially search only places you want instead of excluding (think white-listing vs black-listing) :vimgrep /foo/ bar/** baz/*...
Peter Rincker's user avatar
3 votes
Accepted

How to create qf or location list from results of shell command

The gF command is jumping at a specific line within the file. It open the file at the number specified after the file name where the file name and the line number are separated by a non isfname ...
Vivian De Smedt's user avatar
2 votes
Accepted

Is it possible to use vimgrep with file paths from a file?

On unix like systems, you can use backticks directly in the vimgrep command (in any command that takes file names) :vimgrep "search" `cat cppfiles` | cw There is vim-only way by loading the cpp ...
Mass's user avatar
  • 14.2k
2 votes
Accepted

How can I prevent vim from changing the % register when entering non-modifiable windows?

"% is a read-only register. I doubt there is anything you can do to the register. Instead of simply using % in your grep command, e.g. :grep 'foo' %, use <c-r> to put in the contents of the ...
Peter Rincker's user avatar
2 votes
Accepted

join string and <cword> for vimgrep in command

Use exec with string concatenation: command! -nargs=0 GJL exec 'vimgrep ref{'.expand('<cword>').' *.tex | copen' In a function, you'd do something similar, but more neatly, I suppose: ...
muru's user avatar
  • 25k
2 votes
Accepted

Multi file search for selected text

You can reference the word/WORD under the cursor with: <C-r><C-w> <C-r><C-a> So instead of yanking, you can directly have: :grep -F <C-r><C-w> Or even shorter ...
nobe4's user avatar
  • 16.1k
2 votes
Accepted

:lvimgrep with one match per file

According to the help you can use :1lvimgrep pattern to have only a single match per file added to the quickfix list. I have never tried that however and so I am not sure how well that works. Update ...
Christian Brabandt's user avatar
2 votes
Accepted

Is it possible to do consecutive vimgrep searches to refine and filter results?

There are plugins that address this, such as qftools or vim-qf by our own romainl. A quick google gets plenty of results.
D. Ben Knoble's user avatar
  • 26.6k
2 votes

Put in quickfix list the files whose content does not match a pattern inside it

One way to do it would be to: use :args to populate the arglist with all the files in which you're interested use search() to check whether your pattern can be found in each file, and if it does not, ...
user938271's user avatar
  • 5,987
2 votes
Accepted

Call vimgrep from terminal

It concerns more shell than an editor. I guess, adding this to shell's profile should work vimgrep() { $EDITOR "+vimgrep $1 $2" "+copen"; } To call from terminal do not forget to put single ...
Matt's user avatar
  • 20.8k
2 votes
Accepted

vimscript: No match error

You can just use <cword> directly here: function! CustomGrep() vimgrep <cword> **/*.h **/*.hpp **/*.c **/*.cpp endfunction If you look up :help <cword> you'll see it's on a ...
filbranden's user avatar
  • 29k
2 votes

vimscript: No match error

Did I do something wrong here? :vimgrep is a command which takes a string. expand() is a function call. You must use execute then: execute 'vimgrep' expand('<cword>') '**/*.h ...'
Matt's user avatar
  • 20.8k
2 votes
Accepted

Calling vimgrep from a comand

The function should just be execute 'vimgrep /\v' . a:query . '/g **/*' copen Or you could do this with the command: command -nargs=* Vsearch vimgrep /\v<args>/g **/* | copen
D. Ben Knoble's user avatar
  • 26.6k
2 votes

Find all files matching a glob pattern and add it to the quickfix window

One trick that worked for me was set errorformat=%f | cexpr glob('**/*.md') The :cexpr command takes an expression and uses it to populate the quickfix list. Because the default errorformat doesn't ...
D. Ben Knoble's user avatar
  • 26.6k

Only top scored, non community-wiki answers of a minimum length are eligible