5 ms·
My personal favourite trick with ":r!" is, in a new buffer, running :0r! grep -rn $pattern $path_to_directory or any other command that outputs lines cont
by EvilTerran 10y ago
My personal favourite trick with ":r!" is, in a new buffer, running
:0r! grep -rn $pattern $path_to_directory
or any other command that outputs lines containing "$path_to_file:$line_no" (eg most linters).
With that output read into a buffer, placing the cursor anywhere in the "path:line" part and hitting ^wF will open that file in a new split window, and jump the cursor straight to the indicated line - or you can do ^wgF to do the same in a new tab page.
It's a very handy way to work through a big list of work items spread across many files. You do need to coax the right format for it out of your tools, but fortunately "path:line" is pretty de-facto standard.
(Incidentally, I do ":0r" so it inserts the read-in lines at the very top of the file - just ":r" in an empty buffer leads to a leading blank line, which I find irrationally annoying.)
- u801e 10y agoI know that vim has the built in :grep command that does what you describe. The results are listed in the preview window and pressing enter will open the corresponding file and place the cursor at the desired line.
- EvilTerran 10y agoWell, yes... okay, maybe that was a poor choice of example, :grep is probably more ergonomic for that particular use case. The trick I described is more for when you're dealing with some unusual program that wouldn't work with :grep - at least not without fiddling with 'grepprg' to invoke it, and/or 'grepformat' to correctly interpret its output.
- blockloop 10y agoThere is also a silver searcher plugin for vim (ag).
- JdeBP 10y agoWith the likes of :cfile :cbuffer one can turn that file/buffer directly into a quickfix list, where simply enter will take one to the relevant position. Messages with column positions are recognized in quickfix lists (:help errorformat).
- akavel 10y agoFor any commands or pipelines, you can use: :cex system('git grep -n foo | grep bar') | copen then :cn and :cp to step through the list easily.