sponsor Vim development Vim logo Vim Book Ad

interactive-replace : InteractiveReplace lets you choose replacement text for your search

 script karma  Rating 1/1, Downloaded by 1000  Comments, bugs, improvements  Vim wiki

created by
Harold Rodriguez
 
script type
utility
 
description
InteractiveReplace lets you interactively choose replacement text while you search/replace.

## Usage ##
Just type

    :InteractiveReplace

at the Vim console, or type the shortcut binding in normal mode:

     <leader>r

(on my system that's `\r`).


## Examples ##
Say you wanted to find and replace all occurrences of *Bel-air* in a text file, but you wanted to specify what the replacement text is each time without having to redo a substitution or create a very complicated regex.

With a search performed (e.g. `/Bel-air`), type `\r` to bring up InteractiveReplace. Then for each highlighted term, type the replacement text and press `Enter`.

Easy consecutive substitutions: http://www.planetharold.com/projects/interactive-replace/interactive-replace-1.png

----------------

In a programming context, you can easily substitute variable names stemming from one `o`pened line.

For example, to write out a skeleton for your replaces, you could type (with the cursor on line 6):

     7odrawChart data.tmp[Esc]

to get: http://www.planetharold.com/projects/interactive-replace/interactive-replace-2.png

Now use InteractiveReplace on `/tmp` to sequentially replace variable names: http://www.planetharold.com/projects/interactive-replace/interactive-replace-3.png

## F.A.Q. ##
* How do I install Pathogen?
     * Just put [pathogen.vim] into your ~/.vim/autoload folder. Then put these two lines in your *.vimrc* file:
        * filetype plugin indent on
        * execute pathogen#infect()
* How do I install InteractiveReplace without using Pathogen?
     * If you wanna be really dirty about it, download the zipball from https://github.com/hwrod/interactive-replace and extract the contents to your Vim directory.
* How do I update InteractiveReplace?
    * The beauty of installing with Pathogen is that you `cd` into `~/.vim/bundle/interactive-replace/` and type `$ git pull` to get the latest updates.

## Todo

There are a few ways InteractiveReplace can be improved, including:

* allowing `Enter` to skip replace (make no change)
* highlighting the current search term in a different color
* if nothing's in the `/` register, ask user for a search term

Pull requests are highly encouraged (https://github.com/hwrod/interactive-replace). Questions/comments welcome too.
 
install details
## Install ##
If you wanna be quick-and-dirty, download the zipfile below and extract the contents to your Vim directory.

Better yet, assuming you have Git and Pathogen installed, which you should, just run:

     $ git clone https://github.com/hwrod/interactive-replace.git ~/.vim/bundle/interactive-replace

Optionally, to configure a different key binding, add this line to your *.vimrc* file:

    let g:InteractiveReplace_map = 'X'

where *X* is something like <F5> or \i
 

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
interactive-replace.zip 1.0.0 2013-03-14 7.0 Harold Rodriguez Initial upload
ip used for rating: 216.73.216.155

Questions about Vim should go to the maillist. Help Uganda.     Vim at Github