Reputation: 38644
I have the following text as a simple case:
...
abc xxx 123 456
wer xxx 345 678676
...
what I need to move a block of text xxx to another location:
...
abc 123 xxx 456
wer 345 xxx 678676
...
I think I use visual mode to block a column of text, what are the other commands to move the block to another location?
Upvotes: 45
Views: 72822
Reputation: 11800
Using an external command "awk".
%!awk '{print $1,$3,$2,$4}' test.txt
With pure vim
:%s,\v(\w+) (\w+) (\w+) (\w+),\1 \3 \2 \4,g
Another vim solution using global command
:g/./normal wdwwP
Upvotes: 0
Reputation: 6891
One of the few useful command I learned at the beginning of learning VIM is :1,3 mo 5 This means move text line 1 through 3 to line 5.
Upvotes: 16
Reputation: 13238
You should use blockwise visual mode (Ctrl+v). Then d to delete block, p or P to paste block.
Upvotes: 67
Reputation: 4970
Try the link.
Marking text (visual mode)
Visual commands
Cut and Paste
Upvotes: 29
Reputation: 14531
Upvotes: 8