Replace district quote in vim-surround with string

I am using vim-surround, I am trying to replace:

'this text needs to be replaced'

from

**this text needs to be replaced**

I did both yss and cst (i.e.):

:cst**
:yss**

and both only fix to the first *.

How to surround a text with a string?

HTML tags obviously work fine, I think they detect the first instance of '<' and open the input buffer, but for other text that doesn't seem possible.

+4
source share
3 answers

You can customize the behavior in VIM, for example.

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

or file on which txtis the file type

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

Where 42 is the ASCII value for *. Then change the surrounded text object as usual to a single one *, and it will be replaced by **.

+4
source

From the help file 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  

@:

+1

If you have surround.vim and repeat.vim , you can do this:

ysi'*
.
ds'

So what does he do:

  • surrounds text inside quotation marks with asterisks.
  • repeat the previous command.
  • remove surround quotation marks.

Please note: this does not work if you do not have repeat.vimone that handles .for plugin maps, etc.

0
source

All Articles