binding to "cp" without breaking "c"

Justin M. Keyes justinkz at
Sat Jun 7 09:45:10 CEST 2014


I'm trying to bind a command to the "unused namespace" that happens to
start with "c". By "unused namespace" I mean things like "cp" or "co"
for which there is no valid text object or motion. In Vim, you can
bind "cow" and it does not affect the behavior of "cdw", "ciw", etc,
because "o" is not defined as a text object. For example, in
unimpaired.vim[1], "cow" toggles word-wrap. I would like to do this in
emacs evil, so I tried:

    (define-key evil-normal-state-map (kbd "c o w") 'toggle-truncate-lines)

It reports "eval-region: Key sequence c p w starts with non-prefix key
c". But I don't want to unbind "c" because then I can't use the
evil-change operator.

I tried defining a custom operator, but after looking at the evil
source code I couldn't figure out how to hook into evil-change to
preserve its behavior while listening for "o" and then routing it
somewhere else.

It seems like I'm missing something, I would think this is a common
task, but I haven't found any posts that address this.

Thanks for evil, it's superb!


Justin M. Keyes

More information about the implementations-list mailing list