gpt4 book ai didi

python - Vim 表格 : how to ignore long comments

转载 作者:太空狗 更新时间:2023-10-30 03:00:37 26 4
gpt4 key购买 nike

我在 Vim 中使用 Tabular 将 Python 中数据文件的定义与一些长注释对齐:

# A long comment here with many words
param_1 = 42
parameter_2 = 0.25

# Another long comment
para_3 = 'abc'
parameter_number_4 = some_var

如果我在选择中使用 Tabularize/=,评论也会被处理,因为有些很长,我得到:

# A long comment here with many words
param_1 = 42
parameter_2 = 0.25

# Another long comment
para_3 = 'abc'
parameter_number_4 = some_var

这不是我想要的。有没有办法在选择中忽略以“#”开头的行?从而得到这样的东西:

# A long comment here with many words
param_1 = 42
parameter_2 = 0.25

# Another long comment
para_3 = 'abc'
parameter_number_4 = some_var

最佳答案

我建议您使用 global 命令而不是视觉选择来告诉 tabularize 要对齐的内容。在你的情况下,像这样:

:%g/^\s*[^#]/Tabularize /=

这会找到文件中不是注释的每一行,并对其运行Tabularize/=。如果您想针对更具体的行,可以将 % 替换为 cmdline-range。您也可以直接传递 cmdline-range 来进行表格化,如下所示:

:2,3Tabularize /=

相关帮助主题:

:help cmdline-ranges
:help :g

关于python - Vim 表格 : how to ignore long comments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28610888/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com