簡體   English   中英

使用可變縮進編輯 VIM 中的多行

[英]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 = 

所以我這樣做:

  1. Go 到第一行,按ctrl+vdowndowndownshift+i
  2. 然后刪除所有內容直到最后- ,然后esc
  3. 編輯每一行的末尾我可以 go 到第一行的末尾, shift+cspace=
  4. 然后在另一行重復f+' , .

謝謝

在這種情況下我喜歡做的是:

  1. Select 您希望在視線模式下編輯的所有行 ( V j j )
  2. :對選擇運行正常模式命令。 這將自動將范圍設置為'<,'> ,然后鍵入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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM