/ns-textobject.nvim

A textobejct plugin with nvim-surround

Primary LanguageLuaGNU General Public License v3.0GPL-3.0

ns-textobject.nvim

A textobejct plugin with nvim-surround

Stars Issues Repo Size

screenrecorder-2022-10-16_14.16.05.mp4

Requirements

Installation

Install the plugin with your favourite package manager:

Packer.nvim
use({
    "XXiaoA/ns-textobject.nvim",
    after = "nvim-surround",
    config = function()
        require("ns-textobject").setup({
            -- your configuration here
            -- or just keep empty
        })
    end
})

Usage

We will make the keymaps refer to your nvim-surround's aliases automatically after calling setup, if your auto_mapping option is true (defalut is true).

Or, you could map manually like the following:

Click to show the code.
local nstextobject = require("ns-textobject")

vim.keymap.set({ "x", "o" }, "aq", function()
    -- q means the alias of nvim-surround
    -- a means around or i means inside
    nstextobject.create_textobj("q", "a")
end, { desc = "around the quote" })
vim.keymap.set({ "x", "o" }, "iq", function()
    nstextobject.create_textobj("q", "i")
end, { desc = "inside the quote" })

Configuration

{
    auto_mapping = true
    -- disable 'b' and 'B' mapping
    disable_builtin_mapping = true,
}

TODO

  • new option to disable auto mapping for builtin textobject (ib, etc.)
  • support nvim-surround