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

Mapping for visual mode that starts from insert mode?

Expand Messages
  • WU Yue
    Hi, I know title is unclear, but my English skill is so limited, forgive me please, I will try my best to make my expression more clear. I have set mouse=a, so
    Message 1 of 5 , Oct 1, 2012
    • 0 Attachment
      Hi, I know title is unclear, but my English skill is so limited, forgive
      me please, I will try my best to make my expression more clear.

      I have set mouse=a, so I can drag mouse to start a selection in
      normal/insert mode, I notice that when start selection in normal mode, the
      status line will show: -- VISUAL --, when start selection in insert mode,
      the status line will show: -- (insert) VISUAL --.

      When I have selection in insert mode, I often want to replace/delete the
      seleciton, but I don't have this need for the selection starting from
      normal mode, so my question is, how to make <key>s and <backspace> can
      replace/delete the selection *only* when starts from insert mode.

      I don't know if it's clear now, thank you!

      --
      Regards,
      WU Yue

      State Key laboratory of Natural Products and Functions
      Key Laboratory of Modern Chinese Medicines
      Department of Traditional Chinese Medicine
      China Pharmaceutical University
      No.24, Tongjia Xiang Street, Nanjing 210009, China

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Ben Fritz
      ... The visual mode started from insert mode with the mouse is actually selection mode, which is slightly different. Luckily you can map this selection
      Message 2 of 5 , Oct 2, 2012
      • 0 Attachment
        On Monday, October 1, 2012 9:53:40 PM UTC-5, WU Yue wrote:
        > Hi, I know title is unclear, but my English skill is so limited, forgive
        >
        > me please, I will try my best to make my expression more clear.
        >
        >
        >
        > I have set mouse=a, so I can drag mouse to start a selection in
        >
        > normal/insert mode, I notice that when start selection in normal mode, the
        >
        > status line will show: -- VISUAL --, when start selection in insert mode,
        >
        > the status line will show: -- (insert) VISUAL --.
        >
        >
        >
        > When I have selection in insert mode, I often want to replace/delete the
        >
        > seleciton, but I don't have this need for the selection starting from
        >
        > normal mode, so my question is, how to make <key>s and <backspace> can
        >
        > replace/delete the selection *only* when starts from insert mode.
        >
        >
        >
        > I don't know if it's clear now, thank you!
        >

        The visual mode started from insert mode with the mouse is actually "selection" mode, which is slightly different. Luckily you can map this "selection" mode separately from normal visual mode.

        Visual mode: xmap, xnoremap
        Selection mode: smap, snoremap
        Both: vmap, vnoremap

        :help select-mode-mapping
        :help mapmode-x

        Actually, using vmap and vnoremap is normally a mistake, since in selection mode pressing any key with a printable character will replace the selection with that character and drop into insert mode. I'm actually surprised that <Backspace> doesn't already delete the selection...I may map it to <Del> myself.

        (I learned these things on this very list, by the way).

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • WU Yue
        ... Thank you for detailed explanation, Ben, and sorry for late reply. I have tried with: smap s smap s works well, but
        Message 3 of 5 , Oct 3, 2012
        • 0 Attachment
          On Tue, 02 Oct 2012 23:06:47 +0800, Ben Fritz wrote:

          > On Monday, October 1, 2012 9:53:40 PM UTC-5, WU Yue wrote:
          >> Hi, I know title is unclear, but my English skill is so limited, forgive
          >>
          >> me please, I will try my best to make my expression more clear.
          >>
          >>
          >>
          >> I have set mouse=a, so I can drag mouse to start a selection in
          >>
          >> normal/insert mode, I notice that when start selection in normal mode,
          >> the
          >>
          >> status line will show: -- VISUAL --, when start selection in insert
          >> mode,
          >>
          >> the status line will show: -- (insert) VISUAL --.
          >>
          >>
          >>
          >> When I have selection in insert mode, I often want to replace/delete the
          >>
          >> seleciton, but I don't have this need for the selection starting from
          >>
          >> normal mode, so my question is, how to make <key>s and <backspace> can
          >>
          >> replace/delete the selection *only* when starts from insert mode.
          >>
          >>
          >>
          >> I don't know if it's clear now, thank you!
          >>
          >
          > The visual mode started from insert mode with the mouse is actually
          > "selection" mode, which is slightly different. Luckily you can map this
          > "selection" mode separately from normal visual mode.
          >
          > Visual mode: xmap, xnoremap
          > Selection mode: smap, snoremap
          > Both: vmap, vnoremap
          >
          > :help select-mode-mapping
          > :help mapmode-x
          >
          > Actually, using vmap and vnoremap is normally a mistake, since in
          > selection mode pressing any key with a printable character will replace
          > the selection with that character and drop into insert mode. I'm
          > actually surprised that <Backspace> doesn't already delete the
          > selection...I may map it to <Del> myself.
          >
          > (I learned these things on this very list, by the way).
          >

          Thank you for detailed explanation, Ben, and sorry for late reply.

          I have tried with:

          smap <Del> s
          smap <Backspace> s

          <del> works well, but <Backspace> doesn't work, what do I miss?

          --
          Regards,
          WU Yue

          State Key laboratory of Natural Products and Functions
          Key Laboratory of Modern Chinese Medicines
          Department of Traditional Chinese Medicine
          China Pharmaceutical University
          No.24, Tongjia Xiang Street, Nanjing 210009, China

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • WU Yue
          On Tue, 02 Oct 2012 23:06:47 +0800, Ben Fritz ... After reading the help of selectmode , I realize that -- (insert) VISUAL -- is not
          Message 4 of 5 , Oct 3, 2012
          • 0 Attachment
            On Tue, 02 Oct 2012 23:06:47 +0800, Ben Fritz <fritzophrenic@...>
            wrote:

            > On Monday, October 1, 2012 9:53:40 PM UTC-5, WU Yue wrote:
            >> Hi, I know title is unclear, but my English skill is so limited, forgive
            >>
            >> me please, I will try my best to make my expression more clear.
            >>
            >>
            >>
            >> I have set mouse=a, so I can drag mouse to start a selection in
            >>
            >> normal/insert mode, I notice that when start selection in normal mode,
            >> the
            >>
            >> status line will show: -- VISUAL --, when start selection in insert
            >> mode,
            >>
            >> the status line will show: -- (insert) VISUAL --.
            >>
            >>
            >>
            >> When I have selection in insert mode, I often want to replace/delete the
            >>
            >> seleciton, but I don't have this need for the selection starting from
            >>
            >> normal mode, so my question is, how to make <key>s and <backspace> can
            >>
            >> replace/delete the selection *only* when starts from insert mode.
            >>
            >>
            >>
            >> I don't know if it's clear now, thank you!
            >>
            >
            > The visual mode started from insert mode with the mouse is actually
            > "selection" mode, which is slightly different. Luckily you can map this
            > "selection" mode separately from normal visual mode.
            >
            > Visual mode: xmap, xnoremap
            > Selection mode: smap, snoremap
            > Both: vmap, vnoremap
            >
            > :help select-mode-mapping
            > :help mapmode-x
            >
            > Actually, using vmap and vnoremap is normally a mistake, since in
            > selection mode pressing any key with a printable character will replace
            > the selection with that character and drop into insert mode. I'm
            > actually surprised that <Backspace> doesn't already delete the
            > selection...I may map it to <Del> myself.
            >
            > (I learned these things on this very list, by the way).
            >

            After reading the help of "selectmode", I realize that -- (insert) VISUAL
            -- is not the SELECT mode, I have a workaround:

            autocmd InsertEnter * setlocal selectmode=mouse,key
            autocmd InsertLeave * setlocal selectmode=""

            sounds not good but it works :)

            --
            Regards,
            WU Yue

            State Key laboratory of Natural Products and Functions
            Key Laboratory of Modern Chinese Medicines
            Department of Traditional Chinese Medicine
            China Pharmaceutical University
            No.24, Tongjia Xiang Street, Nanjing 210009, China

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Ben Fritz
            ... Oh, I see. I have behave mswin buried somewhere in my config which (among other things) sets selectmode to mouse,key. So for me, selecting with the mouse
            Message 5 of 5 , Oct 4, 2012
            • 0 Attachment
              On Wednesday, October 3, 2012 9:47:23 PM UTC-5, WU Yue wrote:
              >
              > After reading the help of "selectmode", I realize that -- (insert) VISUAL
              > -- is not the SELECT mode, I have a workaround:
              >
              > autocmd InsertEnter * setlocal selectmode=mouse,key
              > autocmd InsertLeave * setlocal selectmode=""
              >
              > sounds not good but it works :)
              >

              Oh, I see. I have "behave mswin" buried somewhere in my config which (among other things) sets selectmode to mouse,key. So for me, selecting with the mouse in insert mode DOES use select mode. I had forgotten this was not the default.

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            Your message has been successfully submitted and would be delivered to recipients shortly.