Motion for Cammel Notation

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Motion for Cammel Notation

Giorgos Gaganis
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.
 

Thanks
Giorgos
Reply | Threaded
Open this post in threaded view
|

Re: Motion for Cammel Notation

MarcWeber
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
Reply | Threaded
Open this post in threaded view
|

Re: Motion for Cammel Notation

Tim Chase-2
>>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



Reply | Threaded
Open this post in threaded view
|

Re: Motion for Cammel Notation

Giorgos Gaganis
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
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Motion for Cammel Notation

Bertram Scharpf
In reply to this post by Giorgos Gaganis
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
Reply | Threaded
Open this post in threaded view
|

Re: Motion for Cammel Notation

iler.ml
In reply to this post by Giorgos Gaganis
On 7/3/06, Giorgos Gaganis <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: Motion for Cammel Notation

Jürgen Krämer

Hi

Yakov Lerner wrote:

>
> On 7/3/06, Giorgos Gaganis <[hidden email]> 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:[hidden email]
Hinteres Öschle 2                          Tel: +49 / 74 61 / 93 53 - 15
78604 Rietheim-Weilheim                    Fax: +49 / 74 61 / 93 53 - 99
Reply | Threaded
Open this post in threaded view
|

Re: Motion for Cammel Notation

Michael Naumann
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

Reply | Threaded
Open this post in threaded view
|

Re: Motion for Cammel Notation

iler.ml
On 7/5/06, Michael Naumann <[hidden email]> 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