I have a bunch of local variable references in a Python script that I want to pull from a dictionary instead. So, I need to essentially change foo
, bar
, and others into env['foo']
, env['bar']
and so on. Do I need to write a regular expression and match each variable name to transform, or is there a more direct approach that I could just repeat with the .
command?
vim Inserting text Insert text into multiple lines at oncePress Ctrl + v to enter into visual block mode. Use ↑ / ↓ / j / k to select multiple lines. Press Shift + i and start typing what you want. After you press Esc , the text will be inserted into all the lines you selected.
In a visual block, you can insert text in each line before the selection with I , and you can append text in each line after the selection with A . If you use $ to convert the visual selection to select to the end of line, then A will append text to the end of each line in the visual block.
Type A to add text to the end of a line. To see how this command works, position the cursor anywhere on a text line and type A . The cursor moves to the end of the line, where you can type your additions. Press Esc when you are finished.
You can use a macro: type these commands in one go (with spacing just to insert comments)
" first move to start of the relevant word (ie via search)
qa " record macro into the a register.
ienv['<esc> " insert relevant piece
ea'] " move to end of word and insert relevant piece
q " stop recording
then, when you're on the next word, just hit @a
to replay the macro (or even @@
to repeat the last replay after that).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With