vim - how can i do a 'change word' using the current paste buffer












70















I have some text in my paste buffer, e.g. I did a yw (yank word) and now I have 'foo' in my buffer.



I now go to the word 'bar' and I want to replace it with my paste buffer.



To replace the text manually I could do cw and then type the new word.



How can I do a 'change word' but use the contents of my paste buffer instead of manually typing out the replacement word?



The best option I have right now is to go to the beginning of the word I want to replace and do dw (delete word), then go to the other place and do the yw (yank word), then go back to the replacement area and do p (paste) which is kinda clumsy especially if they are not on the same screen.










share|improve this question



























    70















    I have some text in my paste buffer, e.g. I did a yw (yank word) and now I have 'foo' in my buffer.



    I now go to the word 'bar' and I want to replace it with my paste buffer.



    To replace the text manually I could do cw and then type the new word.



    How can I do a 'change word' but use the contents of my paste buffer instead of manually typing out the replacement word?



    The best option I have right now is to go to the beginning of the word I want to replace and do dw (delete word), then go to the other place and do the yw (yank word), then go back to the replacement area and do p (paste) which is kinda clumsy especially if they are not on the same screen.










    share|improve this question

























      70












      70








      70


      14






      I have some text in my paste buffer, e.g. I did a yw (yank word) and now I have 'foo' in my buffer.



      I now go to the word 'bar' and I want to replace it with my paste buffer.



      To replace the text manually I could do cw and then type the new word.



      How can I do a 'change word' but use the contents of my paste buffer instead of manually typing out the replacement word?



      The best option I have right now is to go to the beginning of the word I want to replace and do dw (delete word), then go to the other place and do the yw (yank word), then go back to the replacement area and do p (paste) which is kinda clumsy especially if they are not on the same screen.










      share|improve this question














      I have some text in my paste buffer, e.g. I did a yw (yank word) and now I have 'foo' in my buffer.



      I now go to the word 'bar' and I want to replace it with my paste buffer.



      To replace the text manually I could do cw and then type the new word.



      How can I do a 'change word' but use the contents of my paste buffer instead of manually typing out the replacement word?



      The best option I have right now is to go to the beginning of the word I want to replace and do dw (delete word), then go to the other place and do the yw (yank word), then go back to the replacement area and do p (paste) which is kinda clumsy especially if they are not on the same screen.







      vim vi replace buffer






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 29 '13 at 14:45









      Michael DurrantMichael Durrant

      16.4k45121186




      16.4k45121186






















          11 Answers
          11






          active

          oldest

          votes


















          86














          Option 1



          You could use registers to do it and make a keybinding for the process.



          Yank the word you want to replace with yw.



          The yanked word is in the 0 register which you can see by issuing :registers.



          Go to the word you want to replace and do cw. Do Ctrl+r followed by 0 to paste the 0 register.



          The map for that would look something like this (assuming Ctrl+j as our key combo):



          :map <C-j> cw<C-r>0<ESC>



          Option 2 (simpler)



          With your word yanked, cursor over the word you want to replace and do viwp. Which is visual select inner word and paste.



          Courtesy of @tlo in the comments: you could also just do vep. One char shorter. Downside have to position cursor at start of word and (as with mine) changes the buffer.



          Comment (from Michael):



          This is good. Extra note: the second method is indeed easier but, as is, only works for ONE substitution because after each substitution the buffer then gets changed to the field that was replaced (old text). The first method is a little harder to use BUT has the advantage that the buffer 0 stays 'as is' so you can use that method to do more than 1 replacement of the same text.






          share|improve this answer





















          • 13





            Option 3 (even simpler): With your word yanked, cursor over the first character of the word you want to replace and do vep.

            – tlo
            Sep 9 '14 at 22:10













          • I like Option 3 when there is only 1 word to change. If there is more than one same word to change, Option 1 allows me to use the . operator to repeat it..

            – typelogic
            Sep 20 '18 at 17:36








          • 2





            ve"0p would work to let you repeat your change

            – JKillian
            Feb 6 at 19:03











          • If you're going to map it to something, it's probably better to use: map <C-j> ciw<C-r>0<ESC> so that it doesn't matter from where in the word you press ^j.

            – Paul Parker
            Mar 3 at 0:47











          • Anyone wanting to know why CTRL-R does it's magic: :help insert then search CTRL-R /CTRL-R. For how ve"0p works, look at :help registers

            – Paul Parker
            Mar 3 at 0:50



















          12














          yw to yank your word, then move the cursor to the word you wish to replace and use "_dw to delete it, sending the text to the null register (so it doesn't overwrite the contents of the " register, where yanked/cut text goes by default), and then simply paste with p.



          You could use the following mapping to make things a little easier:



          nnoremap <leader>d "_d


          ...so in normal mode, you could use dw to delete a word, without affecting the " register.






          share|improve this answer































            2














            I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.



            This plugin offers a two-in-one gr command that replaces text covered by a {motion} / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard . command. Should you not like it, its page has links to alternatives.






            share|improve this answer































              2














              To repeat the paste use the change command.



              cw ^R0ESC (^R=Control+R; 0 for register 0)



              will replace the word with the contents from reg. 0 and let's you repeat it with .



              This is great for cgn (VIM 7.4) to replace search patterns:




              • First search with / or *


              • cgn ^R0ESC


              • . to repeat on next match or n to skip






              share|improve this answer































                1














                Since it's not included yet, you usually replace strings with :%s/.../.../ and you can do this with the word under your cursor as well.




                1. You enter the first part of the command, what you are searching for: :s/find/

                2. Then you click <ctrl-r> and choose with the cursor the word you want to replace it with.

                3. Then you click <ctrl-w> (small "word") or <ctrl-a> (big "word) to paste the word under the cursor into the command line

                4. Then you finish the command.


                See the link about how to use cursor stuff in the command line.






                share|improve this answer































                  1














                  I usually use this: yw to yank foo, then delete bar with dw, and as final step, put foo from register 0 which holds yanked text using "0p. Repeat putting with period (.) as needed.



                  Also, instead of yw and dw, you can use yiw and diw (notice the extra i - it means inside). With that you can yank or delete word from any location inside it, not just on the beginning of word.






                  share|improve this answer

































                    0














                    I use this plugin for expanding selection region:
                    https://github.com/terryma/vim-expand-region



                    So my combination for changing a word will be: vvpin any place of a word.



                    I also have a hack for saving unnamed register contents after paste so I can repeat this.



                    vnoremap p p:let @"=@0 <CR>
                    vnoremap P P:let @"=@0 <CR>


                    (my clipboard is autoselect)






                    share|improve this answer































                      0














                      I'm using below key mapping to replace the current word with copied word.
                      " replace with Register 0
                      map <leader>rr ciw<C-r>0<Esc>



                      yiw copy a word. Navigate to a word. ,rr replace the word.

                      Leader key is map to ,.






                      share|improve this answer
























                      • ,rw would make more sense, and on QWERTY is probably a smidgen easier and faster to belt out. On DVORAK, I chose ,rc, which although it doesn't make much sense at all, it is easier and faster than all of them. On DVORAK, ,rw is a horror show ;)

                        – Paul Parker
                        Mar 3 at 1:00





















                      0














                      First, navigate to the start of the word you want to yank. If you're in the middle of the word, just do b to go back to the start of it. Then do ye to yank the whole word, without any trailing spaces (yank to end). Finally, go to the word you want to replace - perhaps by doing w a few times - and do a vep to enter visual selection mode, select to the end of the word, and paste the contents last yanked.



                      (If anyone wants to know why I didn't simply comment on the accepted answer, for the small modification of using ye rather than yw, it's because my reputation on this stack is still too low.)






                      share|improve this answer































                        0















                        1. use yw to yank the world, go to the world you want to change.

                        2. use v to select the world, ve or vw depending on your situation.

                        3. enter p to paster the world you copied to replace the selected block






                        share|improve this answer































                          0














                          To do this the VIM way, you intentionally use the yank, delete and other registers.



                          Register "0 is the yank register. Anything you yank will be put here, but deletes never touch register "0.



                          So, in your example, you had just yanked a word. To replace a word with what you just yanked, you take advantage of deletions never touching the yank register. So move to the target word, delete it with dw, then paste from your yank-register with "0p, or better yet, cw then ^R0 (which is repeatable).



                          A close opposite to the yank register is the small deletions register "-. Any small delete or change removal is put here, but yanks never touch "-. A deletion counts as small if it is less than a full line.



                          Registers "1-"9 are the delete history registers. With "1 containing the latest large deletion or change removal, and "9 containing the oldest large deletion or change removal. Only deletes that aren't small, i.e. deletes of one line or more, get pushed onto "1-"9.



                          For any operation that changes a register, a copy is also always placed in the default, a.k.a. unnamed register "". This is the register used when you don't explicitly name a register.



                          Register "_ is the black hole register, and it is always empty. If you delete to it, nothing in any register is changed at all, not even the default "" register, or the black hole register itself. The removed text is fully gone, apart from your undo history. Yanking to, or pasting from the black hole register does essentially nothing.



                          The black hole register "_ lets you do things like first one small deletion, then a number of other deletions into "_ without changing your small deletions register "-, then paste your first small deletion.



                          Other registers are the last inserted register "., the filename registers "% and "#, the command register ":, search register "/ and expression register "=.



                          You can get a list of all these registers and their contents by the command :register. That command is very useful to experiment with and learn what ends up where.






                          share|improve this answer

























                            Your Answer








                            StackExchange.ready(function() {
                            var channelOptions = {
                            tags: "".split(" "),
                            id: "106"
                            };
                            initTagRenderer("".split(" "), "".split(" "), channelOptions);

                            StackExchange.using("externalEditor", function() {
                            // Have to fire editor after snippets, if snippets enabled
                            if (StackExchange.settings.snippets.snippetsEnabled) {
                            StackExchange.using("snippets", function() {
                            createEditor();
                            });
                            }
                            else {
                            createEditor();
                            }
                            });

                            function createEditor() {
                            StackExchange.prepareEditor({
                            heartbeatType: 'answer',
                            autoActivateHeartbeat: false,
                            convertImagesToLinks: false,
                            noModals: true,
                            showLowRepImageUploadWarning: true,
                            reputationToPostImages: null,
                            bindNavPrevention: true,
                            postfix: "",
                            imageUploader: {
                            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                            allowUrls: true
                            },
                            onDemand: true,
                            discardSelector: ".discard-answer"
                            ,immediatelyShowMarkdownHelp:true
                            });


                            }
                            });














                            draft saved

                            draft discarded


















                            StackExchange.ready(
                            function () {
                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f88714%2fvim-how-can-i-do-a-change-word-using-the-current-paste-buffer%23new-answer', 'question_page');
                            }
                            );

                            Post as a guest















                            Required, but never shown

























                            11 Answers
                            11






                            active

                            oldest

                            votes








                            11 Answers
                            11






                            active

                            oldest

                            votes









                            active

                            oldest

                            votes






                            active

                            oldest

                            votes









                            86














                            Option 1



                            You could use registers to do it and make a keybinding for the process.



                            Yank the word you want to replace with yw.



                            The yanked word is in the 0 register which you can see by issuing :registers.



                            Go to the word you want to replace and do cw. Do Ctrl+r followed by 0 to paste the 0 register.



                            The map for that would look something like this (assuming Ctrl+j as our key combo):



                            :map <C-j> cw<C-r>0<ESC>



                            Option 2 (simpler)



                            With your word yanked, cursor over the word you want to replace and do viwp. Which is visual select inner word and paste.



                            Courtesy of @tlo in the comments: you could also just do vep. One char shorter. Downside have to position cursor at start of word and (as with mine) changes the buffer.



                            Comment (from Michael):



                            This is good. Extra note: the second method is indeed easier but, as is, only works for ONE substitution because after each substitution the buffer then gets changed to the field that was replaced (old text). The first method is a little harder to use BUT has the advantage that the buffer 0 stays 'as is' so you can use that method to do more than 1 replacement of the same text.






                            share|improve this answer





















                            • 13





                              Option 3 (even simpler): With your word yanked, cursor over the first character of the word you want to replace and do vep.

                              – tlo
                              Sep 9 '14 at 22:10













                            • I like Option 3 when there is only 1 word to change. If there is more than one same word to change, Option 1 allows me to use the . operator to repeat it..

                              – typelogic
                              Sep 20 '18 at 17:36








                            • 2





                              ve"0p would work to let you repeat your change

                              – JKillian
                              Feb 6 at 19:03











                            • If you're going to map it to something, it's probably better to use: map <C-j> ciw<C-r>0<ESC> so that it doesn't matter from where in the word you press ^j.

                              – Paul Parker
                              Mar 3 at 0:47











                            • Anyone wanting to know why CTRL-R does it's magic: :help insert then search CTRL-R /CTRL-R. For how ve"0p works, look at :help registers

                              – Paul Parker
                              Mar 3 at 0:50
















                            86














                            Option 1



                            You could use registers to do it and make a keybinding for the process.



                            Yank the word you want to replace with yw.



                            The yanked word is in the 0 register which you can see by issuing :registers.



                            Go to the word you want to replace and do cw. Do Ctrl+r followed by 0 to paste the 0 register.



                            The map for that would look something like this (assuming Ctrl+j as our key combo):



                            :map <C-j> cw<C-r>0<ESC>



                            Option 2 (simpler)



                            With your word yanked, cursor over the word you want to replace and do viwp. Which is visual select inner word and paste.



                            Courtesy of @tlo in the comments: you could also just do vep. One char shorter. Downside have to position cursor at start of word and (as with mine) changes the buffer.



                            Comment (from Michael):



                            This is good. Extra note: the second method is indeed easier but, as is, only works for ONE substitution because after each substitution the buffer then gets changed to the field that was replaced (old text). The first method is a little harder to use BUT has the advantage that the buffer 0 stays 'as is' so you can use that method to do more than 1 replacement of the same text.






                            share|improve this answer





















                            • 13





                              Option 3 (even simpler): With your word yanked, cursor over the first character of the word you want to replace and do vep.

                              – tlo
                              Sep 9 '14 at 22:10













                            • I like Option 3 when there is only 1 word to change. If there is more than one same word to change, Option 1 allows me to use the . operator to repeat it..

                              – typelogic
                              Sep 20 '18 at 17:36








                            • 2





                              ve"0p would work to let you repeat your change

                              – JKillian
                              Feb 6 at 19:03











                            • If you're going to map it to something, it's probably better to use: map <C-j> ciw<C-r>0<ESC> so that it doesn't matter from where in the word you press ^j.

                              – Paul Parker
                              Mar 3 at 0:47











                            • Anyone wanting to know why CTRL-R does it's magic: :help insert then search CTRL-R /CTRL-R. For how ve"0p works, look at :help registers

                              – Paul Parker
                              Mar 3 at 0:50














                            86












                            86








                            86







                            Option 1



                            You could use registers to do it and make a keybinding for the process.



                            Yank the word you want to replace with yw.



                            The yanked word is in the 0 register which you can see by issuing :registers.



                            Go to the word you want to replace and do cw. Do Ctrl+r followed by 0 to paste the 0 register.



                            The map for that would look something like this (assuming Ctrl+j as our key combo):



                            :map <C-j> cw<C-r>0<ESC>



                            Option 2 (simpler)



                            With your word yanked, cursor over the word you want to replace and do viwp. Which is visual select inner word and paste.



                            Courtesy of @tlo in the comments: you could also just do vep. One char shorter. Downside have to position cursor at start of word and (as with mine) changes the buffer.



                            Comment (from Michael):



                            This is good. Extra note: the second method is indeed easier but, as is, only works for ONE substitution because after each substitution the buffer then gets changed to the field that was replaced (old text). The first method is a little harder to use BUT has the advantage that the buffer 0 stays 'as is' so you can use that method to do more than 1 replacement of the same text.






                            share|improve this answer















                            Option 1



                            You could use registers to do it and make a keybinding for the process.



                            Yank the word you want to replace with yw.



                            The yanked word is in the 0 register which you can see by issuing :registers.



                            Go to the word you want to replace and do cw. Do Ctrl+r followed by 0 to paste the 0 register.



                            The map for that would look something like this (assuming Ctrl+j as our key combo):



                            :map <C-j> cw<C-r>0<ESC>



                            Option 2 (simpler)



                            With your word yanked, cursor over the word you want to replace and do viwp. Which is visual select inner word and paste.



                            Courtesy of @tlo in the comments: you could also just do vep. One char shorter. Downside have to position cursor at start of word and (as with mine) changes the buffer.



                            Comment (from Michael):



                            This is good. Extra note: the second method is indeed easier but, as is, only works for ONE substitution because after each substitution the buffer then gets changed to the field that was replaced (old text). The first method is a little harder to use BUT has the advantage that the buffer 0 stays 'as is' so you can use that method to do more than 1 replacement of the same text.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Sep 10 '14 at 1:28

























                            answered Aug 29 '13 at 15:04









                            jmathewjmathew

                            1,31311011




                            1,31311011








                            • 13





                              Option 3 (even simpler): With your word yanked, cursor over the first character of the word you want to replace and do vep.

                              – tlo
                              Sep 9 '14 at 22:10













                            • I like Option 3 when there is only 1 word to change. If there is more than one same word to change, Option 1 allows me to use the . operator to repeat it..

                              – typelogic
                              Sep 20 '18 at 17:36








                            • 2





                              ve"0p would work to let you repeat your change

                              – JKillian
                              Feb 6 at 19:03











                            • If you're going to map it to something, it's probably better to use: map <C-j> ciw<C-r>0<ESC> so that it doesn't matter from where in the word you press ^j.

                              – Paul Parker
                              Mar 3 at 0:47











                            • Anyone wanting to know why CTRL-R does it's magic: :help insert then search CTRL-R /CTRL-R. For how ve"0p works, look at :help registers

                              – Paul Parker
                              Mar 3 at 0:50














                            • 13





                              Option 3 (even simpler): With your word yanked, cursor over the first character of the word you want to replace and do vep.

                              – tlo
                              Sep 9 '14 at 22:10













                            • I like Option 3 when there is only 1 word to change. If there is more than one same word to change, Option 1 allows me to use the . operator to repeat it..

                              – typelogic
                              Sep 20 '18 at 17:36








                            • 2





                              ve"0p would work to let you repeat your change

                              – JKillian
                              Feb 6 at 19:03











                            • If you're going to map it to something, it's probably better to use: map <C-j> ciw<C-r>0<ESC> so that it doesn't matter from where in the word you press ^j.

                              – Paul Parker
                              Mar 3 at 0:47











                            • Anyone wanting to know why CTRL-R does it's magic: :help insert then search CTRL-R /CTRL-R. For how ve"0p works, look at :help registers

                              – Paul Parker
                              Mar 3 at 0:50








                            13




                            13





                            Option 3 (even simpler): With your word yanked, cursor over the first character of the word you want to replace and do vep.

                            – tlo
                            Sep 9 '14 at 22:10







                            Option 3 (even simpler): With your word yanked, cursor over the first character of the word you want to replace and do vep.

                            – tlo
                            Sep 9 '14 at 22:10















                            I like Option 3 when there is only 1 word to change. If there is more than one same word to change, Option 1 allows me to use the . operator to repeat it..

                            – typelogic
                            Sep 20 '18 at 17:36







                            I like Option 3 when there is only 1 word to change. If there is more than one same word to change, Option 1 allows me to use the . operator to repeat it..

                            – typelogic
                            Sep 20 '18 at 17:36






                            2




                            2





                            ve"0p would work to let you repeat your change

                            – JKillian
                            Feb 6 at 19:03





                            ve"0p would work to let you repeat your change

                            – JKillian
                            Feb 6 at 19:03













                            If you're going to map it to something, it's probably better to use: map <C-j> ciw<C-r>0<ESC> so that it doesn't matter from where in the word you press ^j.

                            – Paul Parker
                            Mar 3 at 0:47





                            If you're going to map it to something, it's probably better to use: map <C-j> ciw<C-r>0<ESC> so that it doesn't matter from where in the word you press ^j.

                            – Paul Parker
                            Mar 3 at 0:47













                            Anyone wanting to know why CTRL-R does it's magic: :help insert then search CTRL-R /CTRL-R. For how ve"0p works, look at :help registers

                            – Paul Parker
                            Mar 3 at 0:50





                            Anyone wanting to know why CTRL-R does it's magic: :help insert then search CTRL-R /CTRL-R. For how ve"0p works, look at :help registers

                            – Paul Parker
                            Mar 3 at 0:50













                            12














                            yw to yank your word, then move the cursor to the word you wish to replace and use "_dw to delete it, sending the text to the null register (so it doesn't overwrite the contents of the " register, where yanked/cut text goes by default), and then simply paste with p.



                            You could use the following mapping to make things a little easier:



                            nnoremap <leader>d "_d


                            ...so in normal mode, you could use dw to delete a word, without affecting the " register.






                            share|improve this answer




























                              12














                              yw to yank your word, then move the cursor to the word you wish to replace and use "_dw to delete it, sending the text to the null register (so it doesn't overwrite the contents of the " register, where yanked/cut text goes by default), and then simply paste with p.



                              You could use the following mapping to make things a little easier:



                              nnoremap <leader>d "_d


                              ...so in normal mode, you could use dw to delete a word, without affecting the " register.






                              share|improve this answer


























                                12












                                12








                                12







                                yw to yank your word, then move the cursor to the word you wish to replace and use "_dw to delete it, sending the text to the null register (so it doesn't overwrite the contents of the " register, where yanked/cut text goes by default), and then simply paste with p.



                                You could use the following mapping to make things a little easier:



                                nnoremap <leader>d "_d


                                ...so in normal mode, you could use dw to delete a word, without affecting the " register.






                                share|improve this answer













                                yw to yank your word, then move the cursor to the word you wish to replace and use "_dw to delete it, sending the text to the null register (so it doesn't overwrite the contents of the " register, where yanked/cut text goes by default), and then simply paste with p.



                                You could use the following mapping to make things a little easier:



                                nnoremap <leader>d "_d


                                ...so in normal mode, you could use dw to delete a word, without affecting the " register.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Aug 29 '13 at 19:45









                                evilsoupevilsoup

                                4,31421737




                                4,31421737























                                    2














                                    I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.



                                    This plugin offers a two-in-one gr command that replaces text covered by a {motion} / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard . command. Should you not like it, its page has links to alternatives.






                                    share|improve this answer




























                                      2














                                      I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.



                                      This plugin offers a two-in-one gr command that replaces text covered by a {motion} / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard . command. Should you not like it, its page has links to alternatives.






                                      share|improve this answer


























                                        2












                                        2








                                        2







                                        I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.



                                        This plugin offers a two-in-one gr command that replaces text covered by a {motion} / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard . command. Should you not like it, its page has links to alternatives.






                                        share|improve this answer













                                        I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.



                                        This plugin offers a two-in-one gr command that replaces text covered by a {motion} / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard . command. Should you not like it, its page has links to alternatives.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Oct 1 '13 at 9:19









                                        Ingo KarkatIngo Karkat

                                        8,88711933




                                        8,88711933























                                            2














                                            To repeat the paste use the change command.



                                            cw ^R0ESC (^R=Control+R; 0 for register 0)



                                            will replace the word with the contents from reg. 0 and let's you repeat it with .



                                            This is great for cgn (VIM 7.4) to replace search patterns:




                                            • First search with / or *


                                            • cgn ^R0ESC


                                            • . to repeat on next match or n to skip






                                            share|improve this answer




























                                              2














                                              To repeat the paste use the change command.



                                              cw ^R0ESC (^R=Control+R; 0 for register 0)



                                              will replace the word with the contents from reg. 0 and let's you repeat it with .



                                              This is great for cgn (VIM 7.4) to replace search patterns:




                                              • First search with / or *


                                              • cgn ^R0ESC


                                              • . to repeat on next match or n to skip






                                              share|improve this answer


























                                                2












                                                2








                                                2







                                                To repeat the paste use the change command.



                                                cw ^R0ESC (^R=Control+R; 0 for register 0)



                                                will replace the word with the contents from reg. 0 and let's you repeat it with .



                                                This is great for cgn (VIM 7.4) to replace search patterns:




                                                • First search with / or *


                                                • cgn ^R0ESC


                                                • . to repeat on next match or n to skip






                                                share|improve this answer













                                                To repeat the paste use the change command.



                                                cw ^R0ESC (^R=Control+R; 0 for register 0)



                                                will replace the word with the contents from reg. 0 and let's you repeat it with .



                                                This is great for cgn (VIM 7.4) to replace search patterns:




                                                • First search with / or *


                                                • cgn ^R0ESC


                                                • . to repeat on next match or n to skip







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Dec 22 '16 at 10:48









                                                laktaklaktak

                                                821510




                                                821510























                                                    1














                                                    Since it's not included yet, you usually replace strings with :%s/.../.../ and you can do this with the word under your cursor as well.




                                                    1. You enter the first part of the command, what you are searching for: :s/find/

                                                    2. Then you click <ctrl-r> and choose with the cursor the word you want to replace it with.

                                                    3. Then you click <ctrl-w> (small "word") or <ctrl-a> (big "word) to paste the word under the cursor into the command line

                                                    4. Then you finish the command.


                                                    See the link about how to use cursor stuff in the command line.






                                                    share|improve this answer




























                                                      1














                                                      Since it's not included yet, you usually replace strings with :%s/.../.../ and you can do this with the word under your cursor as well.




                                                      1. You enter the first part of the command, what you are searching for: :s/find/

                                                      2. Then you click <ctrl-r> and choose with the cursor the word you want to replace it with.

                                                      3. Then you click <ctrl-w> (small "word") or <ctrl-a> (big "word) to paste the word under the cursor into the command line

                                                      4. Then you finish the command.


                                                      See the link about how to use cursor stuff in the command line.






                                                      share|improve this answer


























                                                        1












                                                        1








                                                        1







                                                        Since it's not included yet, you usually replace strings with :%s/.../.../ and you can do this with the word under your cursor as well.




                                                        1. You enter the first part of the command, what you are searching for: :s/find/

                                                        2. Then you click <ctrl-r> and choose with the cursor the word you want to replace it with.

                                                        3. Then you click <ctrl-w> (small "word") or <ctrl-a> (big "word) to paste the word under the cursor into the command line

                                                        4. Then you finish the command.


                                                        See the link about how to use cursor stuff in the command line.






                                                        share|improve this answer













                                                        Since it's not included yet, you usually replace strings with :%s/.../.../ and you can do this with the word under your cursor as well.




                                                        1. You enter the first part of the command, what you are searching for: :s/find/

                                                        2. Then you click <ctrl-r> and choose with the cursor the word you want to replace it with.

                                                        3. Then you click <ctrl-w> (small "word") or <ctrl-a> (big "word) to paste the word under the cursor into the command line

                                                        4. Then you finish the command.


                                                        See the link about how to use cursor stuff in the command line.







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Apr 18 '17 at 8:20









                                                        erikbworkerikbwork

                                                        3951416




                                                        3951416























                                                            1














                                                            I usually use this: yw to yank foo, then delete bar with dw, and as final step, put foo from register 0 which holds yanked text using "0p. Repeat putting with period (.) as needed.



                                                            Also, instead of yw and dw, you can use yiw and diw (notice the extra i - it means inside). With that you can yank or delete word from any location inside it, not just on the beginning of word.






                                                            share|improve this answer






























                                                              1














                                                              I usually use this: yw to yank foo, then delete bar with dw, and as final step, put foo from register 0 which holds yanked text using "0p. Repeat putting with period (.) as needed.



                                                              Also, instead of yw and dw, you can use yiw and diw (notice the extra i - it means inside). With that you can yank or delete word from any location inside it, not just on the beginning of word.






                                                              share|improve this answer




























                                                                1












                                                                1








                                                                1







                                                                I usually use this: yw to yank foo, then delete bar with dw, and as final step, put foo from register 0 which holds yanked text using "0p. Repeat putting with period (.) as needed.



                                                                Also, instead of yw and dw, you can use yiw and diw (notice the extra i - it means inside). With that you can yank or delete word from any location inside it, not just on the beginning of word.






                                                                share|improve this answer















                                                                I usually use this: yw to yank foo, then delete bar with dw, and as final step, put foo from register 0 which holds yanked text using "0p. Repeat putting with period (.) as needed.



                                                                Also, instead of yw and dw, you can use yiw and diw (notice the extra i - it means inside). With that you can yank or delete word from any location inside it, not just on the beginning of word.







                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited Nov 10 '17 at 7:55

























                                                                answered Nov 9 '17 at 12:04









                                                                NinoNino

                                                                1113




                                                                1113























                                                                    0














                                                                    I use this plugin for expanding selection region:
                                                                    https://github.com/terryma/vim-expand-region



                                                                    So my combination for changing a word will be: vvpin any place of a word.



                                                                    I also have a hack for saving unnamed register contents after paste so I can repeat this.



                                                                    vnoremap p p:let @"=@0 <CR>
                                                                    vnoremap P P:let @"=@0 <CR>


                                                                    (my clipboard is autoselect)






                                                                    share|improve this answer




























                                                                      0














                                                                      I use this plugin for expanding selection region:
                                                                      https://github.com/terryma/vim-expand-region



                                                                      So my combination for changing a word will be: vvpin any place of a word.



                                                                      I also have a hack for saving unnamed register contents after paste so I can repeat this.



                                                                      vnoremap p p:let @"=@0 <CR>
                                                                      vnoremap P P:let @"=@0 <CR>


                                                                      (my clipboard is autoselect)






                                                                      share|improve this answer


























                                                                        0












                                                                        0








                                                                        0







                                                                        I use this plugin for expanding selection region:
                                                                        https://github.com/terryma/vim-expand-region



                                                                        So my combination for changing a word will be: vvpin any place of a word.



                                                                        I also have a hack for saving unnamed register contents after paste so I can repeat this.



                                                                        vnoremap p p:let @"=@0 <CR>
                                                                        vnoremap P P:let @"=@0 <CR>


                                                                        (my clipboard is autoselect)






                                                                        share|improve this answer













                                                                        I use this plugin for expanding selection region:
                                                                        https://github.com/terryma/vim-expand-region



                                                                        So my combination for changing a word will be: vvpin any place of a word.



                                                                        I also have a hack for saving unnamed register contents after paste so I can repeat this.



                                                                        vnoremap p p:let @"=@0 <CR>
                                                                        vnoremap P P:let @"=@0 <CR>


                                                                        (my clipboard is autoselect)







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Sep 7 '17 at 9:18









                                                                        user2656799user2656799

                                                                        1011




                                                                        1011























                                                                            0














                                                                            I'm using below key mapping to replace the current word with copied word.
                                                                            " replace with Register 0
                                                                            map <leader>rr ciw<C-r>0<Esc>



                                                                            yiw copy a word. Navigate to a word. ,rr replace the word.

                                                                            Leader key is map to ,.






                                                                            share|improve this answer
























                                                                            • ,rw would make more sense, and on QWERTY is probably a smidgen easier and faster to belt out. On DVORAK, I chose ,rc, which although it doesn't make much sense at all, it is easier and faster than all of them. On DVORAK, ,rw is a horror show ;)

                                                                              – Paul Parker
                                                                              Mar 3 at 1:00


















                                                                            0














                                                                            I'm using below key mapping to replace the current word with copied word.
                                                                            " replace with Register 0
                                                                            map <leader>rr ciw<C-r>0<Esc>



                                                                            yiw copy a word. Navigate to a word. ,rr replace the word.

                                                                            Leader key is map to ,.






                                                                            share|improve this answer
























                                                                            • ,rw would make more sense, and on QWERTY is probably a smidgen easier and faster to belt out. On DVORAK, I chose ,rc, which although it doesn't make much sense at all, it is easier and faster than all of them. On DVORAK, ,rw is a horror show ;)

                                                                              – Paul Parker
                                                                              Mar 3 at 1:00
















                                                                            0












                                                                            0








                                                                            0







                                                                            I'm using below key mapping to replace the current word with copied word.
                                                                            " replace with Register 0
                                                                            map <leader>rr ciw<C-r>0<Esc>



                                                                            yiw copy a word. Navigate to a word. ,rr replace the word.

                                                                            Leader key is map to ,.






                                                                            share|improve this answer













                                                                            I'm using below key mapping to replace the current word with copied word.
                                                                            " replace with Register 0
                                                                            map <leader>rr ciw<C-r>0<Esc>



                                                                            yiw copy a word. Navigate to a word. ,rr replace the word.

                                                                            Leader key is map to ,.







                                                                            share|improve this answer












                                                                            share|improve this answer



                                                                            share|improve this answer










                                                                            answered Feb 28 '18 at 10:11









                                                                            FisherFisher

                                                                            12117




                                                                            12117













                                                                            • ,rw would make more sense, and on QWERTY is probably a smidgen easier and faster to belt out. On DVORAK, I chose ,rc, which although it doesn't make much sense at all, it is easier and faster than all of them. On DVORAK, ,rw is a horror show ;)

                                                                              – Paul Parker
                                                                              Mar 3 at 1:00





















                                                                            • ,rw would make more sense, and on QWERTY is probably a smidgen easier and faster to belt out. On DVORAK, I chose ,rc, which although it doesn't make much sense at all, it is easier and faster than all of them. On DVORAK, ,rw is a horror show ;)

                                                                              – Paul Parker
                                                                              Mar 3 at 1:00



















                                                                            ,rw would make more sense, and on QWERTY is probably a smidgen easier and faster to belt out. On DVORAK, I chose ,rc, which although it doesn't make much sense at all, it is easier and faster than all of them. On DVORAK, ,rw is a horror show ;)

                                                                            – Paul Parker
                                                                            Mar 3 at 1:00







                                                                            ,rw would make more sense, and on QWERTY is probably a smidgen easier and faster to belt out. On DVORAK, I chose ,rc, which although it doesn't make much sense at all, it is easier and faster than all of them. On DVORAK, ,rw is a horror show ;)

                                                                            – Paul Parker
                                                                            Mar 3 at 1:00













                                                                            0














                                                                            First, navigate to the start of the word you want to yank. If you're in the middle of the word, just do b to go back to the start of it. Then do ye to yank the whole word, without any trailing spaces (yank to end). Finally, go to the word you want to replace - perhaps by doing w a few times - and do a vep to enter visual selection mode, select to the end of the word, and paste the contents last yanked.



                                                                            (If anyone wants to know why I didn't simply comment on the accepted answer, for the small modification of using ye rather than yw, it's because my reputation on this stack is still too low.)






                                                                            share|improve this answer




























                                                                              0














                                                                              First, navigate to the start of the word you want to yank. If you're in the middle of the word, just do b to go back to the start of it. Then do ye to yank the whole word, without any trailing spaces (yank to end). Finally, go to the word you want to replace - perhaps by doing w a few times - and do a vep to enter visual selection mode, select to the end of the word, and paste the contents last yanked.



                                                                              (If anyone wants to know why I didn't simply comment on the accepted answer, for the small modification of using ye rather than yw, it's because my reputation on this stack is still too low.)






                                                                              share|improve this answer


























                                                                                0












                                                                                0








                                                                                0







                                                                                First, navigate to the start of the word you want to yank. If you're in the middle of the word, just do b to go back to the start of it. Then do ye to yank the whole word, without any trailing spaces (yank to end). Finally, go to the word you want to replace - perhaps by doing w a few times - and do a vep to enter visual selection mode, select to the end of the word, and paste the contents last yanked.



                                                                                (If anyone wants to know why I didn't simply comment on the accepted answer, for the small modification of using ye rather than yw, it's because my reputation on this stack is still too low.)






                                                                                share|improve this answer













                                                                                First, navigate to the start of the word you want to yank. If you're in the middle of the word, just do b to go back to the start of it. Then do ye to yank the whole word, without any trailing spaces (yank to end). Finally, go to the word you want to replace - perhaps by doing w a few times - and do a vep to enter visual selection mode, select to the end of the word, and paste the contents last yanked.



                                                                                (If anyone wants to know why I didn't simply comment on the accepted answer, for the small modification of using ye rather than yw, it's because my reputation on this stack is still too low.)







                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered Apr 5 '18 at 18:52









                                                                                AnomalyAnomaly

                                                                                62




                                                                                62























                                                                                    0















                                                                                    1. use yw to yank the world, go to the world you want to change.

                                                                                    2. use v to select the world, ve or vw depending on your situation.

                                                                                    3. enter p to paster the world you copied to replace the selected block






                                                                                    share|improve this answer




























                                                                                      0















                                                                                      1. use yw to yank the world, go to the world you want to change.

                                                                                      2. use v to select the world, ve or vw depending on your situation.

                                                                                      3. enter p to paster the world you copied to replace the selected block






                                                                                      share|improve this answer


























                                                                                        0












                                                                                        0








                                                                                        0








                                                                                        1. use yw to yank the world, go to the world you want to change.

                                                                                        2. use v to select the world, ve or vw depending on your situation.

                                                                                        3. enter p to paster the world you copied to replace the selected block






                                                                                        share|improve this answer














                                                                                        1. use yw to yank the world, go to the world you want to change.

                                                                                        2. use v to select the world, ve or vw depending on your situation.

                                                                                        3. enter p to paster the world you copied to replace the selected block







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Aug 24 '18 at 2:09









                                                                                        ramwinramwin

                                                                                        1012




                                                                                        1012























                                                                                            0














                                                                                            To do this the VIM way, you intentionally use the yank, delete and other registers.



                                                                                            Register "0 is the yank register. Anything you yank will be put here, but deletes never touch register "0.



                                                                                            So, in your example, you had just yanked a word. To replace a word with what you just yanked, you take advantage of deletions never touching the yank register. So move to the target word, delete it with dw, then paste from your yank-register with "0p, or better yet, cw then ^R0 (which is repeatable).



                                                                                            A close opposite to the yank register is the small deletions register "-. Any small delete or change removal is put here, but yanks never touch "-. A deletion counts as small if it is less than a full line.



                                                                                            Registers "1-"9 are the delete history registers. With "1 containing the latest large deletion or change removal, and "9 containing the oldest large deletion or change removal. Only deletes that aren't small, i.e. deletes of one line or more, get pushed onto "1-"9.



                                                                                            For any operation that changes a register, a copy is also always placed in the default, a.k.a. unnamed register "". This is the register used when you don't explicitly name a register.



                                                                                            Register "_ is the black hole register, and it is always empty. If you delete to it, nothing in any register is changed at all, not even the default "" register, or the black hole register itself. The removed text is fully gone, apart from your undo history. Yanking to, or pasting from the black hole register does essentially nothing.



                                                                                            The black hole register "_ lets you do things like first one small deletion, then a number of other deletions into "_ without changing your small deletions register "-, then paste your first small deletion.



                                                                                            Other registers are the last inserted register "., the filename registers "% and "#, the command register ":, search register "/ and expression register "=.



                                                                                            You can get a list of all these registers and their contents by the command :register. That command is very useful to experiment with and learn what ends up where.






                                                                                            share|improve this answer






























                                                                                              0














                                                                                              To do this the VIM way, you intentionally use the yank, delete and other registers.



                                                                                              Register "0 is the yank register. Anything you yank will be put here, but deletes never touch register "0.



                                                                                              So, in your example, you had just yanked a word. To replace a word with what you just yanked, you take advantage of deletions never touching the yank register. So move to the target word, delete it with dw, then paste from your yank-register with "0p, or better yet, cw then ^R0 (which is repeatable).



                                                                                              A close opposite to the yank register is the small deletions register "-. Any small delete or change removal is put here, but yanks never touch "-. A deletion counts as small if it is less than a full line.



                                                                                              Registers "1-"9 are the delete history registers. With "1 containing the latest large deletion or change removal, and "9 containing the oldest large deletion or change removal. Only deletes that aren't small, i.e. deletes of one line or more, get pushed onto "1-"9.



                                                                                              For any operation that changes a register, a copy is also always placed in the default, a.k.a. unnamed register "". This is the register used when you don't explicitly name a register.



                                                                                              Register "_ is the black hole register, and it is always empty. If you delete to it, nothing in any register is changed at all, not even the default "" register, or the black hole register itself. The removed text is fully gone, apart from your undo history. Yanking to, or pasting from the black hole register does essentially nothing.



                                                                                              The black hole register "_ lets you do things like first one small deletion, then a number of other deletions into "_ without changing your small deletions register "-, then paste your first small deletion.



                                                                                              Other registers are the last inserted register "., the filename registers "% and "#, the command register ":, search register "/ and expression register "=.



                                                                                              You can get a list of all these registers and their contents by the command :register. That command is very useful to experiment with and learn what ends up where.






                                                                                              share|improve this answer




























                                                                                                0












                                                                                                0








                                                                                                0







                                                                                                To do this the VIM way, you intentionally use the yank, delete and other registers.



                                                                                                Register "0 is the yank register. Anything you yank will be put here, but deletes never touch register "0.



                                                                                                So, in your example, you had just yanked a word. To replace a word with what you just yanked, you take advantage of deletions never touching the yank register. So move to the target word, delete it with dw, then paste from your yank-register with "0p, or better yet, cw then ^R0 (which is repeatable).



                                                                                                A close opposite to the yank register is the small deletions register "-. Any small delete or change removal is put here, but yanks never touch "-. A deletion counts as small if it is less than a full line.



                                                                                                Registers "1-"9 are the delete history registers. With "1 containing the latest large deletion or change removal, and "9 containing the oldest large deletion or change removal. Only deletes that aren't small, i.e. deletes of one line or more, get pushed onto "1-"9.



                                                                                                For any operation that changes a register, a copy is also always placed in the default, a.k.a. unnamed register "". This is the register used when you don't explicitly name a register.



                                                                                                Register "_ is the black hole register, and it is always empty. If you delete to it, nothing in any register is changed at all, not even the default "" register, or the black hole register itself. The removed text is fully gone, apart from your undo history. Yanking to, or pasting from the black hole register does essentially nothing.



                                                                                                The black hole register "_ lets you do things like first one small deletion, then a number of other deletions into "_ without changing your small deletions register "-, then paste your first small deletion.



                                                                                                Other registers are the last inserted register "., the filename registers "% and "#, the command register ":, search register "/ and expression register "=.



                                                                                                You can get a list of all these registers and their contents by the command :register. That command is very useful to experiment with and learn what ends up where.






                                                                                                share|improve this answer















                                                                                                To do this the VIM way, you intentionally use the yank, delete and other registers.



                                                                                                Register "0 is the yank register. Anything you yank will be put here, but deletes never touch register "0.



                                                                                                So, in your example, you had just yanked a word. To replace a word with what you just yanked, you take advantage of deletions never touching the yank register. So move to the target word, delete it with dw, then paste from your yank-register with "0p, or better yet, cw then ^R0 (which is repeatable).



                                                                                                A close opposite to the yank register is the small deletions register "-. Any small delete or change removal is put here, but yanks never touch "-. A deletion counts as small if it is less than a full line.



                                                                                                Registers "1-"9 are the delete history registers. With "1 containing the latest large deletion or change removal, and "9 containing the oldest large deletion or change removal. Only deletes that aren't small, i.e. deletes of one line or more, get pushed onto "1-"9.



                                                                                                For any operation that changes a register, a copy is also always placed in the default, a.k.a. unnamed register "". This is the register used when you don't explicitly name a register.



                                                                                                Register "_ is the black hole register, and it is always empty. If you delete to it, nothing in any register is changed at all, not even the default "" register, or the black hole register itself. The removed text is fully gone, apart from your undo history. Yanking to, or pasting from the black hole register does essentially nothing.



                                                                                                The black hole register "_ lets you do things like first one small deletion, then a number of other deletions into "_ without changing your small deletions register "-, then paste your first small deletion.



                                                                                                Other registers are the last inserted register "., the filename registers "% and "#, the command register ":, search register "/ and expression register "=.



                                                                                                You can get a list of all these registers and their contents by the command :register. That command is very useful to experiment with and learn what ends up where.







                                                                                                share|improve this answer














                                                                                                share|improve this answer



                                                                                                share|improve this answer








                                                                                                edited 19 mins ago

























                                                                                                answered 47 mins ago









                                                                                                00prometheus00prometheus

                                                                                                1215




                                                                                                1215






























                                                                                                    draft saved

                                                                                                    draft discarded




















































                                                                                                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                                                                                    • Please be sure to answer the question. Provide details and share your research!

                                                                                                    But avoid



                                                                                                    • Asking for help, clarification, or responding to other answers.

                                                                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                                                                    To learn more, see our tips on writing great answers.




                                                                                                    draft saved


                                                                                                    draft discarded














                                                                                                    StackExchange.ready(
                                                                                                    function () {
                                                                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f88714%2fvim-how-can-i-do-a-change-word-using-the-current-paste-buffer%23new-answer', 'question_page');
                                                                                                    }
                                                                                                    );

                                                                                                    Post as a guest















                                                                                                    Required, but never shown





















































                                                                                                    Required, but never shown














                                                                                                    Required, but never shown












                                                                                                    Required, but never shown







                                                                                                    Required, but never shown

































                                                                                                    Required, but never shown














                                                                                                    Required, but never shown












                                                                                                    Required, but never shown







                                                                                                    Required, but never shown







                                                                                                    Popular posts from this blog

                                                                                                    宮崎県

                                                                                                    濃尾地震

                                                                                                    シテ島