Reputation: 470
I've got some code that does manual encoding/decoding, which I need to extend. The encoding looks like:
map["some_key"] = some_struct.member;
map["some_other_key"] = some_other_struct.member;
to decode I need to swap the parts of the text around '=' (ex. have some_struct.member = map["some_key"]). Needless to say it's a lot of lines I have to edit, so I wanted to automate this somehow. I'm using vim, but the best I could come up with was to pad the "] part to "_____] to have '=' align and then do the Ctrl+V, then d, then ... you know. Is there a better way of doing this?
Upvotes: 1
Views: 61
Reputation: 196566
I would do it with a macro, too, recorded or not:
:%norm! di"t;vBpF"P
:%norm! $dBF"vi"p$P
Upvotes: 0
Reputation: 14212
Use a macro:
" start macro, saving in q register
qq
" (edit one line to do what you want)
" end recording
q
" visually select other lines, hit :, vim starts command line with '<,'>
:'<,'>norm @q
My q register to edit your lines:
^"xd/ =
xxx$i = jk"xp
I have jk mapped to esc, you'll probably need something else there.
Upvotes: 1