在 vi 中自定义单词分隔符
vi 将破折号 -
和空格
视为命令(例如 dw
和 cw
)的单词分隔符。
有没有办法添加下划线_
?
我经常想更改包含下划线的变量名的一部分,例如将 src_branch
更改为 dest_branch
。 我最终计算字符并使用 s
(如 3sdest
),但使用 cw
(如 cwdest< /代码>)。
vi treats dash -
and space
as word separators for commands such as dw
and cw
.
Is there a way to add underscore _
as well?
I quite often want to change part of a variable name containing underscores, such as changing src_branch
to dest_branch
. I end up counting characters and using s
(like 3sdest
), but it would be much easier to use cw
(like cwdest
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
什么是或不是关键字的成员字符取决于语言。 有关 iskeyword 的帮助,请使用
:help iskeyword
。What is, and is not a member character to keywords depends on the language. For help on iskeyword use
:help iskeyword
.如果您使用的是 vim,则可以通过设置
iskeyword
选项 (:he iskeyword
) 来更改它。 如果这不是一个选项,您始终可以使用ct_
而不是计数。In case you're using vim, you can change that by setting the
iskeyword
option (:he iskeyword
). If that is not an option, you can always usect_
instead of counting.在这种情况下,另一个不错的选择是使用 camelcasemotion 插件。
它添加了新的动作
,b
、,e
和,w
,其工作方式与b
、类似>e
和w
,只不过它们识别 CamelCase 和 Snake_case 单词。 有了它,您就可以使用它,如果您的光标位于“src_branch”的第一个字符上,这会将“src_branch”替换为“dest_branch”。
One other good option in such cases is to use camelcasemotion plugin.
It adds new motions
,b
,,e
, and,w
, which work analogously withb
,e
, andw
, except that they recognize CamelCase and snake_case words. With it you can useand this will replace "src_branch" with "dest_branch" if your cursor was on first character of "src_branch".
您可以输入 cf_dest_ 并保存计数部分。
编辑:或按照建议:
ct_
更改文本直到下划线字符之前。 (我更多地使用f
动作,所以它对我来说更自然)或者你可以重新定义
'iskeyword'
(:help iskeyword
了解详情)。You could type
cf_dest_
and save the counting part.Edit: or as suggested:
ct_
changes text until right before the underline character. (I'm using thef
motion more, so it came more naturally to me)Or you could redefine
'iskeyword'
(:help iskeyword
for details).我只是自己看一下并将其添加到我的 .vimrc 中:
我的 .vimrc 有 ^| 问题 和 ^",这是我设置的默认 iskeyword 的一部分,所以我更改为它们的 ascii 值并且工作正常。我的主要修改是在默认设置的末尾添加“^_”以防止 vim 看到下划线作为单词的一部分。
I was just looking at this myself and added this to my .vimrc:
My .vimrc had issues with ^| and ^", which was part of the default iskeyword for my setup, so I changed to their ascii values and it works fine. My main modification was to add "^_" to the end of the default setting to keep vim from seeing underscore as being part of a word.
要删除到下一个下划线,请输入“df_”
要更改为下一个下划线,请输入“cf_”
注意:不要包含双引号。
To delete to the next underscore enter "df_"
To change to the next underscore enter "cf_"
NOTE: don't include the double quotes.