vimideavim

Vim string (double quotes) operator


I found the following vim remaps and they work perfectly for selecting, deleting, choosing...everything in between parenthesis or brackets

onoremap b i[|               
onoremap p i(|

I tried getting the same done for strings but it does not work onoremap s i\"|

I've tried mapping it to different key as well as using omap without success.


Solution

  • First, the "re" in "onoremap" goes with "no" to make "nore", short for "non-recursive", not with "map". Thus, these are not "remaps", but "mappings" (or the uncommon "maps", if you really want).

    Second, I am not sure where you got these from but the | doesn't appear to be an integral part of the mappings. The trailing spaces on the first line make it look like an attempt to handle inline comments as per :help :map-comments, but your sample doesn't include comments so this is puzzling. If you don't have a clear justification for those |s, you should remove them (and fix your trailing whitespace issues):

    onoremap b i[
    onoremap p i(
    

    Third, doing the same for double-quoted strings is easy enough:

    onoremap s i"
    

    Note that the risk is high of overriding useful motions, here. You are already doing that with the first mapping (:help b) and you will probably stumble on other cases as you add more text object "shortcuts". The whole idea doesn't seem very good to me.