Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace ":" by tab to make columns

Tags:

vim

colon

I have word lists where the word or expression in Spanish is separated by its translation with a colon (":"). I want to make two columns, one for spanish, the other for english. I tried with

:%s/:/^I^I^I/g

But it does not give the desired output. The different columns are not aligned. However, when deleting the colon by hand and inserting the number of tabs with the same amount of tab strokes, it always ends up aligned...

Any idea how to solve this, preferably in vim?

like image 384
Nigu Avatar asked Jan 31 '11 17:01

Nigu


2 Answers

On a Linux/*nix system I use column(1)

:%!column -s':' -t 

followed by

:%retab!
like image 122
Fritz G. Mehner Avatar answered Sep 26 '22 02:09

Fritz G. Mehner


I'd probable do a

:s/:/^I/g

followed by a

:set ts=25

Where 25 is the length of the longest word expected + 2. So, if you expect the longest word of your input (on the left side of the colon) to be 12 characters, I'd choose something around 14 instead.

like image 25
René Nyffenegger Avatar answered Sep 26 '22 02:09

René Nyffenegger