I've been using vim for a while and consider myself moderately proficient. I've also built custom text objects, primarily using the fantastic vim-textobj-user rather than natively, as well as using many of the text objects others have built in plugins, and of course built-in text objects and motions.
However, I'm still not clear on the real difference between a text object and a motion. (I think this question is of limited practical importance, but I'm interested anyway). If I hit w, I obviously navigate by words (motion), and if I hit yw, I yank to the end of where that motion would have gone (text object?). However, some text objects (e.g. ip, for inside paragraph) do not work as motions by themselves. In fact, most don't, in my experience. The paragraph motion (}) is a totally unrelated keybinding from ip or ap. In the :operator
documentation, vim talks about using motions after operators, but there is no mention there of text objects. Confusingly, there is also a section called :object-motions
, which refers to "Text Object Motions"!
So what's the difference? Are they actually related, or is Vim itself just built so some (but not all) of the inbuilt text objects also work as motions through deliberately-chosen identical key bindings? I clearly cannot always use a text object as a motion (try typing ip in normal mode), but it seems I can always use a motion as a text object (y} works as expected). Are text objects a subset of motions?