Loading ...
Sorry, an error occurred while loading the content.
 

invoking yanked register into colon command

Expand Messages
  • Guillaume Bog
    Hi vimers, I getting used to many vim features but I still lack some skills, even after having read the user-manual. For example, I do often want to replace a
    Message 1 of 8 , Mar 31, 2007
      Hi vimers,

      I getting used to many vim features but I still lack some skills, even
      after having read the user-manual. For example, I do often want to
      replace a name in the text with another. What I used to do is
      selecting it with mouse and type
      :%s/<ctrl-ins>/newname/gc
      Is there a way to do this with the mouse (and without retyping the name) ?
      What I want is maybe something like 'invoking a yanked register in my
      colon command'

      Thanks
    • Christian Ebert
      ... c -- Vim plugin to paste current GNU Screen buffer in (almost) any mode:
      Message 2 of 8 , Mar 31, 2007
        * Guillaume Bog on Saturday, March 31, 2007 at 23:04:34 +0800:
        > I getting used to many vim features but I still lack some skills, even
        > after having read the user-manual. For example, I do often want to
        > replace a name in the text with another. What I used to do is
        > selecting it with mouse and type
        > :%s/<ctrl-ins>/newname/gc
        > Is there a way to do this with the mouse (and without retyping the name) ?
        > What I want is maybe something like 'invoking a yanked register in my
        > colon command'

        :help c_CTRL-R

        c
        --
        Vim plugin to paste current GNU Screen buffer in (almost) any mode:
        <http://www.vim.org/scripts/script.php?script_id=1512>
      • Tobia
        ... I guess you mean with the keyboard . Yes, there is. Ctrl-R / pull to the commandline the last search pattern Ctrl-R ...the last unnamed delete or
        Message 3 of 8 , Mar 31, 2007
          Guillaume Bog wrote:
          > What I used to do is selecting it with mouse and type
          > :%s/<ctrl-ins>/newname/gc
          > Is there a way to do this with the mouse

          I guess you mean "with the keyboard". Yes, there is.

          Ctrl-R / pull to the commandline the last search pattern
          Ctrl-R " ...the last unnamed delete or yank
          Ctrl-R * ...the current selection (X11 only)
          Ctrl-R + ...the clipboard contents
          Ctrl-R x ...the contents of register x
          Ctrl-R Ctrl-W ...the current word under the cursor

          See :help c_CTRL-R


          Tobia
        • Georg Dahn
          Hi! ... I have the following in my vimrc file: function MakeSearchString(str) return substitute(escape(@ , /.*$^~[] ), n , n , g ) endfunction
          Message 4 of 8 , Mar 31, 2007
            Hi!

            > For example, I do often want to
            > replace a name in the text with another. What I used to do is
            > selecting it with mouse and type
            > :%s/<ctrl-ins>/newname/gc
            > Is there a way to do this with the mouse (and without retyping the name) ?
            > What I want is maybe something like 'invoking a yanked register in my
            > colon command'

            I have the following in my vimrc file:

            function MakeSearchString(str)
            return substitute(escape(@", '\\/.*$^~[]'), '\n', '\\n', 'g')
            endfunction

            function! <SID>VisualSearch(direction)
            if a:direction == '#'
            let l:rhs = "y?"
            else
            let l:rhs = "y/"
            endif
            let l:rhs = l:rhs . "\<C-R>=MakeSearchString(@\")\<CR>\<CR>gV"
            return l:rhs
            endfunction

            vnoremap <expr> * <SID>VisualSearch('*')
            vnoremap <expr> # <SID>VisualSearch('#')

            vnoremap <F3> y/<C-R>=MakeSearchString(@")<CR>
            vnoremap <S-F3> y?<C-R>=MakeSearchString(@")<CR>
            vnoremap <M-F3> y:%s/<C-R>=MakeSearchString(@")<CR>/

            With this just select a text and by typing <F3> you can search for the
            selected text and by typing <M-F3> you can replace it easily. '*'
            searches forward and '#' backwards like '*' and '#' do for the word
            under the cursor in normal mode.

            Best regards,
            Georg
          • Guillaume Bog
            ... Thanks all of you for your answers. I grab the tip with Ctrl-R because I have to use vim on many different computers, but will consider adding the script
            Message 5 of 8 , Mar 31, 2007
              On 01/04/07, Georg Dahn <gorgyd@...> wrote:
              > Hi!
              >
              > > For example, I do often want to
              > > replace a name in the text with another. What I used to do is
              > > selecting it with mouse and type
              > > :%s/<ctrl-ins>/newname/gc
              > > Is there a way to do this with the mouse (and without retyping the name) ?
              > > What I want is maybe something like 'invoking a yanked register in my
              > > colon command'
              >
              > I have the following in my vimrc file:
              >
              > function MakeSearchString(str)
              > return substitute(escape(@", '\\/.*$^~[]'), '\n', '\\n', 'g')
              > endfunction
              >
              > function! <SID>VisualSearch(direction)
              > if a:direction == '#'
              > let l:rhs = "y?"
              > else
              > let l:rhs = "y/"
              > endif
              > let l:rhs = l:rhs . "\<C-R>=MakeSearchString(@\")\<CR>\<CR>gV"
              > return l:rhs
              > endfunction
              >
              > vnoremap <expr> * <SID>VisualSearch('*')
              > vnoremap <expr> # <SID>VisualSearch('#')
              >
              > vnoremap <F3> y/<C-R>=MakeSearchString(@")<CR>
              > vnoremap <S-F3> y?<C-R>=MakeSearchString(@")<CR>
              > vnoremap <M-F3> y:%s/<C-R>=MakeSearchString(@")<CR>/
              >
              > With this just select a text and by typing <F3> you can search for the
              > selected text and by typing <M-F3> you can replace it easily. '*'
              > searches forward and '#' backwards like '*' and '#' do for the word
              > under the cursor in normal mode.
              >
              > Best regards,
              > Georg

              Thanks all of you for your answers. I grab the tip with Ctrl-R because
              I have to use vim on many different computers, but will consider
              adding the script when I'll refresh my vimrces.

              Guillaume
            • Georg Dahn
              Hi! There is an error: The function ... should be function MakeSearchString(str) return substitute(escape(a:str, /.*$^~[] ), n , n , g ) endfunction I
              Message 6 of 8 , Apr 1, 2007
                Hi!

                There is an error: The function

                > function MakeSearchString(str)
                > return substitute(escape(@", '\\/.*$^~[]'), '\n', '\\n', 'g')
                > endfunction

                should be

                function MakeSearchString(str)
                return substitute(escape(a:str, '\\/.*$^~[]'), '\n', '\\n', 'g')
                endfunction

                I have not seen this error before, because the function did the expected
                things even with this error.

                Best regards,
                Georg
              • Gene Kwiecinski
                ... name) ? ... Me, I go to whatever I m looking for, hit v , then use normal motion commands (eg, 3e ) to highlight the text in question, instead of using
                Message 7 of 8 , Apr 2, 2007
                  >after having read the user-manual. For example, I do often want to
                  >replace a name in the text with another. What I used to do is
                  >selecting it with mouse and type
                  >:%s/<ctrl-ins>/newname/gc
                  >Is there a way to do this with the mouse (and without retyping the
                  name) ?
                  >What I want is maybe something like 'invoking a yanked register in my
                  >colon command'

                  Me, I go to whatever I'm looking for, hit 'v', then use normal motion
                  commands (eg, "3e") to highlight the text in question, instead of using
                  the moose.

                  If a single word, '*' will automagically highlight and search for the
                  word under the cursor.

                  From there, once you highlighted the exact pattern you want, can just
                  use

                  :%s//newname/gc

                  as it remembers what you just looked for. No need to reinsert it for
                  the 's' command.
                • John Little
                  ... And with vnoremap * y:exe norm! / . escape(@@, /*. [$^~ ) . r in your .vimrc, it works for more than a single word, any stuff up to a line s
                  Message 8 of 8 , Apr 3, 2007
                    Gene Kwiecinski wrote:

                    > Me, I go to whatever I'm looking for, hit 'v', then use normal motion
                    > commands (eg, "3e") to highlight the text in question, instead of using
                    > the mouse.
                    >
                    > If a single word, '*' will automagically highlight and search for the
                    > word under the cursor.

                    And with

                    vnoremap * y:exe 'norm! /' . escape(@@, '/*.\[$^~') . "\r"<cr>

                    in your .vimrc, it works for more than a single word, any stuff up to a
                    line's worth.

                    HTH
                    John
                  Your message has been successfully submitted and would be delivered to recipients shortly.