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

yanking into register and using that in command

Expand Messages
  • Denis Perelyubskiy
    hello, I am trying to emulate textpad. In textpad, when cursor is over some word and you press ctrl-f5 the search box pops up, and a word is in the input area.
    Message 1 of 4 , Aug 1, 2006
    • 0 Attachment
      hello,

      I am trying to emulate textpad. In textpad, when cursor is over some
      word and you press ctrl-f5 the search box pops up, and a word is in the
      input area.

      So, an equivalent behavior (at least for now :-)) in vim is to press
      ctrl-f5 and have a word show up in the string
      :vimgrep/WORD/j c:/projects/foo/**/*.[ch]

      I know how to do this in a kludgy way, by yanking the word with viwy.
      However, that "kills" the * register. The question is whether it is
      possible to do what i want through some temp register, without "killing"
      the * (or using the * and then restoring it):

      I could map ctrl f5 to something like (kludgy):
      nmap <C-F5> <ESC>viwy:vimgrep/<S-Insert>/j c:/projects/kopera/**/*.[ch]
      map! <C-F5> <ESC>viwy:vimgrep/<S-Insert>/j c:/projects/kopera/**/*.[ch]

      There must be a prettier way of doing that (and a way which does not
      kill the *)

      Could someone please point me to the right direction?

      thanks,
      denis
      --
      // mailto: Denis Perelyubskiy <lists at overwhelmTAKECAPITALSOUT dot net>
      // icq : 12359698
    • Ilya
      ... nmap :vimgrep/ /j c:/projects/kopera/**/*.[ch] map! :vimgrep/ /j c:/projects/kopera/**/*.[ch]
      Message 2 of 4 , Aug 2, 2006
      • 0 Attachment
        Denis Perelyubskiy wrote:
        > hello,
        >
        > I am trying to emulate textpad. In textpad, when cursor is over some
        > word and you press ctrl-f5 the search box pops up, and a word is in the
        > input area.
        >
        > So, an equivalent behavior (at least for now :-)) in vim is to press
        > ctrl-f5 and have a word show up in the string
        > :vimgrep/WORD/j c:/projects/foo/**/*.[ch]
        >
        > I know how to do this in a kludgy way, by yanking the word with viwy.
        > However, that "kills" the * register. The question is whether it is
        > possible to do what i want through some temp register, without "killing"
        > the * (or using the * and then restoring it):
        >
        > I could map ctrl f5 to something like (kludgy):
        > nmap <C-F5> <ESC>viwy:vimgrep/<S-Insert>/j c:/projects/kopera/**/*.[ch]
        > map! <C-F5> <ESC>viwy:vimgrep/<S-Insert>/j c:/projects/kopera/**/*.[ch]
        >
        nmap <C-F5> <ESC>:vimgrep/<C-R><C-W>/j c:/projects/kopera/**/*.[ch]
        map! <C-F5> <ESC>:vimgrep/<C-R><C-W>/j c:/projects/kopera/**/*.[ch]

        :help c_<C-R>_<C-W>

        > There must be a prettier way of doing that (and a way which does not
        > kill the *)
        >
        > Could someone please point me to the right direction?
        >
        > thanks,
        > denis
        >
      • A.J.Mechelynck
        ... It only kills the * register (the clipboard) if you have :set clipboard=unnamed . Otherwise it clobbers only registers (the unnamed or default
        Message 3 of 4 , Aug 2, 2006
        • 0 Attachment
          Denis Perelyubskiy wrote:
          > hello,
          >
          > I am trying to emulate textpad. In textpad, when cursor is over some
          > word and you press ctrl-f5 the search box pops up, and a word is in the
          > input area.
          >
          > So, an equivalent behavior (at least for now :-)) in vim is to press
          > ctrl-f5 and have a word show up in the string
          > :vimgrep/WORD/j c:/projects/foo/**/*.[ch]
          >
          > I know how to do this in a kludgy way, by yanking the word with viwy.
          > However, that "kills" the * register. The question is whether it is
          > possible to do what i want through some temp register, without "killing"
          > the * (or using the * and then restoring it):

          It only kills the * register (the clipboard) if you have ":set
          clipboard=unnamed". Otherwise it clobbers only registers " (the
          "unnamed" or default register) and 0 (the "last yank" register). You can
          yank into any other register of your choice (usually a to z but there
          are a few other "special-purpose" registers) by prefixing the y of the
          yank command with "x where x is the one-character register name: for
          instance,

          viw"zy

          uses register z (rather than the unnamed register and, with
          "clipboard=unnamed", the clipboard) for the yank.

          You can also access any register as a variable by prefixing its
          one-character name with an at-sign as in

          :let save_clipboard = @*

          or

          :let @* = save_clipboard

          In Insert/Replace and Command-line modes, you can also insert any
          register's contents by means of Ctrl-R followed by the register's name:
          for instance, Ctrl-R / (or, in a mapping, <C-R>/ ) inserts the latest
          search pattern.

          see ":help copy-move" and read all of section 5, i.e., until the
          horizontal separation before "6. Formatting text".

          >
          > I could map ctrl f5 to something like (kludgy):
          > nmap <C-F5> <ESC>viwy:vimgrep/<S-Insert>/j c:/projects/kopera/**/*.[ch]
          > map! <C-F5> <ESC>viwy:vimgrep/<S-Insert>/j c:/projects/kopera/**/*.[ch]
          >
          > There must be a prettier way of doing that (and a way which does not
          > kill the *)
          >
          > Could someone please point me to the right direction?
          >
          > thanks,
          > denis

          Best regards,
          Tony.
        • Gautam Iyer
          ... The on command line expands to the word under the cursor. I generally use command! PartialWordGrep grep -I *.* in my ~/.vimrc, which is
          Message 4 of 4 , Aug 2, 2006
          • 0 Attachment
            On Tue, Aug 01, 2006 at 05:25:44PM -0700, Denis Perelyubskiy wrote:

            > I am trying to emulate textpad. In textpad, when cursor is over some
            > word and you press ctrl-f5 the search box pops up, and a word is in the
            > input area.
            >
            > So, an equivalent behavior (at least for now :-)) in vim is to press
            > ctrl-f5 and have a word show up in the string
            > :vimgrep/WORD/j c:/projects/foo/**/*.[ch]
            >
            > I know how to do this in a kludgy way, by yanking the word with viwy.
            > However, that "kills" the * register. The question is whether it is
            > possible to do what i want through some temp register, without
            > "killing" the * (or using the * and then restoring it):

            The <cword> on command line expands to the word under the cursor. I
            generally use

            command! PartialWordGrep grep -I <cword> *.*

            in my ~/.vimrc, which is similar to what you want to do. You can modify
            as needed. Also relevant would be the expand() function.

            GI

            --
            POLITICS THROUGH COWS -- A TALIBAN CORPORATION:
            You have all the cows in Afghanistan, which is two. You don't milk them
            because you cannot touch any creature's private parts. At night when no
            one is looking, you milk both of them. Then you kill them and claim a US
            bomb blew them up while they were in the hospital.
          Your message has been successfully submitted and would be delivered to recipients shortly.