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

Re: Delete word under cursor in insert mode

Expand Messages
  • darren chamberlain
    ... Is dw what you re looking for (d-elete the next w-ord)? You might want to tweak your definition of word , or use dW (which deletes everything up to the
    Message 1 of 12 , Aug 31 7:27 AM
    • 0 Attachment
      Igor Lyubimov <Igor.Lyubimov@...> said something to this effect on 08/31/2001:
      > Hello everybody,
      >
      > I came to VIM from other text editors under MSWin. But I can't find
      > the solution for using Ctrl-Del for deleting word after the cursor.
      > I've mapped the keys this way:
      > imap <C-BS> <C-W> " It works perfectly!
      > imap <C-Del> <Esc><Right>ce " It doesn't work correctly at
      > " the begin of the line
      > " the first letter stil present.
      > " :-(
      > How can I solve this problem?
      > Actually, I need to delete only the rest part of the word after the
      > cursor position.

      Is dw what you're looking for (d-elete the next w-ord)? You
      might want to tweak your definition of "word", or use dW (which
      deletes everything up to the next whitespace character).

      (darren)

      --
      What if nothing exists and we're all in somebody's dream? Or what's
      worse, what if only that fat guy in the third row exists?
      -- Woody Allen
    • Igor Lyubimov
      Hello everybody, I came to VIM from other text editors under MSWin. But I can t find the solution for using Ctrl-Del for deleting word after the cursor. I ve
      Message 2 of 12 , Aug 31 7:27 AM
      • 0 Attachment
        Hello everybody,

        I came to VIM from other text editors under MSWin. But I can't find
        the solution for using Ctrl-Del for deleting word after the cursor.
        I've mapped the keys this way:
        imap <C-BS> <C-W> " It works perfectly!
        imap <C-Del> <Esc><Right>ce " It doesn't work correctly at
        " the begin of the line
        " the first letter stil present.
        " :-(
        How can I solve this problem?
        Actually, I need to delete only the rest part of the word after the
        cursor position.

        --
        Best regards,
        Igor mailto:Igor.Lyubimov@...
      • Adam 'Vonlia' Seyfarth
        ... Hmm, is the problem that moves left all the time that it isn t at the beginning of a line? If so, I ve thought about this also, and here s what I
        Message 3 of 12 , Aug 31 7:39 AM
        • 0 Attachment
          On Fri, 31 Aug 2001, Igor Lyubimov wrote:

          > Hello everybody,
          >
          > I came to VIM from other text editors under MSWin. But I can't find
          > the solution for using Ctrl-Del for deleting word after the cursor.
          > I've mapped the keys this way:
          > imap <C-BS> <C-W> " It works perfectly!
          > imap <C-Del> <Esc><Right>ce " It doesn't work correctly at
          > " the begin of the line
          > " the first letter stil present.
          > " :-(
          > How can I solve this problem?
          > Actually, I need to delete only the rest part of the word after the
          > cursor position.

          Hmm, is the problem that <Esc> moves left all the time that it isn't at
          the beginning of a line? If so, I've thought about this also, and
          here's what I came up with:

          imap <C-Del> t<Esc>xce
          "=====================
          " t arbitrary, insures not at beginning of line
          " <Esc> out of insert mode, cursor on 't'
          " x delete the 't', cursor is where it was in insert
          " mode before
          " ce change to end of word

          It looks like a hack, if anyone can think of a better solution, please
          let me know!


          HTH


          --
          Two is not equal to three, not even for very large values of two.
          -- Gregory Propf

          /|| Adam Seyfarth <http://members.home.net/adam.seyfarth/> ||\
          /«|| <mailto:cloud@...> Geekcode, version 3.12 ||»\
          \«|| GU d-- s+: a---- C++ UL+>++ P-- L++ E-- W++ N++ o K- w-- ||»/
          \|| O M- V- PE- Y PGP- t 5 X R tv+ b+ DI+ D+ G e-- h! !r !y+ ||/
        • Bohdan Vlasyuk
          ... imap cw [or dw, de, whichever fits you best] works nice for me. -- The alarm clock that is louder than God s own belongs to the roommate with
          Message 4 of 12 , Aug 31 7:44 AM
          • 0 Attachment
            On Fri, Aug 31, 2001 at 09:39:48AM -0500, Adam 'Vonlia' Seyfarth wrote:

            > imap <C-Del> t<Esc>xce
            > It looks like a hack, if anyone can think of a better solution, please
            > let me know!
            imap <C-Del> <C-O>cw
            [or dw, de, whichever fits you best]

            works nice for me.

            --
            The alarm clock that is louder than God's own belongs to the roommate with
            the earliest class.
          • Dan Sharp
            ... From insert mode, use instead of . It leaves the cursor on the current letter instead of moving it left one character (on 6.0at, at
            Message 5 of 12 , Aug 31 7:47 AM
            • 0 Attachment
              At 09:39 AM 8/31/2001 -0500, Adam 'Vonlia' Seyfarth wrote:

              >On Fri, 31 Aug 2001, Igor Lyubimov wrote:
              >
              > > Hello everybody,
              > >
              > > I came to VIM from other text editors under MSWin. But I can't find
              > > the solution for using Ctrl-Del for deleting word after the cursor.
              > > I've mapped the keys this way:
              > > imap <C-BS> <C-W> " It works perfectly!
              > > imap <C-Del> <Esc><Right>ce " It doesn't work correctly at
              > > " the begin of the line
              > > " the first letter stil present.
              > > " :-(
              > > How can I solve this problem?
              > > Actually, I need to delete only the rest part of the word after the
              > > cursor position.
              >
              >Hmm, is the problem that <Esc> moves left all the time that it isn't at
              >the beginning of a line? If so, I've thought about this also, and
              >here's what I came up with:

              From insert mode, use <C-O> instead of <ESC><Right>. It leaves the cursor
              on the current letter instead of moving it left one character (on 6.0at, at
              least).

              Dan Sharp
            • 'Bohdan Vlasyuk'
              ... It never happened for me on linux/60at ... nope. it behave QUTE differently. see :h cw for the difference e.g: aaa|bb cc [| represents cursor] dw
              Message 6 of 12 , Aug 31 8:00 AM
              • 0 Attachment
                On Fri, Aug 31, 2001 at 08:01:05AM -0700, HALIM,SALMAN (HP-NewJersey,ex2) wrote:

                > on vim 6.0at (windows 2000), the 'c' after a <c-o> appears to create
                > a double insert mode -- after the change, hitting escape STILL
                > leaves me in insert mode.
                It never happened for me on linux/60at

                > for this reason (i doubt that this is a bug -- anyone?)
                > i would suggest using 'd' instead of 'c' -- it seems to do the trick
                > just as well.
                nope. it behave QUTE differently.
                see :h cw for the difference

                e.g:
                aaa|bb cc
                [| represents cursor]
                <C-o>dw would do
                aaa|cc
                whereas <C-o>cw:
                aaa| cc

                if you'll use <C-o>de, it would not delete blanks before word, yet
                would delete the word too, which is not nice (imho)

                just set up these mappings and play a little

                --
                A king's castle is his home.
              • Adam 'Vonlia' Seyfarth
                ... Yes, is good for this particular example, but sometimes you would need to have the cursor on the char you were on in insert mode in normal mode. Eg,
                Message 7 of 12 , Aug 31 10:42 AM
                • 0 Attachment
                  On Fri, 31 Aug 2001, Dan Sharp wrote:

                  > >Hmm, is the problem that <Esc> moves left all the time that it isn't at
                  > >the beginning of a line? If so, I've thought about this also, and
                  > >here's what I came up with:
                  >
                  > From insert mode, use <C-O> instead of <ESC><Right>. It leaves the cursor
                  > on the current letter instead of moving it left one character (on 6.0at, at
                  > least).

                  Yes, <C-O> is good for this particular example, but sometimes you would
                  need to have the cursor on the char you were on in insert mode in normal
                  mode. Eg, for a replacement of <BS> with no boundries:

                  imap <BS> <C-O>hxi

                  ---that won't work, it needs the <Esc>tx treatment. Thus, I've gotten
                  into the habbit of doing that for imaps that call normal mode commands.


                  Adam say: «ctrl-o gets heavy use interactively, though»


                  --
                  ``This is the most beautiful coin I have ever seen. It has
                  amazing detail, and that 3D, holographic image makes it look
                  like it's from some futuristic, sci-fi movie.''
                  -- An actual, American, TV commercial

                  /|| Adam Seyfarth <http://members.home.net/adam.seyfarth/> ||\
                  /«|| <mailto:cloud@...> Geekcode, version 3.12 ||»\
                  \«|| GU d-- s+: a---- C++ UL+>++ P-- L++ E-- W++ N++ o K- w-- ||»/
                  \|| O M- V- PE- Y PGP- t 5 X R tv+ b+ DI+ D+ G e-- h! !r !y+ ||/
                • Bohdan Vlasyuk
                  ... Umm?? :set bs=2 ... I don t undertand how tx is supposed to work... -- Detroit is Cleveland without the glitter.
                  Message 8 of 12 , Aug 31 10:47 AM
                  • 0 Attachment
                    On Fri, Aug 31, 2001 at 12:42:21PM -0500, Adam 'Vonlia' Seyfarth wrote:

                    > Eg, for a replacement of <BS> with no boundries:
                    > imap <BS> <C-O>hxi
                    Umm?? :set bs=2

                    > ---that won't work, it needs the <Esc>tx treatment.
                    I don't undertand how <Esc>tx is supposed to work...

                    --
                    Detroit is Cleveland without the glitter.
                  • Adam 'Vonlia' Seyfarth
                    ... Yes, I know, I was short on examples and that was the only one I could think of... ... Sorry, typo, I meant t x . That puts the cursor in normal mode
                    Message 9 of 12 , Aug 31 10:53 AM
                    • 0 Attachment
                      On Fri, 31 Aug 2001, Bohdan Vlasyuk wrote:

                      > On Fri, Aug 31, 2001 at 12:42:21PM -0500, Adam 'Vonlia' Seyfarth wrote:
                      >
                      > > Eg, for a replacement of <BS> with no boundries:
                      > > imap <BS> <C-O>hxi
                      > Umm?? :set bs=2

                      Yes, I know, I was short on examples and that was the only one I could
                      think of...

                      > > ---that won't work, it needs the <Esc>tx treatment.
                      > I don't undertand how <Esc>tx is supposed to work...

                      Sorry, typo, I meant "t<Esc>x". That puts the cursor in normal mode on
                      the char the cursor was on in insert mode.


                      --
                      singing person: ``There's nothing quite as wonderful as money,
                      There's nothing quite as beautiful as cash...''
                      choire: ``money money money money money money money...''
                      -- Monty Python::music

                      /|| Adam Seyfarth <http://members.home.net/adam.seyfarth/> ||\
                      /«|| <mailto:cloud@...> Geekcode, version 3.12 ||»\
                      \«|| GU d-- s+: a---- C++ UL+>++ P-- L++ E-- W++ N++ o K- w-- ||»/
                      \|| O M- V- PE- Y PGP- t 5 X R tv+ b+ DI+ D+ G e-- h! !r !y+ ||/
                    • Bohdan Vlasyuk
                      ... same does .. I still don t understand what you want to win with , considering that it behaves differently at the beginnig of the line. -- Each
                      Message 10 of 12 , Aug 31 10:56 AM
                      • 0 Attachment
                        On Fri, Aug 31, 2001 at 12:53:33PM -0500, Adam 'Vonlia' Seyfarth wrote:

                        >>> ---that won't work, it needs the <Esc>tx treatment.
                        >> I don't undertand how <Esc>tx is supposed to work...
                        > Sorry, typo, I meant "t<Esc>x". That puts the cursor in normal mode
                        > on the char the cursor was on in insert mode.
                        same does <C-O>..
                        I still don't understand what you want to win with <esc>, considering
                        that it behaves differently at the beginnig of the line.

                        --
                        Each honest calling, each walk of life, has its own elite, its own aristocracy
                        based on excellence of performance. -- James Bryant Conant
                      • Adam 'Vonlia' Seyfarth
                        ... Look before you leap :-) Try this: imap hx it will move the cursor left, then insert an x. That isn t what I want, I want to delete the char to
                        Message 11 of 12 , Aug 31 2:55 PM
                        • 0 Attachment
                          On Fri, 31 Aug 2001, Bohdan Vlasyuk wrote:

                          > On Fri, Aug 31, 2001 at 12:53:33PM -0500, Adam 'Vonlia' Seyfarth wrote:
                          >
                          > >>> ---that won't work, it needs the <Esc>tx treatment.
                          > >> I don't undertand how <Esc>tx is supposed to work...
                          > > Sorry, typo, I meant "t<Esc>x". That puts the cursor in normal mode
                          > > on the char the cursor was on in insert mode.
                          > same does <C-O>..

                          Look before you leap :-) Try this:

                          imap <BS> <C-O>hx

                          it will move the cursor left, then insert an x. That isn't what I want,
                          I want to delete the char to the left. Which is two normal mode
                          commands. So, if I were to do it in normal mode, I would have to stay
                          in normal mode after the first command.

                          > I still don't understand what you want to win with <esc>, considering
                          > that it behaves differently at the beginnig of the line.
                          (it isn't a battle, just a discussion :-)

                          <Esc>, by itself, will behave differently at beginning of line. That is
                          the problem I was fixing in the first place. That is why I would do
                          this:

                          imap <BS> t<Esc>xhx
                          " ===================
                          " t temperary. so we are NOT at beginning of line
                          " <Esc> to normal mode, on the 't'
                          " x delete the 't' we just put
                          " hx delete char to left

                          ---it behaves same for any position of line, except for this example is
                          bad, it needs an 'h' which does behave differently on beginning of line,
                          but the "t<Esc>x" should work.


                          --
                          Hunter with gun: ``I love animals. That's why I love to kill
                          them.''
                          -- Monty Python::sketch

                          /|| Adam Seyfarth <http://members.home.net/adam.seyfarth/> ||\
                          /«|| <mailto:cloud@...> Geekcode, version 3.12 ||»\
                          \«|| GU d-- s+: a---- C++ UL+>++ P-- L++ E-- W++ N++ o K- w-- ||»/
                          \|| O M- V- PE- Y PGP- t 5 X R tv+ b+ DI+ D+ G e-- h! !r !y+ ||/
                        • Bohdan Vlasyuk
                          ... You may consider using :normal hx ... that is the problem that solves. If you still beliebe method is better, well, i have nothing
                          Message 12 of 12 , Sep 3, 2001
                          • 0 Attachment
                            On Fri, Aug 31, 2001 at 04:55:53PM -0500, Adam 'Vonlia' Seyfarth wrote:

                            > > same does <C-O>..
                            > Look before you leap :-) Try this:
                            > imap <BS> <C-O>hx
                            You may consider using <C-o>:normal hx<cr>


                            >> I still don't understand what you want to win with <esc>,
                            >> considering that it behaves differently at the beginnig of the
                            >> line.
                            > <Esc>, by itself, will behave differently at beginning of line.
                            > That is the problem I was fixing in the first place.
                            that is the problem that <C-o> solves. If you still beliebe <esc>
                            method is better, well, i have nothing else to say.


                            --
                            Life's too short to dance with ugly women.
                          Your message has been successfully submitted and would be delivered to recipients shortly.