Saturday, January 29, 2011

Generate CSV list in Vim

Put below mappings in your .vimrc file :

nnoremap \, :%s/$/,/:%g/^/-j
vnoremap \, y:$opmz:'z,$s/$/,/:'z,$g/^/-j


Example :

for example if you have numbers as :
1
2
3
4
5
6
7
8
9
10

inorder to make csv list out of that, after putting those mappings in .vimrc file just press \,
in command mode will generate :
1 2, 3, 4, 5, 6, 7, 8, 9, 10,

you can select particular lines or block using visual mode and can generate csv only for that values also.

Happy Vimming !!

Regards,
Satya

No comments:

Post a Comment

Followers