Home

Awesome

surround.nvim

Features

Key mappings

There are two keymap modes for normal mode mappings.

Normal Mode - Sandwich Mode

  1. Provides key mapping to add surrounding characters.( visually select then press s<char> or press sa{motion}{char})
  2. Provides key mapping to replace surrounding characters.( sr<from><to> )
  3. Provides key mapping to delete surrounding characters.( sd<char> )
  4. ss repeats last surround command.

Normal Mode - Surround Mode

  1. Provides key mapping to add surrounding characters.( visually select then press s<char> or press ys{motion}{char})
  2. Provides key mapping to replace surrounding characters.( cs<from><to> )
  3. Provides key mapping to delete surrounding characters.( ds<char> )

Insert Mode

IDK I was bored

  1. Cycle surrounding quotes type. (stq)
  2. Cycle surrounding brackets type. (stb)
  3. Use <char> == f for adding, replacing, deleting functions.

Installation

  1. vim-plug: Plug 'ur4ltz/surround.nvim' and Put this somewhere in your init.vim: lua require"surround".setup{}
  2. minPlug: MinPlug ur4ltz/surround.nvim and Put this somewhere in your init.vim: lua require"surround".setup{}
  3. Packer.nvim
use {
  "ur4ltz/surround.nvim",
  config = function()
    require"surround".setup {mappings_style = "sandwich"}
  end
}

OR

use {
  "ur4ltz/surround.nvim",
  config = function()
    require"surround".setup {mappings_style = "surround"}
  end
}

Configuration

Format: for vimscript let g:surround_<option> and for lua vim.g.surround_<option>

{
  nestable = {
    b = { "(", ")" },
    s = { "[", "]" },
    B = { "{", "}" },
    a = { "<", ">" }
    },
  linear = {
    q = { "'", "'" },
    t = { "`", "`" },
    d = { '"', '"' }
  },
}

or pass a lua table to the setup function

require"surround".setup {
  context_offset = 100,
  load_autogroups = false,
  mappings_style = "sandwich",
  map_insert_mode = true,
  quotes = {"'", '"'},
  brackets = {"(", '{', '['},
  space_on_closing_char = false,
  pairs = {
    nestable = { b = { "(", ")" }, s = { "[", "]" }, B = { "{", "}" }, a = { "<", ">" } },
    linear = { q = { "'", "'" }, t = { "`", "`" }, d = { '"', '"' } }
  },
  prefix = "s"
}

Caveats

  1. Only supports neovim and always will because it's written in lua which is neovim exclusive.
  2. Doesn't support python docstrings and html tags yet. Either can be added to the pairs table with an alias as shortcut. (No dynamic tags yet, though. You need to add the tags you want beforehand.)
  3. No vim docs(idk how to make them. Need help)
  4. Support for repeating actions with . requires tpope's vim-repeat.

Contributing

You are more than welcome to submit PR for a feature you would like to see or bug fixes.