Viewing substitute command changes

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Viewing substitute command changes

Pavel Shevaev

Hi, folks!

Is it possible somehow to put all substitute changes into quickfix window?

Well, there are "n" and "p" flags however being able to browse all
changes with :cn, :cope commands could be much more convenient imho.
This could be especially helpful for viewing changes in multiple files
after applying :argdo %s/../../

Any tips?

--
Best regards, Pavel

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Viewing substitute command changes

Gary Johnson

On 2007-07-20, Pavel Shevaev <[hidden email]> wrote:

> Hi, folks!
>
> Is it possible somehow to put all substitute changes into quickfix window?
>
> Well, there are "n" and "p" flags however being able to browse all
> changes with :cn, :cope commands could be much more convenient imho.
> This could be especially helpful for viewing changes in multiple files
> after applying :argdo %s/../../
>
> Any tips?

Interesting idea.  I like it.

I often make changes to many lines in a file using some substitute
command, then I want to review each of those changes in context and
perhaps clean up the formatting of the changed lines.  I usually do
that by searching for the replacement string, but that wouldn't work
if the replacement was complex or if the replacement string occurred
in several places in the file that weren't part of the substitution.  
Sometimes I'll do a side-by-side diff of the buffer with the
original file on disk.

You might take a look at

   :help changelist

and see if that feature comes close to doing what you want.  Maybe
there's a way to put the ":changes" list into the quickfix error
list.

HTH,
Gary

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Viewing substitute command changes

Antony Scriven-3

On 20/07/07, Gary Johnson <[hidden email]> wrote:

 > On 2007-07-20, Pavel Shevaev <[hidden email]> wrote:
 > > Hi, folks!
 > >
 > > Is it possible somehow to put all substitute changes
 > > into quickfix window?
 > >
 > > Well, there are "n" and "p" flags however being able to
 > > browse all changes with :cn, :cope commands could be
 > > much more convenient imho. This could be especially
 > > helpful for viewing changes in multiple files after
 > > applying :argdo %s/../../
 > >
 > > Any tips?
 >
 > Interesting idea.  I like it.
 >
 > I often make changes to many lines in a file using some
 > substitute command, then I want to review each of those
 > changes in context and perhaps clean up the formatting of
 > the changed lines.  I usually do that by searching for
 > the replacement string, but that wouldn't work if the
 > replacement was complex or if the replacement string
 > occurred in several places in the file that weren't part
 > of the substitution.

You could prefix your replacement with, say, `@@@', and then
search for that. When you are done :%s/@@@//

 > Sometimes I'll do a side-by-side diff of the buffer with
 > the original file on disk.

That's a good idea too.

 > You might take a look at
 >
 >    :help changelist
 >
 > and see if that feature comes close to doing what you
 > want.  Maybe there's a way to put the ":changes" list
 > into the quickfix error list.

I don't think that will give you all the changes made.

You could try something like the following (using a location
list rather than quickfix list).

:let changes = '' | %s/RE/\='['.submatch(0).' ->
'.substitute(submatch(0), '.*', 'mychange', '') . ']'/ | let changes
.= @% . ':' . line('.') . ':' . getline('.') . "\n"
:lexpr changes
:lopen

But the @@@ thing works for me. --Antony

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Viewing substitute command changes

John Little-4

I, too, like the idea of putting the change list into the quick fix
window, like :vimgrep does; you could do that now on the searched
pattern and do the substitutes one by one.

I use the diff approach.  With an autocommand on the BufWritePost
event that renames the backup file with a time stamp, and functions
that switch to and from the diff view, the review is two key strokes
away (save before the substitute, diff with backup after).  Okay, the
backup directory gets a little full, but there's that warm fuzzy
feeling.

Regards, John


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Viewing substitute command changes

Pavel Shevaev

> I use the diff approach.  With an autocommand on the BufWritePost
> event that renames the backup file with a time stamp, and functions
> that switch to and from the diff view, the review is two key strokes
> away (save before the substitute, diff with backup after).  Okay, the
> backup directory gets a little full, but there's that warm fuzzy
> feeling.

Could you please share your .vimrc settings for this trick? ;)

--
Best regards, Pavel

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Viewing substitute command changes

Yegappan Lakshmanan
In reply to this post by Pavel Shevaev

Hello,

On 7/20/07, Pavel Shevaev <[hidden email]> wrote:

>
> Hi, folks!
>
> Is it possible somehow to put all substitute changes into quickfix window?
>
> Well, there are "n" and "p" flags however being able to browse all
> changes with :cn, :cope commands could be much more convenient imho.
> This could be especially helpful for viewing changes in multiple files
> after applying :argdo %s/../../
>
> Any tips?
>

You can try using the following greplace plugin:

http://vim.sourceforge.net/scripts/script.php?script_id=1813

- Yegappan

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Viewing substitute command changes

John Little-4
In reply to this post by Pavel Shevaev

> Could you please share your .vimrc settings for this trick?

Well, here's the backup function I used with vim 7 on windows, but at
work I'm presently using 6.3 that comes with Red Hat, and the
globpath() call works quite differently, it never returns the empty
string; for each dir in the backupdir option it always returns an
entry for the file, whether it exists or not.  I'll have to loop on
the string returned by globpath calling filereadable(), or, get vim 7
somehow, without involving administrators.  (The dilemma has put the
problem in the too hard pile.)

HTH, John

function! StampBackup()
    let bup = globpath(&backupdir, expand('%:t') . &bex)
    if bup != ""
        let stamp = ".".strftime("%y.%m.%d_%H.%M.%S")."."
        let stamped = substitute(bup, '\M.\(\[^.]\*\)' . &bex, stamp . '\1', '')
        if stamped == bup " file has no suffix
            let stamped = substitute(bup, '\M' . &bex, stamp . &bex, '')
        endif
        if rename(bup, stamped)
            echoerr "failed rename of backup " . bup . " to " . stamped
        endif
    endif
endfunction

augroup StampBackup
    au! BufWritePost * call StampBackup()
augroup END

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Viewing substitute command changes

Tony Mechelynck

John Little wrote:
[...]

> Well, here's the backup function I used with vim 7 on windows, but at
> work I'm presently using 6.3 that comes with Red Hat, and the
> globpath() call works quite differently, it never returns the empty
> string; for each dir in the backupdir option it always returns an
> entry for the file, whether it exists or not.  I'll have to loop on
> the string returned by globpath calling filereadable(), or, get vim 7
> somehow, without involving administrators.  (The dilemma has put the
> problem in the too hard pile.)
>
> HTH, John
[...]

6.3 is obsolete by now. Since its days, both 6.4 and 7.0 have come and gone,
and the current version, 7.1, is at patchlevel 32. You should be able to
compile it yourself, it is not very difficult. See how I do it at
http://users.skynet.be/antoine.mechelynck/vim/compunix.htm

If you don't have admin privileges, you ought to be able to install it
somewhere under your home directory (e.g. equating $VIMRUNTIME with
$HOME/vim/vim71 with no dot before vim). In that case the harder difficulty
may be to make sure that all needed "development" packages are installed on
the system.

Or else (this would be better if you can pull it off) convince your admin that
he has obsolete software installed; you may even offer to bring it up-to-date ;-)


Best regards,
Tony.
--
     f y cn rd ths thn y cn hv grt jb n cmptr prgrmmng

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---


Reply | Threaded
Open this post in threaded view
|

Re: Viewing substitute command changes

John Little-4
Tony said:

>6.3 is obsolete by now....

Yes, but it's still very, very good...

Further finding: Vim 6's glob() functions misbehave *only* with a tilde in the file name (or names).  Changing &backupext to something else solves the problem.  I wonder what

    :echo glob("xyzzy~")

says with Vim 7 and unix etc. (assuming there's no such file about).  Looks like some tilde expansion effect, though the

>You should be able to compile it yourself...

Yeah, but that's not what the client is paying me for.  It's a development shop where they're really keen on developer boxes having the 'standard build' and it's quite involved to get that build changed; they do lots of pair programming swapping around every day.  I'll have to put together "Vim on a stick" so that I can carry it around.

Regards, John

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Viewing substitute command changes

fREW Schmidt

> Yeah, but that's not what the client is paying me for.  It's a development
> shop where they're really keen on developer boxes having the 'standard
> build' and it's quite involved to get that build changed; they do lots of
> pair programming swapping around every day.  I'll have to put together "Vim
> on a stick" so that I can carry it around.

Portable vim is available for windows boxes.  If you do put portable
vim on a usb key I would suggest writing a script that will update
your .vimrc as it tends to lag behind the version on your computer
otherwise.

--
-fREW

Q: Why is this email 5 sentences or less?
A: http://five.sentenc.es

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---