I am trying to create a new text object in Evil. For example, the text object iw will only select subsets of strings containing hyphens. I want the new text object to match words with any non-space characters. What I got so far is:
(evil-define-text-object evil-inner-space (count &optional beg end type)
"Select inner space."
:extend-selection nil
(evil-regexp-range count beg end type "[ \n]" " " t))
(define-key evil-inner-text-objects-map " " 'evil-inner-space)
This code fails to correctly match words at the end of a line. It works for words at the beginning of a line thanks to \n.
I tried many things that did not work. The trouble for me is that when something does not work, I don't know if it is due to a wrong regexp or to limitations in evil-regexp-range. For example, using \s- reports an error, which seems to be a limitation in Evil.
Update:
evil-regexp-range
was recently replaced withevil-select-paren
. This works on current evil and has the same usage as the old one:Original Answer:
If you end up defining more than one new text object, the repetition can get annoying, especially if you want to bind both inner and outer objects. If you hit that barrier, try this:
Usage:
(This is more than you wanted, but I'll leave it here in case it helps someone :)