外部GNU BinUtils按列“排序”在VIM中不起作用(External GNU BinUtils “Sort” by column won't work in VIM)

编程入门 行业动态 更新时间:2024-10-27 23:31:43
外部GNU BinUtils按列“排序”在VIM中不起作用(External GNU BinUtils “Sort” by column won't work in VIM)

我在VIM中有一个简单的数据表,由两组可变长度字符串组成。 例如:

test bob check mike review tom test2 tom presentation mike

通过使用CTRL + V选择VIM中的所有五行,在视觉上选择所有五行,然后点击SHIFT + 组合键进入命令模式,然后我可以通过column来管道它“更漂亮”发出命令'<,'>!column -t ,它看起来像:

test bob check mike review tom test2 tom presentation mike

现在,我想最后按第二列排序。 我尝试进行视觉块选择,并使用'<,'>!sort -n -k2 ,但我得到:

check mike presentation mike review tom test bob test2 tom

所以,它排序,但只有第一列。 认为这可能使用文字列号而不是假设SPACE作为分隔符,并且考虑连续分隔符,我再次尝试使用'<,'>!sort -n -k15 ,但我仍然得到相同的不良行为。

我怎样才能通过第二列对文本列号(即:15)或可视列号(即:2)进行排序?

谢谢。

I have a simple table of data in VIM consisting of two sets of variable-length strings. For example:

test bob check mike review tom test2 tom presentation mike

I have been able to make it "prettier" by piping it through column, by selecting all five lines in VIM using CTRL+V, selecting all five entire lines visually, then hitting the SHIFT+: key combination to enter command mode, and then issue the command '<,'>!column -t, which makes it look like:

test bob check mike review tom test2 tom presentation mike

Now, I would like to finally sort by the second column. I tried doing a visual block selection, and using '<,'>!sort -n -k2, but I just get:

check mike presentation mike review tom test bob test2 tom

So, it sorts, but only by the first column. Thinking this uses perhaps the literal column number rather than assuming SPACE as a delimiter, and accounting for consecutive delimiters, I tried again with '<,'>!sort -n -k15, but I still get the same undesired behavior.

How can I get this to sort by the second column, either by the literal column number (ie: 15), or by the visual column number (ie: 2)?

Thank you.

最满意答案

这个命令:

%sor r /\S\+$/

产生:

test bob check mike presentation mike review tom test2 tom

检查:h :sort详情

您的逐块视觉选择无助于排序(内置或外置)。 因为它传递了一个基于行的range ,即使选择以块/列方式查看。 :h range细节。 如果要使用外部排序,则应该与shell中完全相同。

this command:

%sor r /\S\+$/

generates:

test bob check mike presentation mike review tom test2 tom

check :h :sort for details

your block-wise visual selection won't help sorting (either built-in or external). because it passed a range, which is line based, even though the selection looks in block/column wise. :h range for detail. If you want to use external sort, you should do exactly same as in shell.

更多推荐

本文发布于:2023-07-30 01:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321440.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   VIM   BinUtils   GNU   work

发布评论

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

>www.elefans.com

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