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

Completion on command line?

Expand Messages
  • yahoogroups@vikas.mailshell.com
    Suppose I have a file containing very long words like verylongword and I want to replace it with short ... I tire of typing the verylongword . Is there a
    Message 1 of 8 , Feb 1, 2002
    • 0 Attachment
      Suppose I have a file containing very long words like 'verylongword' and I want
      to replace it with 'short'

      :%s/verylongword/short/g

      I tire of typing the 'verylongword'.

      Is there a way I can do keyword completion here similar to Ctrl-P/N in insert
      mode?

      Thanks

      __________________________________________________
      Do You Yahoo!?
      Great stuff seeking new owners in Yahoo! Auctions!
      http://auctions.yahoo.com
    • Thomas S. Urban
      ... You could go to the command-line edit window and do it there where ... -- Stop searching forever. Happiness is just next to you.
      Message 2 of 8 , Feb 1, 2002
      • 0 Attachment
        On Fri, Feb 01, 2002 at 05:29:06PM -0800, yahoogroups@... wrote:
        > Suppose I have a file containing very long words like 'verylongword' and I want
        > to replace it with 'short'
        >
        > :%s/verylongword/short/g
        >
        > I tire of typing the 'verylongword'.
        >
        > Is there a way I can do keyword completion here similar to Ctrl-P/N in insert
        > mode?

        You could go to the command-line edit window and do it there where
        Ctrl-P/N work like you would expect. q: or CTRL-F from :

        :help cmdline-window


        --
        Stop searching forever. Happiness is just next to you.
      • yahoogroups@vikas.mailshell.com
        Hm... http://vim.sourceforge.net/scripts/script.php?script_id=146 seems to do what I want. But it is all black magic to me. Could some kind soul please break
        Message 3 of 8 , Feb 1, 2002
        • 0 Attachment
          Hm...

          http://vim.sourceforge.net/scripts/script.php?script_id=146

          seems to do what I want.

          But it is all black magic to me.

          Could some kind soul please break this down and explain it step by step?

          Thanks

          __________________________________________________
          Do You Yahoo!?
          Great stuff seeking new owners in Yahoo! Auctions!
          http://auctions.yahoo.com
        • Tim Chase
          ... though i haven t found such a way, ^R works as it does in insert mode, such that if you have thisisalongword stored in x, you can type ^Rx from the
          Message 4 of 8 , Feb 1, 2002
          • 0 Attachment
            >Is there a way I can do keyword completion here similar to
            >Ctrl-P/N in insert mode?

            though i haven't found such a way, ^R works as it does in insert mode, such
            that if you have "thisisalongword" stored in "x, you can type ^Rx from the
            command-line prompt and it will insert the contents of that register. ^n
            and ^p act more like a history recall on the command line (the same
            functionality as up-arrow and down-arrow) hth,

            -tim

            _________________________________________________________________
            Send and receive Hotmail on your mobile device: http://mobile.msn.com
          • Hari Krishna Dara
            On Fri, 1 Feb 2002 at 5:29pm, yahoogroups@vikas.mailshell.com wrote:Suppose I have a file containing very long words like verylongword and I want to
            Message 5 of 8 , Feb 3, 2002
            • 0 Attachment
              On Fri, 1 Feb 2002 at 5:29pm, yahoogroups@... wrote:

              > Suppose I have a file containing very long words like 'verylongword' and I want
              > to replace it with 'short'
              >
              > :%s/verylongword/short/g
              >
              > I tire of typing the 'verylongword'.
              >
              > Is there a way I can do keyword completion here similar to Ctrl-P/N in insert
              > mode?
              >
              > Thanks
              >

              I would do this by first doing a search on the word that I want to
              replace, which is easy by pressing * or # on the word, and then by running
              the following substitute:

              :%s//small/g

              I also have the following mapping:

              :cnoremap <C-X><C-G> <C-R>=expand ("<cword>")<C-M>

              so I can also start typing the substitute command when the cursor is on
              the word to be replaced, and press ^X^G to get it onto the command line
              when I have to actually type the word.

              HTH,
              Hari



              _________________________________________________________
              Do You Yahoo!?
              Get your free @... address at http://mail.yahoo.com
            • Douglas L . Potts
              ... Well, step by step, no. As it was provided to me by others (specifically Stephan Roemer), I am only familiar with the workings, to intimate. But it
              Message 6 of 8 , Feb 4, 2002
              • 0 Attachment
                On Fri, Feb 01, 2002 at 08:05:21PM -0800 yahoogroups@... wrote:
                > Hm...
                >
                > http://vim.sourceforge.net/scripts/script.php?script_id=146
                >
                > seems to do what I want.
                >
                > But it is all black magic to me.
                >
                > Could some kind soul please break this down and explain it step by step?

                Well, step by step, no. As it was provided to me by others
                (specifically Stephan Roemer), I am only familiar with the workings, to
                intimate. But it basically plays with copying the current command line,
                escaping back to the file, appending the copied command line into the
                file, trying to do a normal <c-x><c-n>/<c-p> completion, and the copies
                that from the file (leaving it apparently 'untouched') back onto the
                command line.

                Is that good enough, or do you need more?
                -Doug

                --
                *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                Douglas L. Potts
                Any resemblance between the above views and those of my employer, my
                terminal, or the view out my window are purely coincidental. Any
                resemblance between the above and my own views is non-deterministic.
                The question of the existence of views in the absence of anyone to hold
                them is left as an exercise for the reader. The question of the
                existence of the reader is left as an exercise for the second god
                coefficient. (A discussion of non-orthogonal, non-integral polytheism
                is beyond the scope of this article.) -Ralph Jennings
                GPG Fingerprint: 768A EEF8 197A 4C9A 5EF7 DA5B 464C 97DF DCD5 68C2
                *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
              • yahoogroups@vikas.mailshell.com
                ... Please, if you can. At a high level, I know that it does what you mention it does above. It has to. But I was more interested in how it accomplishes it in
                Message 7 of 8 , Feb 4, 2002
                • 0 Attachment
                  --- In vim@y..., "Douglas L . Potts" <pottsdl@y...> wrote:
                  > On Fri, Feb 01, 2002 at 08:05:21PM -0800 yahoogroups@v... wrote:
                  > > Hm...
                  > >
                  > > http://vim.sourceforge.net/scripts/script.php?script_id=146
                  > >
                  > > seems to do what I want.
                  > >
                  > > But it is all black magic to me.
                  > >
                  > > Could some kind soul please break this down and explain it step by step?
                  >
                  > Well, step by step, no. As it was provided to me by others
                  > (specifically Stephan Roemer), I am only familiar with the workings, to
                  > intimate. But it basically plays with copying the current command line,
                  > escaping back to the file, appending the copied command line into the
                  > file, trying to do a normal <c-x><c-n>/<c-p> completion, and the copies
                  > that from the file (leaving it apparently 'untouched') back onto the
                  > command line.
                  >
                  > Is that good enough, or do you need more?
                  > -Doug

                  Please, if you can. At a high level, I know that it does what you mention it
                  does above. It has to. But I was more interested in how it accomplishes it in
                  such a seamless fashion!

                  It will help me to learn how to use the Vim scripting language better.

                  Thanks,
                  Vikas


                  __________________________________________________
                  Do You Yahoo!?
                  Great stuff seeking new owners in Yahoo! Auctions!
                  http://auctions.yahoo.com
                • Benji Fisher
                  ... I ll take a stab at it. It starts with some comments, indicating that Stefan Roemer sent it to Johannes Zellner and the list (although it seems that
                  Message 8 of 8 , Feb 4, 2002
                  • 0 Attachment
                    yahoogroups@... wrote:
                    >
                    > --- In vim@y..., "Douglas L . Potts" <pottsdl@y...> wrote:
                    > > On Fri, Feb 01, 2002 at 08:05:21PM -0800 yahoogroups@v... wrote:
                    > > > Hm...
                    > > >
                    > > > http://vim.sourceforge.net/scripts/script.php?script_id=146
                    > > >
                    > > > seems to do what I want.
                    > > >
                    > > > But it is all black magic to me.
                    > > >
                    > > > Could some kind soul please break this down and explain it step by step?
                    > >
                    > > Well, step by step, no. As it was provided to me by others
                    > > (specifically Stephan Roemer), I am only familiar with the workings, to
                    > > intimate. But it basically plays with copying the current command line,
                    > > escaping back to the file, appending the copied command line into the
                    > > file, trying to do a normal <c-x><c-n>/<c-p> completion, and the copies
                    > > that from the file (leaving it apparently 'untouched') back onto the
                    > > command line.
                    > >
                    > > Is that good enough, or do you need more?
                    > > -Doug
                    >
                    > Please, if you can. At a high level, I know that it does what you mention it
                    > does above. It has to. But I was more interested in how it accomplishes it in
                    > such a seamless fashion!
                    >
                    > It will help me to learn how to use the Vim scripting language better.

                    I'll take a stab at it. It starts with some comments, indicating that
                    Stefan Roemer sent it to Johannes Zellner and the list (although it seems that
                    Douglas Potts posted it to VimOlnline):

                    " ===========================================================================
                    " Date: Mon, 12 Jul 1999 15:31:21 +0200
                    " From: Stefan Roemer <roemer@...-muenchen.de>
                    " To: Johannes Zellner <johannes@...>
                    " Cc: Vim users mailing list <vim@...>
                    " Subject: Re: command & `complete'

                    Now, standard stuff for plugin files. This prevents multiple loading,
                    and allows the user to turn it off. :help write-plugin

                    if exists('g:Cmdline_loaded') | finish | endif
                    let g:Cmdline_loaded = 1

                    For the sake of explanation, I moved this from the bottom of the script.
                    There is a similar map for searching backwards. In Command mode, <C-X><C-B>
                    is mapped to do the following: move to the start of the line (<C-B>); insert
                    a " character (to comment out the whole line); return to Normal mode (<CR>)
                    while saving the command in the : register (:help @:); assign the : register
                    to the l register; call the function with argument 0; return to Command mode
                    (:); and insert the l register (modified by the function) on the Command line
                    (:help c_ctrl-r).

                    " search forward
                    cno <c-x><c-n> <c-b>"<cr>:let@l=@:<cr>:call CmdlineCompl(0)<cr>:<c-r>l

                    This defines a function, which is called by the maps near the bottom of
                    the file:

                    function! CmdlineCompl(flag)

                    Next, some customization. The user may set these global variables in his
                    (her) vimrc file. If not, they are given default values. Also, set the local
                    variables n and s.

                    " --- user customizable: completion style (CTRL-X CTRL-???) --------
                    if !exists("g:ccp_cmd")|let g:ccp_cmd="\<c-x>\<c-n>"|endif
                    " ------------------------------------------------------------------
                    " Note: this function changes the p and q mark registers
                    " ------------------------------------------------------------------
                    if !exists("g:ccp_pos")|let g:ccp_pos=0|endif
                    if !exists("g:ccp_lst")|let g:ccp_lst=0|endif|let n=g:ccp_lst
                    if !exists("g:ccp_str")|let g:ccp_str=""|endif|let s=g:ccp_str

                    Now, start to do something. The following lines were combined into one
                    with "|" separators in the original. Save the m register (:help
                    expr-register) in the local variable m, set the 'q mark (:mark q would be
                    simpler), add an empty line (:help :put and :help "_) and then the complicated
                    :execute line. This inserts the value of the l register, which is defined in
                    the maps that call this function; moves to the start of the line (^); replace
                    the leading " character with a raw <C-X>; delete the <C-X> (saving it in the
                    unnamed register); go to the end of the line; set the p mark (mp); put the
                    <C-X> (from the unnamed register); move back one word; delete up to, but not
                    including, the <C-X> into the m register ("mdt' . "\<C-X>"); delete the <C-X>.

                    let m=@m
                    exe'norm mq'
                    put_
                    exe 'norm"lp^r' . "\<c-x>" . 'x$mppb"mdt' . "\<c-x>" . 'x'

                    That's a start. The goal of all that seems to be to get the last word
                    from the Command line into the m register, which is used below. If you want
                    another way to see the above, try typing the :execute 'norm... line one step
                    at a time: after setting the l register appropriately, type the following in
                    Normal mode, where <C-X> is NOT typed literally:
                    "lp^r<c-x>x$mppb"mdt\<c-x>x
                    You can type the following lines individually in Command mode to see what they
                    do.

                    if match(n,@m)||col("`p")!=g:ccp_pos
                    let s=""|let n=@m|let g:ccp_pos=col("`p")
                    elseif s[0]=~"\<c-p>\<c-n>"[a:flag]
                    let s=strpart(s,1,999999)|let@m=n
                    else
                    let s=s."\<c-p>\<c-n>"[!a:flag]|let m=n
                    endif

                    After all that conditional stuff, which modifies the m register, the
                    following line appends the contents of this register to the line we have been
                    using, executes the g:ccp_cmd command (by default, <C-X><C-N>) in Normal mode,
                    followed by whatever is in the s variable (either "" or <C-P> or <C-N>) and so
                    on.

                    exe"norm a\<c-r>m".g:ccp_cmd.s."\e^\"ly$u`q"
                    let g:ccp_lst=n|let g:ccp_str=s|let@m=m
                    call histdel(':','^".*')
                    endf

                    "if exists('g:autoload') | finish | endif " used by the autoload generator

                    " search backwards
                    cno <c-x><c-p> <c-b>"<cr>:let@l=@:<cr>:call CmdlineCompl(1)<cr>:<c-r>l
                  Your message has been successfully submitted and would be delivered to recipients shortly.