开发者

Replace colon with tab to make columns

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. In vim I tried with

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

But it does not give the desired output. The different columns are not aligned.

When deleting the colon by开发者_JAVA百科 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?


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

:%!column -s':' -t 

followed by

:%retab!


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.


With Tabular.vim it's quite easy, just type :Tab /:\zs and it does the rest.


When in insert mode a setting of yours makes tab to reach a nth column. This is set with the 'softtabstop' settings if I am right.

For those tasks you could use a plugin like Align.vim or Tabularize.

Another option is to insert a huge number of spaces, and then use Visual Block with < operator as many times as necessary, if you have to do it once. Otherwise prefer reusable methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜