突出显示 VIM 中的特定列

发布于 2024-11-24 16:12:39 字数 3167 浏览 8 评论 0原文

我经常处理包含固定位置数据的文件。如果您愿意的话,可以使用非分隔的“CSV”文件...通常,我想突出显示特定的列。

我尝试过

:match ErrorMsg /\%>30v.\+\%<40v/

,但是运行速度非常慢并且只匹配第一行。我想该文件可能太大了。请注意,这些文件非常宽(大约 40000 个字符),但不是很长(大约 2000 行)。这些数据来自我无法控制的旧工具。

示例文件:

                                                 63082                                                   
                                                 01089                                                   
                                                 75518                              735301               

                                                 53473                              017146               
                                                                                     37217               
                                                                                        07               
                                                                                    940376               
                                                   762                                2842               

                                                                                     88331               
                                                 40680                                8928               
            645718                                                                                       
                                                  0131                                                   
                                                                                     03522               

             47210                                                                   27431               

             93837                                                                                       
                                                                                   8825072    49479415   

                                                 52084                                8940               
                                               0591705                              205635               
                                                                                    525429               
                                                 65339                                 300               


                                                  0397                                                   
                                                                                      1983               
                                                     0                                                   
                                                                                   2605768               
            121991                                                                     648               
                                                  3892                                                   

                                                  1260                                                   

有什么想法吗?

I work a lot with files which contain data on fixed positions. Non-delimited "CSV" files if you will... Often, I'd like to highlight a specific column.

I tried

:match ErrorMsg /\%>30v.\+\%<40v/

but this runs extremely slow and only matches the first line. I suppose the file may be too large for this. Mind you, the files are very wide (around 40000 characters) but not very long (around 2000 lines). The data originates from old tools over which I have no control.

Example file:

                                                 63082                                                   
                                                 01089                                                   
                                                 75518                              735301               

                                                 53473                              017146               
                                                                                     37217               
                                                                                        07               
                                                                                    940376               
                                                   762                                2842               

                                                                                     88331               
                                                 40680                                8928               
            645718                                                                                       
                                                  0131                                                   
                                                                                     03522               

             47210                                                                   27431               

             93837                                                                                       
                                                                                   8825072    49479415   

                                                 52084                                8940               
                                               0591705                              205635               
                                                                                    525429               
                                                 65339                                 300               


                                                  0397                                                   
                                                                                      1983               
                                                     0                                                   
                                                                                   2605768               
            121991                                                                     648               
                                                  3892                                                   

                                                  1260                                                   

Any ideas?

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

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

发布评论

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

评论(2

第七度阳光i 2024-12-01 16:12:39

你使用的是 Vim 7.3 吗?

显然他们最近刚刚添加了一个 colorcolumn 选项。

尝试:

:set colorcolumn=31,32,33,34,35,36,37,38,39

请注意 :help 'colorcolumn' 表示“将使屏幕重绘速度变慢”。不过,我通过使用 1234567890 的纯块以及您指定的精确重复计数,在一定程度上复制了您的场景。

您提到的命令非常慢。 colorcolumn 不是。

但是运行速度非常慢并且只匹配第一行

“第一行”是指启用自动换行时显示的第一行吗?不幸的是 colorcolumn 将表现出相同的行为......

Are you using Vim 7.3?

Apparently they just recently added a colorcolumn option.

Try:

:set colorcolumn=31,32,33,34,35,36,37,38,39

Note that :help 'colorcolumn' says "Will make screen redrawing slower". I somewhat replicated your scenario, though, by using pure blocks of 1234567890 with the exact repetition count you specified.

The command you mentioned is very slow. colorcolumn isn't.

but this runs extremely slow and only matches the first line

By "first line" do you mean the first displayed line, when word wrapping is enabled? Unfortunately colorcolumn will exhibit the same behavior...

亢潮 2024-12-01 16:12:39

这偏离了最初的主题,但谷歌将人们带到了这里。当尝试修复严重缩进的 YAML 或任何其他 swiftwidth=2 文件时,我真的很难直观地识别有效列中的内容和不包含的内容。 @ib接受的答案引导我找到这颗宝石。

<代码>
:let &l:colorcolumn = join(范围(3,15,2),',')

它基本上表示将 colorcolumn 设置为从 3 到 15 的逗号分隔字符串值,按 2 计数。(换句话说::set colorcolumn=3,5,7,9, 11,13,15) 结果如下所示:

在此处输入图像描述

您可以执行一个简单的 :set colorcolumn 来查看结果值。

要摆脱它,请执行 :set colorcolumn=

This is off the original topic, but Google leads people here. When trying to fix a horribly indented YAML or any other swiftwidth=2 file, I really struggle to visually recognize what is and isn't in a valid column. A comment by @ib to the accepted answer lead me to this gem.


:let &l:colorcolumn = join(range(3,15,2),',')

It basically says set colorcolumn to the comma delimited string value of 3 through 15 counted by 2. (In other words: :set colorcolumn=3,5,7,9,11,13,15) The result looks like this:

enter image description here

You can do a simple :set colorcolumn to see what value results.

To get rid of it do :set colorcolumn=

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