Emacs邪恶模式:如何创建一个新的文本对象来选择具有任何非空格字符的单词? [英] Emacs Evil mode: how to create a new text object to select words with any non-space characters?
问题描述
我试图在Evil中创建一个新的文本对象。例如,文本对象 iw 只会选择包含连字符的字符串。我想让新的文本对象与任何非空格字符匹配。到目前为止,我得到的是:
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.
我尝试了许多不起作用的事情。对我来说,麻烦的是,当某些事情不起作用时,我不知道是由于正确的正则表达式错误还是由于邪恶的正则表达式限制。例如,使用\s-报告错误,这似乎是邪恶的限制。
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.
推荐答案
正确的正则表达式是\ |。?$。以下代码实现与任何非空格字符匹配的新文本对象。
The correct regexp is " \|.?$". The following code implements a new text object matching any nonspace character.
(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))
这篇关于Emacs邪恶模式:如何创建一个新的文本对象来选择具有任何非空格字符的单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!