2014-01-09 48 views
4

我使用vim環繞,我試圖取代:在vim環繞周圍替換報價與字符串

'this text needs to be replaced' 

**this text needs to be replaced** 

我已經做了兩個YSS和CST (即):

:cst** 
:yss** 

兩者都只能捕捉到第一個*。

如何用字符串包圍文本?

HTML標籤顯然工作正常,我猜他們檢測'<'的第一個實例,並打開輸入緩衝區,但其他文本看起來並不像它的可能。

+0

您是否嘗試過環球的問題跟蹤器? – romainl

回答

4

您可以自定義VIM中的行爲,例如基於

let g:surround_42 = "**\r**" 

或文件,其中txt是文件類型

autocmd FileType txt let b:surround_42 = "**\r**" 

凡42是用於*一個ASCII值。然後像往常一樣改變包圍的文本對象,使用單個*,它將被替換爲**

+1

另一種寫法:'let g:surround_ {char2nr('*')} =「** \ r **」'。我發現這提高了可維護性。 –

1

sorround幫助文件:

A replacement argument is a single character, and is required by |cs|, |ys|, 
and |vS|. Undefined replacement characters (with the exception of alphabetic 
characters) default to placing themselves at the beginning and end of the 
destination, which can be useful for characters like/and |. 

所以其實你可以在置換隻使用單個字符。無論如何surround可以定製,你可以採用其他答案中提出的解決方案。

但是在這種情況下,爲什麼不使用一些普通的vim替代?

:s/'/**/g 

如果你有兩個surround.vimrepeat.vim然後可以重複另一條線路上這一變化與@:

0

,你可以這樣做:

ysi'* 
. 
ds' 

所以它做什麼:

  1. 用星號括住​​引號內的文字。
  2. 重複上一個命令。
  3. 刪除環繞引號。

注意,如果你沒有repeat.vim,它處理.的插件地圖,這樣做這是行不通的。