问题描述
限时送ChatGPT账号..我已经安装了 Tabular 插件,它对我来说效果很好,只要不涉及复杂的正则表达式......
I have installed the Tabular plugin, which works very well for me, as long as there are no complicated regexes involved…
但我有这个列表:
one @abc @rstuvw &foo
three @defg &bar
four @mn @opq &kludge &hack
twelve @hijkl &baz &quux
我希望这样对齐(首先在@...,然后在 &...):
I wish to align it that way (on @… first, then on &…) :
one @abc @rstuvw &foo
three @defg &bar
four @mn @opq &kludge &hack
twelve @hijkl &baz &quux
这意味着我同时有 3 个问题:
which means I have 3 problems at the same time :
在第一次出现时对齐2 个不同的分隔符(@ 和 &)这不是真正的分隔符,而是单词开头的特殊字符"这远远超出了我对正则表达式和 Tabular.vim 的理解
This is far beyond my understanding of both regexes and Tabular.vim
我应该如何进行?
推荐答案
在第一次出现时对齐
帮助文件解释了这个问题,你可以使用这个命令:
Align on the first occurrence
The help file explains this problem, you can use this command:
:Tabularize /^[^@]*\zs@/l1l0
稍微解释一下:
^
表示行首[^@]*
匹配不是 @
的所有内容.*
表示 0 次或多次,尽可能多\zs
将正则表达式的开头放在这里(从这一点开始的所有内容都匹配)@
上句中的'this point'表示@
符号/l1l0
表示将第一个块向左对齐并添加 1 个空格(l1
)并将第二个块向左对齐并添加 0 个空格(l0
)
^
means the begin of the line
[^@]*
match everything that isn't a @
. The *
means 0 or more times, as much as you can
\zs
put the start of the regex here (everything from this point is matched)
@
the 'this point' in the previous sentence means the @
symbol
/l1l0
means align the 1st block to the left and add 1 space (l1
) and align the 2nd block to the left and add 0 spaces (l0
)
您需要在 2 个命令中执行此操作.为了让您的生活更轻松,您可以命名模式并使用该名称:
You need to do this in 2 commands. To make your life easier you can name the pattern and use that name:
:AddTabularPattern f_at /^[^@]*\zs@/l1l0
:AddTabularPattern f_and /^[^&]*\zs&/l1l0
现在可以运行了
:Tabularize f_at
:Tabularize f_and
映射命令
您甚至可以映射这些方法以生成简单的快捷方式.在此处
这篇关于Tabular.vim:如何对齐放置在 Words 开头的 2 个不同分隔符的第一次出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论