Skip to content

Introduce vim surround keymappings

machakann edited this page Apr 3, 2016 · 9 revisions

Introduce vim-surround keymappings

If you want to use with vim-surround keymappings, add the following line to your vimrc.

runtime macros/sandwich/keymap/surround.vim

ys, yss, yS, ds, cs in normal mode and S in visual mode are available. Not in vim-surround, but dss and css are also available, these are similar as ds and cs but determine deleted/replaced texts automatically. See the file directly for detail.

Textobjects

Additionally, vim-sandwich provides several textobjects. They would also be helpful, give it a try!

Textobjects to select a text surrounded by braket or same characters user input.

xmap is <Plug>(textobj-sandwich-query-i)
xmap as <Plug>(textobj-sandwich-query-a)
omap is <Plug>(textobj-sandwich-query-i)
omap as <Plug>(textobj-sandwich-query-a)
  • Examples
   |<---- is( ---->|
{[(a_surrounded_text)]}
  |<----- as( ----->|

  |<----- is[ ----->|
{[(a_surrounded_text)]}
 |<------ as[ ------>|

 |<------ is{ ------>|
{[(a_surrounded_text)]}
|<------- as{ ------->|

     |<  is_ >|
{[(a_surrounded_text)]}
    |<-  as_ ->|

Textobjects to select the nearest surrounded text automatically.

xmap iss <Plug>(textobj-sandwich-auto-i)
xmap ass <Plug>(textobj-sandwich-auto-a)
omap iss <Plug>(textobj-sandwich-auto-i)
omap ass <Plug>(textobj-sandwich-auto-a)
  • Examples
   |<---- iss ---->|
{[(a_surrounded_text)]}
  |<----- ass ----->|

   |<---- iss ---->|
({[a_surrounded_text]})
  |<----- ass ----->|

   |<---- iss ---->|
[({a_surrounded_text})]
  |<----- ass ----->|

Textobjects to select a text surrounded by same characters user input.

xmap im <Plug>(textobj-sandwich-literal-query-i)
xmap am <Plug>(textobj-sandwich-literal-query-a)
omap im <Plug>(textobj-sandwich-literal-query-i)
omap am <Plug>(textobj-sandwich-literal-query-a)
  • Examples
     |<  im_ >|
{[(a_surrounded_text)]}
    |<-  am_ ->|
Clone this wiki locally