Tabular.vim:如何对齐放置在 Words 开头的 2 个不同分隔符的第一次出现?

编程入门 行业动态 更新时间:2024-10-10 14:22:32
本文介绍了Tabular.vim:如何对齐放置在 Words 开头的 2 个不同分隔符的第一次出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-05-01 10:46:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408640.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:开头   分隔符   Tabular   vim   Words

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!