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 via email to