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 ...
9
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)
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 | ...
5
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 ...
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 ...
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! ...
3
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 "\%^"...
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('...
3
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 ...
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 ...
3
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 ...
3
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 ...
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:
...
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 ...
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.
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/*...
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 ...
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 ...
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:
...
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.
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, ...
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 ...
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
...
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 ...
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 ...'
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
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 ...
2
votes
Accepted
How to get the number of the output of `vimgrep`
Simpler is
function! CustomReplace(target, newWord)
call CustomGrep(a:target)
cdo execute 's/'.a:target.'/'.a:newWord.'/gc'
endfunction
Or with cfdo and %s,
function! CustomReplace(target, ...
2
votes
Accepted
Convert absolute path to one relative to another absolute one
Nope, not a Vim answer. AFAIK, though it's the best solution available.
absolute->relative is needed a lot less frequently then relative->absolute so I expect your choices will be pretty limited....
2
votes
Accepted
User <cword> inside a vimgrep regex expression
There's a lot missing there. Ignoring the part after the first <CR> for now...
First, there are some contexts, i.e. where a filename is expected, where you can use <cword> bare. But in ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
vimgrep × 35quickfix × 7
search × 5
vimrc × 4
vimscript × 4
regular-expression × 3
grep × 3
functions × 2
multiple-files × 2
key-bindings × 1
neovim × 1
command-line × 1
terminal × 1
autocompletion × 1
substitute × 1
replace × 1
external-command × 1
filesystem × 1
startup × 1
plugin-fugitive × 1
working-directory × 1
the-silver-searcher × 1