在可变缩进的VIM中编辑多行

  • 本文关键字:编辑 VIM 缩进 vim
  • 更新时间 :
  • 英文 :


我需要一次编辑多行。我知道如何从ctrl+v-down ...-shift+i这行开始,但问题是我的变量长度不同,所以我不能用同样的技巧来添加每个变量的末尾。当然,我可以在每一行上做.,但我想知道是否有更快的方法来实现相同的结果?

示例:我需要更改:

parser.add_argument('--name', type=str, help='The name of the experiment')
parser.add_argument('--debug', default=False, action='store_true', help=f'If the run is a debugging run')
parser.add_argument('--gpu_id', type=int, default=0 if torch.cuda.device_count() > 0 else -1, help='The ID of the GPU (if there is any) to run the network on (e.g., --gpu_id 1 will run the network on GPU #1 etc.)')

:

name = 
debug = 
gpu_id = 

所以做这个I:

  1. 到第一行,点击ctrl+v,down,down,down,shift+i
  2. 然后删除所有内容,直到最后一个-,然后esc
  3. 编辑每行的末尾,我可以到第一行的末尾,shift+c,space,=
  4. 然后在每一行重复f+',.

感谢

在这种情况下,我喜欢做的是:

  1. 选择您希望在可视行模式下编辑的所有行(Vjj)
  2. :对所选项执行普通模式命令。这将自动设置范围为'<,'>,然后输入norm yi'VpxxA =

所以整个命令变成了:'<,'>norm yi'VpxxA =

将抽取每行第一个单引号对的内部内容,用抽取的文本替换整行,删除前两个字符,然后追加=

用两个简单的替换(比找出一个复杂的替换更快):

" remove what comes before the variable name
:,+2s/.{-}--
" substitute what comes after it with an equal sign
:'[,s/'.*/ =

参见:help :range,:help :s,:help pattern-multi-items

有很多方法可以做到这一点…

最新更新