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

Re: How to use variables in command-line mode searching

Expand Messages
  • Teemu Likonen
    ... Interactively you can use Ctrl-r = and then type any expression to be evaluated. Type a and then Enter to have variable a evaluated, like ... Here
    Message 1 of 8 , Aug 6, 2009
    • 0 Attachment
      On 2009-08-06 05:49 (-0700), Pento wrote:

      > Is it possible to use predefined variables in command-line mode
      > searching in vim?
      > Example:
      > we have some text like " bla-bla bar"
      >
      > :let a="foo"
      > :%s/bar/$a/g
      >
      > Result:
      > " bla-bla foo"

      Interactively you can use "Ctrl-r =" and then type any expression to be
      evaluated. Type "a" and then Enter to have variable "a" evaluated, like
      this:

      :%s/bar/<Ctrl-r>=a<Enter>/g

      Here <Ctrl-r> and <Enter> mean that you really press those keys.

      You can also use :execute command to evaluate expressions and have the
      result of evaluation become the command to run, like:

      execute '%s/var/' . a . '/g'

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • sergio
      let @a= word ... =@a is reg a :) ... --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use maillist. For
      Message 2 of 8 , Aug 6, 2009
      • 0 Attachment
        let @a="word"

        :%s/word/\=@a/g

        \=@a is reg 'a' :)

        On 6 ago, 10:04, Teemu Likonen <tliko...@...> wrote:
        > On 2009-08-06 05:49 (-0700), Pento wrote:
        >
        > > Is it possible to use predefined variables in  command-line mode
        > > searching in vim?
        > > Example:
        > > we have some text like " bla-bla bar"
        >
        > > :let a="foo"
        > > :%s/bar/$a/g
        >
        > > Result:
        > > " bla-bla foo"
        >
        > Interactively you can use "Ctrl-r =" and then type any expression to be
        > evaluated. Type "a" and then Enter to have variable "a" evaluated, like
        > this:
        >
        >     :%s/bar/<Ctrl-r>=a<Enter>/g
        >
        > Here <Ctrl-r> and <Enter> mean that you really press those keys.
        >
        > You can also use :execute command to evaluate expressions and have the
        > result of evaluation become the command to run, like:
        >
        >     execute '%s/var/' . a . '/g'
        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • sergio
        let @a= new %s/old/ =@a/g ... --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use maillist. For more
        Message 3 of 8 , Aug 6, 2009
        • 0 Attachment
          let @a="new"

          %s/old/\=@a/g



          On 6 ago, 10:59, sergio <voye...@...> wrote:
          > let @a="word"
          >
          > :%s/word/\=@a/g
          >
          > \=@a   is reg 'a'  :)
          >
          > On 6 ago, 10:04, Teemu Likonen <tliko...@...> wrote:
          >
          > > On 2009-08-06 05:49 (-0700), Pento wrote:
          >
          > > > Is it possible to use predefined variables in  command-line mode
          > > > searching in vim?
          > > > Example:
          > > > we have some text like " bla-bla bar"
          >
          > > > :let a="foo"
          > > > :%s/bar/$a/g
          >
          > > > Result:
          > > > " bla-bla foo"
          >
          > > Interactively you can use "Ctrl-r =" and then type any expression to be
          > > evaluated. Type "a" and then Enter to have variable "a" evaluated, like
          > > this:
          >
          > >     :%s/bar/<Ctrl-r>=a<Enter>/g
          >
          > > Here <Ctrl-r> and <Enter> mean that you really press those keys.
          >
          > > You can also use :execute command to evaluate expressions and have the
          > > result of evaluation become the command to run, like:
          >
          > >     execute '%s/var/' . a . '/g'
          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • John Beckett
          Please bottom post on this list. Quote a small (relevant) part of the message you are replying to, and put your text underneath. See the list guidelines:
          Message 4 of 8 , Aug 6, 2009
          • 0 Attachment
            Please bottom post on this list. Quote a small (relevant) part
            of the message you are replying to, and put your text underneath.

            See the list guidelines:
            http://groups.google.com/group/vim_use/web/vim-information


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • KKde
            ... How could I enter in command line.. I tried directly by pressing those kesy in command line..But it s not working... Can you let me know what
            Message 5 of 8 , Aug 6, 2009
            • 0 Attachment
              >
              > Interactively you can use "Ctrl-r =" and then type any expression to be
              > evaluated. Type "a" and then Enter to have variable "a" evaluated, like
              > this:
              >
              >     :%s/bar/<Ctrl-r>=a<Enter>/g
              >
              > Here <Ctrl-r> and <Enter> mean that you really press those keys.

              How could I enter <Ctrl-r> in command line.. I tried directly by
              pressing those kesy in command line..But it's not working... Can you
              let me know what wrong I am doing here?

              Thanks,
              Sharat
              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • John Beckett
              ... The =2+3 is replaced with 5 . You could also have entered =x where x is a variable. John --~--~---------~--~----~------------~-------~--~----~ You
              Message 6 of 8 , Aug 7, 2009
              • 0 Attachment
                KKde wrote:
                > How could I enter <Ctrl-r> in command line.. I tried directly
                > by pressing those kesy in command line.

                In normal mode (after pressing Esc), type the following:

                :echo<space><ctrl-r>=2+3<enter><enter>

                The "=2+3" is replaced with "5". You could also have entered
                "=x" where x is a variable.

                John


                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • KKde
                ... Thanks..It worked :) --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use maillist. For more information,
                Message 7 of 8 , Aug 7, 2009
                • 0 Attachment
                  > In normal mode (after pressing Esc), type the following:
                  >
                  >   :echo<space><ctrl-r>=2+3<enter><enter>
                  >
                  > The "=2+3" is replaced with "5". You could also have entered
                  > "=x" where x is a variable.
                  >

                  Thanks..It worked :)
                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                Your message has been successfully submitted and would be delivered to recipients shortly.