I find it very strange that I can't find this question anywhere...

I made a mapping nnoremap <leader>C /\u<CR> to go to the next capital letter. I thought it would be useful to edit camelCase stuff, so if I had something like oneTwoThree and I wanted to change it to oneFourThree I could just put cursor on the T and do c<leader>C. However this does not work. Is there an easy way to make this work?

Edit: I accidentally found out that pressing <leader>Cc<leader> does what I want, I don't understand why.

  • Can you tell us what your mapping is? – B Layer Dec 16 '19 at 7:53
  • @BLayer nnoremap <leader>C /\u<CR> – RUBEN GONÇALO MOROUÇO Dec 16 '19 at 8:00
  • @BLayer I wish this to work for any operator. For example if I did d<leader>C it would delete, if I did y<leader>C would yank, etc. – RUBEN GONÇALO MOROUÇO Dec 16 '19 at 8:04
  • Ah, ok. Got it. Then you'll want to look at the omap family of mapping commands as you're in an "operator-pending" state after you hit c. – B Layer Dec 16 '19 at 8:04
  • Here's an example: vi.stackexchange.com/questions/6101/… – B Layer Dec 16 '19 at 8:11

nnoremap adds your mapping to Normal mode only. But after c you are in Operator-pending mode, where <leader>C has no effect.

So it suffices to do just noremap <silent><leader>C /\u<CR> instead.

noremap is a convenient command to register mapping in three modes (normal, visual and operator-pending) at once.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.