在 vi 中自定义单词分隔符

发布于 2024-07-08 09:48:46 字数 336 浏览 9 评论 0原文

vi 将破折号 - 和空格   视为命令(例如 dwcw)的单词分隔符。

有没有办法添加下划线_

我经常想更改包含下划线的变量名的一部分,例如将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

枫以 2024-07-15 09:48:46

有没有办法也添加下划线_

:set iskeyword-=_ 

什么是或不是关键字的成员字符取决于语言。 有关 iskeyword 的帮助,请使用 :help iskeyword

Is there a way to add underscore _ as well?

:set iskeyword-=_ 

What is, and is not a member character to keywords depends on the language. For help on iskeyword use :help iskeyword.

深海夜未眠 2024-07-15 09:48:46

如果您使用的是 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 use ct_ instead of counting.

无法言说的痛 2024-07-15 09:48:46

在这种情况下,另一个不错的选择是使用 camelcasemotion 插件。

它添加了新的动作 ,b,e,w,其工作方式与 b类似>ew,只不过它们识别 CamelCase 和 Snake_case 单词。 有了它,您就可以使用它,

c,edest

如果您的光标位于“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 with b, e, and w, except that they recognize CamelCase and snake_case words. With it you can use

c,edest

and this will replace "src_branch" with "dest_branch" if your cursor was on first character of "src_branch".

打小就很酷 2024-07-15 09:48:46

您可以输入 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 the f motion more, so it came more naturally to me)

Or you could redefine 'iskeyword' (:help iskeyword for details).

第七度阳光i 2024-07-15 09:48:46

我只是自己看一下并将其添加到我的 .vimrc 中:

set iskeyword=!-~,^*,^45,^124,^34,192-255,^_

我的 .vimrc 有 ^| 问题 和 ^",这是我设置的默认 iskeyword 的一部分,所以我更改为它们的 ascii 值并且工作正常。我的主要修改是在默认设置的末尾添加“^_”以防止 vim 看到下划线作为单词的一部分。

I was just looking at this myself and added this to my .vimrc:

set iskeyword=!-~,^*,^45,^124,^34,192-255,^_

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.

思慕 2024-07-15 09:48:46

要删除到下一个下划线,请输入“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文