Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have few lines that each of them are colon separated values,

abc:def:3

Now I could do the reformat with printf plus IFS variable,

while read line; do IFS=":" printf "%-20s %-16s %5d\n" ${line[0]} ${line[1]} ${line[2]}; done < XX

but is it possible to do it within VIM?

share|improve this question
up vote 4 down vote accepted

Well, in the vi spirit, you'd call a command to do it like:

:%!column -ts:

(if you have column and it supports the -s option).

Otherwise you could do:

:%s/[^:]\+/                                        &/g
:%s/\v^ *([^:]{20}): *([^:]{16}): *([^:]{5})/\1:\2:\3/
share|improve this answer
1  
+1 for column command! – warl0ck Dec 28 '12 at 9:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.