我在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 mikeI 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 mikeNow, 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 tomSo, 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 tomcheck :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.
更多推荐
发布评论