Vim Surround ✨

backgroundMe
Contents

#Installation

  • Packer

     use("tpope/vim-surround")
    
  • Lazy

    "tpope/vim-surround"
    
  • Plug

    Plug "tpope/vim-surround"
    

You can check the document details here: vim-surround

#Create Surround

  • ysiw" surround the word with " … "
    e.g: hello_world"hello_world"

    ysiw"

  • ysiw' surround the word with ' … '
    e.g: hello_world'hello_world'

    ysiw'

  • ysiw<em> surround the word with '<em> … </em>'
    e.g: hello_world<em>hello_world</em>

    ysiwtag

  • ysiw) surround the word with '( … )'
    e.g: hello_world(hello_world)

    ysiw)

  • ysiw] surround the word with '[ … ]'
    e.g: hello_world[hello_world]

    ysiw]

note: this only applies to one word, if you want to surround more than one word, you can check the visual mode below.

#Change Surround

  • cs"' change " … " to ' … '
    e.g: "hello_world"'hello_world'

    cs1

  • cs"<em> change " … " to '<em> … </em>'
    e.g: "hello_world"<em>hello_world</em>

    cs2

  • cst) change '<em> … </em>' to '( … )'
    e.g: '<em>hello_world</em>'(hello_world)

    cs3

  • cs)" change '( … )' to " … "
    e.g: (hello_world)"hello_world"

    cs4

  • cs)] change '( … )' to '[ … ]'
    e.g: '(hello_world)''[hello_world]'

    cs5

#Delete Surround

  • ds" delete sorround " … "
    e.g: "hello_world"hello_world

    cs1

  • dst delete sorround (html tag) '<em> … </em>'
    e.g: '<em>hello_world</em>'hello_world

    cs2

  • ds) delete sorround '( … )'
    e.g: '(hello_world)'hello_world

    cs3

  • ds)[ delete '[ … ]'
    e.g: '[hello_world]'hello_world

    cs4

#Visual Mode

note: you can use any v motion you want, i use v(n)e

  • S" surround in visual cursor selection with " … "
    e.g: hello world"hello world"

    vS1

  • Stem> surround visual cursor selection with '<em> … </em>'
    e.g: hello world'<em>hello world</em>'

    vS2

  • S) surround visual cursor selection with '( … )'
    e.g: hello world(hello world)

    vS3

  • S] surround visual cursor selection with '[ … ]'
    e.g: hello world[hello world]

    vS4

#Function

  • ysWfprint<CR> surround the word with any function print()
    e.g: hello_world → fmt.Printf(hello_world)

    ysWf

  • ysWFprint<CR> surround the anything with function and space arround print()
    e.g: hello_world → fmt.Println( hello_world )

    ysWF