What is the best way to reorder columns in a tab delimited text file in vim?

I already know how to do this with

:%s/\(\S\+\)^I\(\S\+\)/\2^I\1/

but I feel like I'm picking up a lot. Is there a cleaner and faster way to do this?

+3
source share
2 answers

If the columns are lined up, you can use the visual block mode by pressing Ctrl + V, then cut and paste. If the columns are not aligned, first increase the tab width so that it is larger than the contents of the columns in question.

+5
source

The best way to do this in VIM is not to do it with VIM and (re) use existing tools to work. * NIX solution:

:%!awk -F \\t '{print $2 FS $1}'

awk, , , (FS). awk Windows.

P.S. cut, - cut -f 2,1 (-d , TAB ) , : |

+3

Source: https://habr.com/ru/post/1751780/


All Articles