sponsor Vim development Vim logo Vim Book Ad

jreplace.vim : Repeat you last SEARCH+REPLACE with your grepprg

 script karma  Rating 0/0, Downloaded by 186  Comments, bugs, improvements  Vim wiki

created by
ivan wellesz
 
script type
utility
 
description
Searches files under the current directory,
looking for your last search pattern with your grepprg
to replace occurrences in the next quickfix target line
with the same replacement you just did before calling this script.
...closely organized like jcallers script is .. @see Vim wiki

1 - Starts with a :normal mA  .. AS A GLOBAL MARK [A] .. you can jump back to as a return point.
2 - Calls your grepprg to build a quickfix list used to navigate to the next occurrence under the current working directory.
3 - Each call to the content of the [q register] with the @q command will attempt the next replacement.
4 - The result is a highlighted replaced text you can undo at will before your next call to @q.
5 - Lets you navigate the grep quickfix resulting list to review or undo any of those replacements.
6 - Calling @q while moving back and forth the quickfix list will attempt the next replacement from that slot.

Notes:
- F_replace(old,new) function applies a global substitute of all occurrences on each quickfix-target-line.

- USES [A global mark] as a call return point.
...(there are 2 calls to [A mark] you can adjust to use another mark :normal mA and :normal 'A

- USES [q register] to store jump and replacement for the next quickfix entry.
...@q will execute the next substitution
...you can check the results one step at a time
...( :nnoremap Q   @q .. may help )
 
install details
- put the file where you put your other scripts (it has no dependency)
- then map something to source it.
...mine is:
:nnoremap      <esc>r   :so ~/VIM/scripts/jreplace.vim<cr><cr>

...and the mass-destruction version:
:nmap     <esc><esc>r   :so ~/VIM/scripts/jreplace.vim<cr><cr>:silent! normal 99Q<cr>:silent normal z.:crew<cr>:cn<cr>
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
jreplace.vim 201209 2020-12-10 7.0 ivan wellesz Initial upload
ip used for rating: 3.14.70.203

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github