News for hackers. Stuff that matters.
Re:Vim After 15 Years by kazinator on Wednesday October 26, 2022 @07:28PM (#33351007)
About :grep, try integrating GNU id-utils with Vim.

GNU id-utils provides a mkid command which scans a directory of files to build a binary index file called ID. The lid tool is used to query this and provides a grep-compatible mode.

lid sometimes puts out things in a funny order, so I sort the output.

  :set grepprg=lid\ --word\ --result=grep\ '$*'\ \\\|\ sort\ -n\ -t\ :\ -k\ 2
This is basically instant even on huge file trees.

Or, if you'd like :grep to use git grep:

  :set grepprg=git\ grep\ -n\ '$*'
Re:Vim After 15 Years by brian_cloutier on Wednesday October 26, 2022 @07:50PM (#33351201)
What do either of these `grepprg` options win me? Currently my `grepprg` calls `ag` which is plenty fast for me, and it sounds like `lid` is a slightly more general ctags?
Re:Vim After 15 Years by kazinator on Wednesday October 26, 2022 @08:37PM (#33351515)
lid doesn't tell you where an identifier is defined, but indexes all the places where it occurs. A lid query is instant; it just pulls the info from the ID file without searching any files.

In a large-ish project like the Linux kernel tree, there is no perceptible delay.

I use ctags in parallel with mkid; different tools for different job.

Speaking of :grep, I have it mapped to the K key.

The default action of K is to do a man page lookup of the word under the cursor. I changed it to grep instead. ... and I preserved the man page functionality too. The default K takes an optional prefix (man page section). I have it so that if I give a numeric prefix to K, it will do the man page lookup for that section:

  :nmap K "_y:execute count ? ( ":!man " . count . " " . expand("<cword>") ) : ( ":grep \\<" . expand("<cword>") . "\\>")<CR>
and for grepping for a visual selection:

  :vmap K "zy:execute ":grep " . getreg("z")<CR>