I have the file tmp.git.log
in my $HOME:
commit 07f5bbb6a3a112f7b601d6cd1f72ec3f20112920
Author: me
Date: 2024
some
comit
messages
diff --git path/file.end
index e969a7691b..0bf58bcb94 100644
--- removed
+++ added
@@ -1,7 +1,7 @@
- removed
+ added
:key="index"
label
:color="color"
@@ -10,11 +10,13 @@
:class="fontWeight"
etc.
I wanted to fill my quickfix list with the beginnings and endings of the changes, marked here by @@
at the line start. I tried to execute
:vimgrep /^@@ ~/tmp.git.log
And Nvim answered with
E682 invalid search pattern or separator
What is wrong with the above vimgrep command?
Also: Can I :vimgrep
in buffers which aren't written, e.g. non-files?
I want to :read !git show <git-hash>
into nvim to see changes done in my repo by certain commits, I don't need the files persisted. I know, there are plugins, but I want to understand what vanilla nvim can do here.
I want to read the result of git show <git-gash>
within Neovim, and populate the quickfix list with vimgrep.
Vimgrep fails to accept my search
:vimgrep /^@@ ~/tmp.git.log
with E682
.
How do I accomplish to fill my quickfix list with the added/removed file chunk positions for faster navigation?
Ideally without saving the git show result to a temporary file first.
You must enclose your pattern with
/
and/
(or a pair of another character), as per:help :vimgrep
:No. Both
:grep
and:vimgrep
can only be used to search through files.The mechanisms for searching in a file and searching in a buffer can't really be identical because the two tasks sit at different abstraction levels. You have very old and simple commands like
:vimgrep
for the former but, sadly, only low-level stuff for the latter.I came up with this monstrous one-liner years ago because I wanted to use the quickfix for buffer-level search but it only works for named buffers. I guess one could use the same basic logic (filter the lines from current buffer) but use
:help setqflist()
/:help setloclist()
instead.--- EDIT ---
FWIW, I just wrote this more versatile version of the linked snippet that makes use of the location list:
which seems to work fine with everything I threw at it, named buffer or not.
Usage, populate location list with matching lines in given range:
Usage, populate location list with non-matching lines in given range: