对部分行执行 Vim 替换

发布于 2024-08-04 09:34:46 字数 457 浏览 0 评论 0原文

我们可以通过在可视模式下选择一组行并进入命令模式来执行 vim 替换。它会自动填充选定的范围
:'<,'>;

我们可以执行替代操作 :'<,'>s/TestSubstitute//gc

我想知道 vim 中是否可以在可视模式下选择的部分行上执行替换命令,例如

:`<,``>; [随后是替代品 命令]

通常,我会在vim中复制一组由分隔符“,”分隔的字段名称,并希望计算列数,在可视模式下选择所有字段名称后,可以通过逗号出现的次数来确定列数。

从文件信息中选择 fname、lastmodtime、lastaccesstime;

如果我在可视模式下选择从 fname 到 Lastaccesstime 的文本,并且想知道所选文本中的逗号数量。

预先感谢,
纳迦基兰

we can perform vim substitute on a set of lines by selecting them in visual mode and entering command mode. it auto populates the selected range
:'<,'>

and we can perform substitute like
:'<,'>s/TestSubstitute//gc

I would like to know is it possible in vim to perform substitute command on a partial line selected in visual mode, so something like

:`<,``> [followed by substitute
command]

Generally,i will copy a set of field names separated by delimeter "," in vim and would like to calculate the column count which can be determined by the number of comma occurrences once all the field names are selected in visual mode.

select fname,lastmodtime,lastaccesstime from fileInfo;

If i select the text from fname to lastaccesstime in visual mode and would like to know the number of commas in the selected text.

Thanks in advance,
Naga Kiran

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

情愿 2024-08-11 09:34:46

在模式表达式中使用 \%V 修饰符。它将强制 vim 仅在您当前所在或之前所在的视觉块内进行匹配。使用这样的修饰符:

:s/\%Vpattern/substitution/

在视觉模式下,这将显示为:。

:'<,'>s/\%Vpattern/substitution/

Use \%V modifier in pattern expression. It will force vim to match only within visual block you're currently in or were in before. Use the modifier like this:

:s/\%Vpattern/substitution/

In visual mode this will be shown as:.

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