开发者

Join all lines with tabs inserted (vim)

开发者 https://www.devze.com 2022-12-16 03:08 出处:网络
I have a tab delimited file (one line). I can easily enough replace the tabs with new lines so that I can see what fields are in what position

I have a tab delimited file (one line). I can easily enough replace the tabs with new lines so that I can see what fields are in what position

:%s/\t/\r/g

How can I do the inverse, after I've edited the fields? I could record a macro:

Js<tab>Esc

And then repeat it all开发者_StackOverflow社区 the way down - but is there an easier way?


How about this:

:%s/\n/\t/


You can use s to replace newlines with tabs, basically the reverse of the operation you used to replace the tabs with newlines:

:%s/\n/\t/


:1,$-1s/$/\t/|%j

Which means: from the first line to the punultimate 1,$-1 replace the end of the line with a tab s/$/\t/ and then | for all lines % join them j

0

精彩评论

暂无评论...
验证码 换一张
取 消