Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - easily edit filter result

Tags:

vim

filtering

I would like to use something like vils for vim buffers.

Example:

a
b
a
b

Search for "a" (:g/a/)

Output:

a
a

and then edit the output as if it were a normal buffer. When I'm done it should map my changes line by line back to the original buffer.

How do I do that?

PS: I could probably use :%s/../../ or something like that, but it wouldn't be nearly as comfortable as it could be. (Even if the completion in the CTRL+F buffer would work.)

like image 722
Ivaldi Avatar asked Jun 11 '12 14:06

Ivaldi


3 Answers

Use Qfreplace http://github.com/thinca/vim-qfreplace

  1. add some into quickfix. ex: grep foo */
  2. type :Qfreplace on quickfix
  3. change lines as you want.
  4. :w
like image 86
mattn Avatar answered Nov 07 '22 20:11

mattn


The feature you're talking about sounds like occure/narrow-to-region in emacs.

In vim, you can type this command:

:vimgrep pattern %

Then type :cw to open the quickfix-list.

You can use mouse click or :cn/:cp to navigate to make changes.

like image 32
kev Avatar answered Nov 07 '22 18:11

kev


As long as the matching lines span a single range of consecutive lines, the NrrwRgn plugin may work for you.

like image 1
Ingo Karkat Avatar answered Nov 07 '22 18:11

Ingo Karkat