Skip to content

Instantly share code, notes, and snippets.

@romainl
Last active September 23, 2025 22:19
Show Gist options
  • Save romainl/ca742f241457b8609836202fe05ee5c0 to your computer and use it in GitHub Desktop.
Save romainl/ca742f241457b8609836202fe05ee5c0 to your computer and use it in GitHub Desktop.
Poor man's Surround

Poor man's Surround

The following shows how to replicate some of Surround's features if you don't happen to have it installed.

NOTE: We only dealt with the simplest cases, here, and the convoluted nature of some of these commands shows how well designed and useful that plugin is. And let's not talk about all the corner cases it handles.

Install it, it's worth it.

The list

Surround

  • ys<motion><thing>

    Surround current word with parentheses

    With surround:

    ysiw)
    

    Native:

    ciw(<C-r>")<Esc>
    
  • vS<thing>

    Surround current visual selection with square brackets

    With surround:

    S]
    

    Native:

    c[<C-r>"]<Esc>
    

Delete

  • ds', ds", and ds`

    Delete surrounding single quotes

    With surround:

    ds'
    

    Native:

    di'vhP
    
  • ds< with <:> added to :help matchpairs, ds(, ds{, and ds[

    Delete surrounding parentheses

    With surround:

    ds)
    

    Native:

    di(v%P
    
  • dst

    Delete surrounding *ML tag

    With surround:

    dst
    

    Native:

    ditvatP
    

Change

  • cs'<thing>, cs"<thing>, and cs`<thing>

    Change surrounding single quotes to double quotes

    With surround:

    cs'"
    

    Native:

    di'vh"_c"<C-r>""<Esc>
    
  • cs<<thing> with <:> added to :help matchpairs, cs(<thing>, cs{<thing>, and cs[<thing>

    Change surrounding parentheses to braces

    With surround:

    cs)}
    

    Native:

    di("_c%{<C-r>"}<Esc>
    
  • cst<new>

    Change surrounding *ML tag to <new>…</new>

    With surround:

    cst<new<CR>
    

    Native:

    dit"_cat<new><C-r>"</new><Esc>
    

My Vim-related gists.

@nyngwang
Copy link

nyngwang commented Sep 23, 2025

Good writing. Maybe too good so that now I'm more interested in those edge cases that really require a plugin / make the native-gang dumb.

To nitpick, I would say that apparently you must know di(vhP when you wrote di(v%P, and that made me laugh. (I hate typing the % symbol, personally)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment