Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Is it possible to VimGolf this?
# To help me importing some CSV
# Using vim (to avoid eval hell)
# can we 'easily' move from something like
# To something like
legacy_venue_id = row[0]
venue_name = row[1]
legacy_region_id = row[2]
venue_address = row[3]
venue_oot = row[4]
venue_db = row[5]
venue_notes = row[6]

How about this?

:s/,/\r/g                  -  replace commas with newlines
<C-o>                      -  jump back to top of block
:let i=0                   -  create a variable `i`
qw                         -  start recording a macro
A{ = row[<C-r>=i<Enter>]}  -  append ` = row[i]` at end of line, using actual value of variable `i`
:let i=i+1                 -  increment variable `i`
q                          -  stop recording the macro
jV}                        -  move down one line, then select to end of block
:normal @w                 -  execute the macro on each selected line

There's a similar example in Practical Vim, tip 70, Evaluate an Iterator to Number Items in a List.

I'm sure that if you posted this example to you'd get some solutions that required fewer keystrokes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment