sponsor Vim development Vim logo Vim Book Ad

multichange.vim : Edit a word and have the change propagate throughout the buffer

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

created by
Andrew Radev
 
script type
utility
 
description
Github project: https://github.com/AndrewRadev/multichange.vim

The plugin exposes a command, :Multichange, that enters a special "multi" mode. In this mode, any change of a word with a "c" mapping is propagated throughout the entire file. Example:

    def add(one, two):
        return one + two

If we wanted to rename the "one" parameter to "first" and the "two" parameter to "second", we could do it in a number of ways using either the . mapping or substitutions. With multichange, we execute the :Multichange command, and then perform the cw operation on "one" and "two" within the argument list. Changing them to "first" and "second" will be performed for the entire file.

Note that this works similarly to the * mapping -- it replaces words only, so it won't replace the "one" in "one_more_thing".

To exit "multi" mode, press <esc>. To limit the "multi" mode to only an area of the file (for example, to rename variables within a single function definition), select the desired area and then execute :Multichange.

You can also make a change in visual mode. For example, you want to change a function name in Vimscript:

    function! s:BadName()
    endfunction

    call s:BadName()

Since : is not in iskeyword (I think), you might have problems changing the function name using word motions. In this case, start "multi" mode as described above, then mark s:BadName in characterwise visual mode (with v). After pressing c, change the name to whatever you like. This will propagate the same way as the word change from before. The difference is that whatever was selected will be changed, regardless of word boundaries. So, if you only select "Name" and change it, any encounter of "Name" will be replaced.

The plugin also exposes a mapping for the :Multichange command that acts as a text object. Read the documentation for more details.
 
install details
There are several ways to install the plugin. The recommended one is by using Tim Pope's pathogen (http://www.vim.org/scripts/script.php?script_id=2332). In that case, you can clone the plugin's git repository like so:

    git clone git://github.com/AndrewRadev/multichange.vim.git ~/.vim/bundle/multichange

If your vim configuration is under git version control, you could also set up the repository as a submodule, which would allow you to update more easily. The command is (provided you're in ~/.vim):

    git submodule add git://github.com/AndrewRadev/multichange.vim.git bundle/multichange

Another way is to simply copy all the essential directories inside the ~/.vim directory: autoload, doc, plugin.
 

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
multichange.zip 0.2.0 2015-01-27 7.0 Andrew Radev Mapping is a text object now, so it allows much easier targeting of the area of effect.
multichange.zip 0.1.0 2012-11-10 7.0 Andrew Radev Initial upload
ip used for rating: 142.132.191.50

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