I have this dataset in a csv file
1.33570301776, 3.61194e-06, 7.24503e-06, -9.91572e-06, 1.25098e-05, 0.0102828, 0.010352, 0.0102677, 0.0103789, 0.00161604,
I just wrote tablign for this purpose. Install with
pip3 install tablign --user
Then simply mark the table in vim and do
:'<,'>:!tablign
I have this in my .vimrc.
command! CSV set nowrap | %s/,/,|/g | %!column -n -t -s "|"
This aligns the columns while keeping the comma, which may be needed later for correct reading. For example, with Python Pandas read_csv(..., skipinitialspace=True)
, thanks Pandas guys for this smart option, otherwise in vim %s/,\s\+/,/g
. It may be easier if your column
has the option --output-separator I guess, my doesn't and I'm not sure why (my man page for column says 2004, on ubuntu 18.04, not sure ubuntu will get a new version). Anyway, this works for me, and comment if you have any suggestions.
You could use the csv.vim plugin.
:%ArrangeColumn
However, this will not do exactly what you have asked: it will right adjust the contents of cells, whereas you have your values aligned by the decimal point or by the first digit.
The plugin has many other useful commands for working with CSV files.
I wrote python script that allows users to basicly columize any type of text also outside of vim. Not sure if this will work for windows or mac users.
columnice.py gist
Usage when in vim.
:'<,'>!columnice =
This will use the equals sign as the delimeter. The delimeter is not thrown away though.
Also, Tabularize is quite good http://vimcasts.org/episodes/aligning-text-with-tabular-vim/
We now also have the fabulous EasyAlign plugin, written by junegunn.
Demonstration GIF from its README: