Go to file
github-actions[bot] ec2dc76710
chore(main): release 2.3.0 (#343)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-06-24 09:15:06 -07:00
.github ci: Publish LuaRock when tags are released. 2024-02-27 11:43:22 -08:00
doc feat: Improve `move_cursor`. (#334) 2024-06-08 14:29:15 -07:00
lua/nvim-surround feat(config): Automatically wrap `add` key in a table. (#342) 2024-06-24 09:14:31 -07:00
queries/lua feat: Start the beginnings of queries. 2022-11-09 21:49:10 -08:00
tests feat(config): Automatically wrap `add` key in a table. (#342) 2024-06-24 09:14:31 -07:00
.gitignore fix: Visual selection highlight disappearing. (#312) 2024-02-27 11:24:08 -08:00
.luacheckrc ci: Enable GitHub actions for StyLua, luacheck and tests. (#93) 2022-07-18 22:45:35 +00:00
CHANGELOG.md chore(main): release 2.3.0 (#343) 2024-06-24 09:15:06 -07:00
CONTRIBUTING.md docs: Update CONTRIBUTING. 2022-08-28 18:26:45 -07:00
LICENSE Initial commit, introduces basic code structure. 2022-04-29 12:20:58 -07:00
README.md docs: Improve installation instructions. 2023-04-29 18:53:20 -07:00
selene.toml ci: Use `selene` for linting. 2023-05-22 13:55:15 -07:00
stylua.toml style: Format using StyLua. 2022-07-16 14:13:43 -07:00
vim.yml ci: Use `selene` for linting. 2023-05-22 13:55:15 -07:00

README.md

nvim-surround

Surround selections, stylishly 😎

Features

  • Add/delete/change surrounding pairs
    • Function calls and HTML tags out-of-the-box
  • Dot-repeat previous actions
  • Set buffer-local mappings and surrounds
  • Jump to the nearest surrounding pair for modification
  • Use a single character as an alias for several text-objects
    • E.g. q is aliased to `,',", so csqb replaces the nearest set of quotes with parentheses
  • Surround using powerful pairs that depend on user input
  • Modify custom surrounds
    • First-class support for Vim motions, Lua patterns, and Tree-sitter nodes
  • Highlight selections for visual feedback

🔒 Requirements

  • Neovim 0.8+
  • Recommended] If
    [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) is
    installed, then Tree-sitter nodes may be surrounded and modified, in addition
    to just Vim motions and Lua patterns
    
  • Recommended] If
    [nvim-treesitter-textobjects](https://github.com/nvim-treesitter/nvim-treesitter-textobjects)
    is installed, then Tree-sitter text-objects can be used to define surrounds,
    simplifying configuration
    
    

📦 Installation

Install this plugin using your favorite plugin manager, and then call require("nvim-surround").setup().

lazy.nvim

{
    "kylechui/nvim-surround",
    version = "*", -- Use for stability; omit to use `main` branch for the latest features
    event = "VeryLazy",
    config = function()
        require("nvim-surround").setup({
            -- Configuration here, or leave empty to use defaults
        })
    end
}

packer.nvim

use({
    "kylechui/nvim-surround",
    tag = "*", -- Use for stability; omit to use `main` branch for the latest features
    config = function()
        require("nvim-surround").setup({
            -- Configuration here, or leave empty to use defaults
        })
    end
})

🚀 Usage

The three "core" operations of add/delete/change can be done with the keymaps ys{motion}{char}, ds{char}, and cs{target}{replacement}, respectively. For the following examples, * will denote the cursor position:

    Old text                    Command         New text
--------------------------------------------------------------------------------
    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

Detailed information on how to use this plugin can be found in :h nvim-surround.usage.

⚙️ Configuration

The default configuration is found here. Simply call require("nvim-surround").setup or require("nvim-surround").buffer_setup with the desired options.

More information on how to configure this plugin can be found in :h nvim-surround.configuration.

Contributing

See the contributing file.

Shoutouts