如何在vim中单词的两边重复添加文本? [英] How to repeatedly add text on both sides of a word in vim?

查看:195
本文介绍了如何在vim中单词的两边重复添加文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python脚本中有一堆局部变量引用,而我想从字典中提取。因此,我基本上需要将 foo bar 等更改为 env ['foo '] env ['bar'] 等。我是否需要编写一个正则表达式并匹配每个变量名称以进行转换,或者是否可以使用命令重复一个更直接的方法?

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?

推荐答案

您可以使用宏:一次性键入这些命令(以空格仅用于插入注释)

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

然后,当您输入下一个单词时,只需按 @a 重播宏(甚至 @@ 在此之后重复上一次重播)。

then, when you're on the next word, just hit @a to replay the macro (or even @@ to repeat the last replay after that).

这篇关于如何在vim中单词的两边重复添加文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆