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

Re: Motion for Cammel Notation

Expand Messages
  • Tim Chase
    ... [cut] ... I think the OP wants an (in vim nomenclature) operator pending mode mapping , so that it can be used *with* the c command, rather than
    Message 1 of 9 , Jul 3, 2006
      >>I would particularly want to use it with the 'c' command.
      [cut]
      > I'm using c quite often. I wouldn't remap it ;)

      I think the OP wants an (in vim nomenclature) "operator pending
      mode mapping", so that it can be used *with* the "c" command,
      rather than *instead* of the "c" command.

      :onoremap > /\u<cr>
      :onoremap <lt> ?\u<cr>

      This pair of mappings will allow one to do

      c>

      or

      c<

      to change to the next/previous start of a "camel-case word"

      The 2nd mapping has problems if you're in the first "word" or on
      the 1st character of the 2nd word (e.g. "abcdEfgHiJklmno" and
      your cursor is on the "E"), so you can change the mapping to

      :onoremap <lt> ?\u<bslash><bar><bslash><lt><cr>

      which will handle both cases.

      There's a good bit of help on the matter scattered throughout the
      docs. Some suggested places to start reading:

      :help omap
      :help operator-pending
      :help map_backslash
      :help <bar>
      (reading the surrounding section on bslash, lt, cr and when to
      use them too is helpful)

      These mappings do happen to break the convenience of the ">>" and
      "<<" commands, as after the first "<" or ">", vim is now in
      operator-pending mode, so unless there is another uppercase
      letter on the line (before or after the cursor respectively),
      this will give you grief. However, you can map them to other
      keys if you prefer (plus/minus are rarely used, given their
      synonymity with j/k), or you might be able to create additional
      mappings for ">>" and "<<" to explicitly perform their original
      actions:

      :nnoremap <lt><lt> <lt><lt>
      :nnoremap >> >>

      might do the trick (untested).

      HTH,

      -tim
    • Marc Weber
      ... What about map c / u ? This will go to the next upper case character. ? searches backwards See ... Remember that you can use fC to jump the the next
      Message 2 of 9 , Jul 3, 2006
        On Mon, Jul 03, 2006 at 12:20:37PM +0300, Giorgos Gaganis wrote:
        > Hello
        >
        > I was wondering if it is possible to have a motion command that would be
        > aware of the Cammel Notation (eg BufferedInputStreamReader) so that the
        > cursor would stop on the capital letters.
        >
        > I would particularly want to use it with the 'c' command.
        What about map c /\u<cr> ? This will go to the next upper case
        character.
        ? searches backwards
        See
        :h /
        :h ?
        :h pattern

        Remember that you can use fC to jump the the next uppercase C which will
        be faster than pressing c 3 times. See also :h , and :h ; to repeat last
        movement.

        I'm using c quite often. I wouldn't remap it ;)

        Marc
      • Giorgos Gaganis
        ... Thank you very much for your answers. What Tim suggested is doing the job with the following modification ... the above works like cw but also stops on
        Message 3 of 9 , Jul 3, 2006
          Tim Chase wrote:
          >>> I would particularly want to use it with the 'c' command.
          > [cut]
          >> I'm using c quite often. I wouldn't remap it ;)
          >
          > I think the OP wants an (in vim nomenclature) "operator pending mode
          > mapping", so that it can be used *with* the "c" command, rather than
          > *instead* of the "c" command.
          >
          > :onoremap > /\u<cr>
          > :onoremap <lt> ?\u<cr>
          >
          > This pair of mappings will allow one to do
          >
          > c>
          >
          > or
          >
          > c<
          Thank you very much for your answers.
          What Tim suggested is doing the job with the following modification

          :onoremap u /\u\\|\W<cr>

          the above works like 'cw' but also stops on uppercase letters.

          Although it does the job there is a really annoying side-effect. Because
          it uses a search all uppercase and nonword chars are highlighted which
          makes the screen practically unreadable.
          I have found the :nohl command but using it like this:

          :onoremap u /\u\\|\W<cr>:nohl<cr>

          simply enters the text :nohl in insert mode

          is there a way to temporarily turn off search highlighting?


          >
          > to change to the next/previous start of a "camel-case word"
          >
          > The 2nd mapping has problems if you're in the first "word" or on the
          > 1st character of the 2nd word (e.g. "abcdEfgHiJklmno" and your cursor
          > is on the "E"), so you can change the mapping to
          >
          > :onoremap <lt> ?\u<bslash><bar><bslash><lt><cr>
          >
          > which will handle both cases.
          >
          > There's a good bit of help on the matter scattered throughout the
          > docs. Some suggested places to start reading:
          >
          > :help omap
          > :help operator-pending
          > :help map_backslash
          > :help <bar>
          > (reading the surrounding section on bslash, lt, cr and when to use
          > them too is helpful)
          >
          > These mappings do happen to break the convenience of the ">>" and "<<"
          > commands, as after the first "<" or ">", vim is now in
          > operator-pending mode, so unless there is another uppercase letter on
          > the line (before or after the cursor respectively), this will give you
          > grief. However, you can map them to other keys if you prefer
          > (plus/minus are rarely used, given their synonymity with j/k), or you
          > might be able to create additional mappings for ">>" and "<<" to
          > explicitly perform their original actions:
          >
          > :nnoremap <lt><lt> <lt><lt>
          > :nnoremap >> >>
          >
          > might do the trick (untested).
          >
          > HTH,
          >
          > -tim
          >
          >
          >
          >
          >
        • Bertram Scharpf
          Hi, ... See also tip #1016. Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de
          Message 4 of 9 , Jul 3, 2006
            Hi,

            Am Montag, 03. Jul 2006, 12:20:37 +0300 schrieb Giorgos Gaganis:
            > I was wondering if it is possible to have a motion command that would be
            > aware of the Cammel Notation (eg BufferedInputStreamReader) so that the
            > cursor would stop on the capital letters.

            See also tip #1016.

            Bertram


            --
            Bertram Scharpf
            Stuttgart, Deutschland/Germany
            http://www.bertram-scharpf.de
          • Yakov Lerner
            ... Preserving search pattern will resolve the side-effect you mention. The following works for me: function! U() let x=@/ / u | W let @/=x endfun ... I tried
            Message 5 of 9 , Jul 3, 2006
              On 7/3/06, Giorgos Gaganis <G.Gaganis@...> wrote:
              > Tim Chase wrote:
              > >>> I would particularly want to use it with the 'c' command.
              > > [cut]
              > >> I'm using c quite often. I wouldn't remap it ;)
              > >
              > > I think the OP wants an (in vim nomenclature) "operator pending mode
              > > mapping", so that it can be used *with* the "c" command, rather than
              > > *instead* of the "c" command.
              > >
              > > :onoremap > /\u<cr>
              > > :onoremap <lt> ?\u<cr>
              > >
              > > This pair of mappings will allow one to do
              > >
              > > c>
              > >
              > > or
              > >
              > > c<
              > Thank you very much for your answers.
              > What Tim suggested is doing the job with the following modification
              >
              > :onoremap u /\u\\|\W<cr>
              >
              > the above works like 'cw' but also stops on uppercase letters.
              >
              > Although it does the job there is a really annoying side-effect. Because
              > it uses a search all uppercase and nonword chars are highlighted which
              > makes the screen practically unreadable.

              Preserving search pattern will resolve the
              side-effect you mention. The following works for me:

              function! U()
              let x=@/
              /\u\|\W
              let @/=x
              endfun

              :onoremap u :call U()<cr>

              I tried to make this into one-liner but failed. Multiple
              commands on the rhs of omap didn't work for me, so I
              packaged rhs as a function.


              Yakov
            • Jürgen Krämer
              Hi ... a function already takes care of not changing the last used search pattern and the redo command, so function! U() / u | W endfunction ... should be
              Message 6 of 9 , Jul 3, 2006
                Hi

                Yakov Lerner wrote:
                >
                > On 7/3/06, Giorgos Gaganis <G.Gaganis@...> wrote:
                > >
                > > Although it does the job there is a really annoying side-effect. Because
                > > it uses a search all uppercase and nonword chars are highlighted which
                > > makes the screen practically unreadable.
                >
                > Preserving search pattern will resolve the
                > side-effect you mention. The following works for me:
                >
                > function! U()
                > let x=@/
                > /\u\|\W
                > let @/=x
                > endfun
                >
                > :onoremap u :call U()<cr>

                a function already takes care of not changing the last used search
                pattern and the redo command, so

                function! U()
                /\u\|\W
                endfunction

                :onoremap u :call U()<cr>

                should be enough.

                Regards,
                Jürgen

                --
                Jürgen Krämer Softwareentwicklung
                HABEL GmbH & Co. KG mailto:jkr@...
                Hinteres Öschle 2 Tel: +49 / 74 61 / 93 53 - 15
                78604 Rietheim-Weilheim Fax: +49 / 74 61 / 93 53 - 99
              • Michael Naumann
                ... In fact it will only work correctly with normal, as in function! UpperOrWord() normal / u | W^M endfunction ... Note: the ^M is entered by ctrl-v ctrl-m I
                Message 7 of 9 , Jul 4, 2006
                  On Tuesday 04 July 2006 08:58, Jürgen Krämer wrote:
                  > a function already takes care of not changing the last used search
                  > pattern and the redo command, so
                  >
                  > function! U()
                  > /\u\|\W
                  > endfunction
                  >
                  > :onoremap u :call U()<cr>
                  >
                  > should be enough.

                  In fact it will only work correctly with normal, as in>

                  function! UpperOrWord()
                  normal /\u\|\W^M
                  endfunction

                  :onoremap u :call UpperOrWord()<cr>

                  Note: the ^M is entered by ctrl-v ctrl-m

                  I prefer to have a speaking names for functions, hence the change in
                  functionname here.


                  HTH, Michael
                • Yakov Lerner
                  ... Another working solution to using search(): function! CamelCase() call search( u | W ) endfunction ... Yakov
                  Message 8 of 9 , Jul 4, 2006
                    On 7/5/06, Michael Naumann <michael@...> wrote:
                    > On Tuesday 04 July 2006 08:58, Jürgen Krämer wrote:
                    > > a function already takes care of not changing the last used search
                    > > pattern and the redo command, so
                    > >
                    > > function! U()
                    > > /\u\|\W
                    > > endfunction
                    > >
                    > > :onoremap u :call U()<cr>
                    > >
                    > > should be enough.
                    >
                    > In fact it will only work correctly with normal, as in>

                    Another working solution to using search():

                    function! CamelCase()
                    call search('\u\|\W')
                    endfunction
                    :onoremap u :call CamelCase()<cr>

                    >
                    > function! UpperOrWord()
                    > normal /\u\|\W^M
                    > endfunction
                    >
                    > :onoremap u :call UpperOrWord()<cr>
                    >
                    > Note: the ^M is entered by ctrl-v ctrl-m

                    Yakov
                  Your message has been successfully submitted and would be delivered to recipients shortly.