1

This can be super simple stuff but i am not able to figure it out, i have to mappings in my config file

nnoremap gh ^
nnoremap gl g_

These mappings work just fine and behave as expected when i use them in normal mode, but as soon as i combine them with yank command like ygl to yank the text from cursor to last non-white space character and same way ygh to first non-white space character, it simply does not work.

Am i missing something here ?

1 Answer 1

1

Mappings are of different types. The ones you have mapped are normal mode mappings. And the ones that you claim not to work are operator-pending mode mappings. I suggest you take a look at :h vim-modes.

So, put these in your $MYVIMRC, to get operator-pending mode mappings, to work as you asked:

onoremap gh ^
onoremap gl g_

Notice, the only change is the letter o from n which, unsurprisingly, indicates operator-pending mode while n indicates normal mode.

For better flexbility, I suggest you also map visual mode mappings, like this:

xnoremap gh ^
xnoremap gl g_

These will work when you are in visual-selection mode. Note that, there are two kinds of mappings in visual mode mappings, visual mode and select mode. And I suggest, you nearly always use select mode mappings with letter x in your config. If you want to know more, here is a q/a thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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