Last Updated: February 25, 2016
·
340
· amiel

Turn a list of attributes into symbols in vim

I pasted in a list of columns from a spec document, so I had something like this (only it was a much larger list of attributes:

module Foo
  Bar = Struct.new(
    Order Number
    Line Item
    Date
    Amount
  )
end

I used the following

:3,6!ruby  -ne'puts $_.gsub(/\b \b/,"_").sub(/(\s+)(.+)/, "\\1:\\2,").downcase'

To turn it into this

module Foo
  Bar = Struct.new(
    :order_number,
    :line_item,
    :date,
    :amount,
  )
end