[英]Editing multiple lines in VIM with variable indent
我需要一次編輯多行。 我知道如何從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 =
所以我這樣做:
ctrl+v
, down
, down
, down
, shift+i
-
,然后esc
。shift+c
, space
, =
。f+'
, .
謝謝
在這種情況下我喜歡做的是:
'<,'>
,然后鍵入norm yi'VpxxA =
。 所以整個命令變成:'<,'>norm yi'VpxxA =
這將抽出每行中第一個單引號對的內部內容,用抽出的文本替換整行,刪除前兩個字符,然后刪除 append =
。
使用兩個簡單的替換(比找出一個復雜的替換更快):
" 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
。
有很多方法可以做到這一點……
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.