vim-sandwich ============ [](https://travis-ci.org/machakann/vim-sandwich) [](https://ci.appveyor.com/project/machakann/vim-sandwich/branch/master) `sandwich.vim` is a set of operator and textobject plugins to add/delete/replace surroundings of a sandwiched textobject, like **(foo)**, **"bar"**. # Quick start ### Add Press `sa{motion/textobject}{addition}`. For example, a key sequence `saiw(` makes **foo** to **(foo)**. ### Delete Press `sdb` or `sd{deletion}`. For example, key sequences `sdb` or `sd(` makes **(foo)** to **foo**. `sdb` searches a set of surrounding automatically. ### Replace Press `srb{addition}` or `sr{deletion}{addition}`. For example, key sequences `srb"` or `sr("` makes **(foo)** to **"foo"**. That's all. Now you already know enough about `sandwich.vim`. If you are using [vim-surround](https://github.com/tpope/vim-surround), you can use a preset keymappings similar as it. See [here](https://github.com/machakann/vim-sandwich/wiki/Introduce-vim-surround-keymappings) `sandwich.vim` has some functional input for *{addition}*/*{deletion}*. Check [here](https://github.com/machakann/vim-sandwich/wiki/Magic-characters)! # Design This plugin provides functions to add/delete/replace surroundings of a sandwiched text. These functions are implemented genuinely by utilizing operator/textobject framework. Thus their action can be repeated by `.` command without any dependency. It consists of two parts, **operator-sandwich** and **textobj-sandwich**. ### operator-sandwich A sandwiched text could be resolved into two parts, {surrounding} and {surrounded text}. * Add surroundings: mapped to the key sequence `sa` * {surrounded text} ---> {surrounding}{surrounded text}{surrounding} * Delete surroundings: mapped to the key sequence `sd` * {surrounding}{surrounded text}{surrounding} ---> {surrounded text} * Replace surroundings: mapped to the key sequence `sr` * {surrounding}{surrounded text}{surrounding} ---> {new surrounding}{surrounded text}{new surrounding} ### textobj-sandwich * Search and select a sandwiched text automatically: mapped to the key sequence `ib` and `ab` * Search and select a sandwiched text with query: mapped to the key sequence `is` and `as` `ib` and `is` selects {surrounded text}. `ab` and `as` selects {surrounded text} including {surrounding}s. ``` |<----ib,is---->| {surrounding}{surrounded text}{surrounding} |<-----------------ab,as----------------->| ``` ### Configuration The point is that it would be nice to be shared the definitions of {surrounding}s pairs in all kinds of operations. User can freely add new settings to extend the functionality. If `g:sandwich#recipes` was defined, this plugin works with the settings inside. As a first step, it would be better to copy the default settings in `g:sandwich#default_recipes`. ```vim let g:sandwich#recipes = deepcopy(g:sandwich#default_recipes) ``` Each setting, it is called `recipe`, is a set of a definition of {surrounding}s pair and options. The key named `buns` is used for the definition of {surrounding}. ``` let g:sandwich#recipes += [{'buns': [{surrounding}, {surrounding}], 'option-name1': {value1}, 'option-name2': {value2} ...}] For example: {'buns': ['(', ')']} foo ---> (foo) ``` Or there is a different way, use external textobjects to define {surrounding}s from the difference of two textobjects. ``` let g:sandwich#recipes += [{'external': [{textobj-i}, {textobj-a}], 'option-name1': {value1}, 'option-name2': {value} ...}] For example: {'external': ['it', 'at']}