Pasting inside delimiters without using visual selection

前端 未结 5 918
轻奢々
轻奢々 2020-12-21 18:09

In Vim, let\'s say I want to replace the contents of one String with the content of another.

Original input

var1 = \"January\"
var2          


        
5条回答
  •  独厮守ぢ
    2020-12-21 18:51

    There is a plugin that addresses this problem precisely. It was presumably born out of the same feeling you're feeling, namely that Visual mode often feels less than ideal to advanced Vim users.

    operator-replace – Operator to replace text with register content

    With operator-replace installed the replacing goes like this.

    1. Yank the word inside the quotes.

      yi"
      
    2. Move to the target line

      j
      
    3. Replace inside the quotes with the yanked text. (I've set up gr as the replace operator: :map gr (operator-replace). Pick your own mapping.)

      gri"
      

    Check it out! This is part of the truly excellent textobj/operator frameworks. I couldn't work without them.

提交回复
热议问题