nvim-surround

repository·main·Indexed 26 days ago

https://github.com/kylechui/nvim-surround

A Neovim plugin for adding, deleting, and changing surrounding pairs such as quotes, parentheses, HTML tags, and function calls. It provides core operations via keymap patterns: ys{motion}{char} to add, ds{char} to delete, and cs{target}{replacement} to change. Requires Neovim 0.8+ and optionally supports nvim-treesitter-textobjects.

Tokens
957
Snippets
3
Records
3
Agent score
38%

What's inside nvim-surround

  1. Use nvim-surround core operations

    main

    The plugin provides three core operations: adding, deleting, and changing surrounding pairs using specific keymap patterns.

    Keymap Patterns:

    • Add: ys{motion}{char}
    • Delete: ds{char}
    • Change: cs{target}{replacement}

    Delimiter Behavior:

    • Surrounding with an opening delimiter (e.g., () adds a space before and after the selection.
    • Surrounding with a closing delimiter (e.g., )) does not include spaces.
        Old text                    Command         New text
    --------------------------------------------------------------------------------
        surr*ound_words             ysiw)           (surround_words)
        surr*ound_words             ysiw(           ( surround_words )
        *make strings               ys$"            "make strings"
        [delete ar*ound me!]        ds]             delete around me!
        remove <b>HTML t*ags</b>    dst             remove HTML tags
        'change quot*es'            cs'"            "change quotes"
        <b>or tag* types</b>        csth1<CR>       <h1>or tag types</h1>
        delete(functi*on calls)     dsf             function calls
  2. Install nvim-surround

    main

    Install nvim-surround using your preferred plugin manager. It requires Neovim 0.8+ and optionally benefits from nvim-treesitter-textobjects for Tree-sitter text-object support.

    ### Using vim.pack
    
    ```lua
    -- NOTE: This requires Neovim version 0.12 and greater!
    vim.pack.add({ {
        src = "https://github.com/kylechui/nvim-surround",
        version = vim.version.range("4.x"), -- Use for stability; omit to use `main` branch for the latest features
    } })

    Using lazy.nvim

    {
        "kylechui/nvim-surround",
        version = "^4.0.0", -- Use for stability; omit to use `main` branch for the latest features
        event = "VeryLazy",
        -- Optional: See `:h nvim-surround.configuration` and `:h nvim-surround.setup` for details
        -- config = function()
        --     require("nvim-surround").setup({
        --         -- Put your configuration here
        --     })
        -- end
    }
  3. Configure nvim-surround

    main

    Configure the plugin by calling require("nvim-surround").setup(options) for global configuration or require("nvim-surround").buffer_setup(options) for buffer-local settings. Refer to :h nvim-surround.configuration in Neovim for the full list of available options.

    require("nvim-surround").setup({
        -- Put your configuration here
    })