Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xxiaoa/ns-textobject.nvim
Awesome textobject plugin works with nvim-surround
https://github.com/xxiaoa/ns-textobject.nvim
lua neovim neovim-plugin nvim nvim-plugin vim
Last synced: 5 days ago
JSON representation
Awesome textobject plugin works with nvim-surround
- Host: GitHub
- URL: https://github.com/xxiaoa/ns-textobject.nvim
- Owner: XXiaoA
- License: gpl-3.0
- Created: 2022-10-15T01:25:19.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-26T12:40:09.000Z (over 1 year ago)
- Last Synced: 2024-10-04T21:17:02.714Z (about 1 month ago)
- Topics: lua, neovim, neovim-plugin, nvim, nvim-plugin, vim
- Language: Lua
- Homepage:
- Size: 38.1 KB
- Stars: 37
- Watchers: 1
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ns-textobject.nvim
Awesome textobject plugin works with nvim-surroundhttps://user-images.githubusercontent.com/62557596/210149085-8cb8c3e0-dd57-40c6-aeec-5fbac8aa01d1.mp4
Click to show the configuration in demo.
```lua
require("ns-textobject").setup({})-- from https://github.com/kylechui/nvim-surround/discussions/53#discussioncomment-3134891
-- move the following callback into `~/.config/nvim/after/ftplugin/markdown.lua`
require("nvim-surround").buffer_setup({
surrounds = {
["l"] = {
add = function()
local clipboard = vim.fn.getreg("+"):gsub("\n", "")
return {
{ "[" },
{ "](" .. clipboard .. ")" },
}
end,
find = "%b[]%b()",
delete = "^(%[)().-(%]%b())()$",
change = {
target = "^()()%b[]%((.-)()%)$",
replacement = function()
local clipboard = vim.fn.getreg("+"):gsub("\n", "")
return {
{ "" },
{ clipboard },
}
end,
},
},
}
})
```### Requirements
- [nvim-surround](https://github.com/kylechui/nvim-surround)
### Usage
We will make the keymaps refer to your nvim-surround's aliases and surrounds **automatically** after calling `setup`. If you want to disable this feature, check the [Configuration](#Configuration) .
Or you're able to map manually like the following:
Click to show the code.
```lua
local nstextobject = require("ns-textobject")vim.keymap.set({ "x", "o" }, "aq", function()
-- First parameter means a alias or surround of nvim-surround
-- The second one has two choice: `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" })-- Or a simple way:
-- First parameter means a alias or surround of nvim-surround
-- The second one used to add the description for keymap
nstextobject.map_textobj("q", "quotes")
```And here comes some useful features with default configuration:
- For function:
```lua
a = func(args)
-- if press dsf
a = args
-- if press daf
a =
-- if press dif
a = func()
```- For quotes
```lua
s = "this's a `string`"
-- press ciqworld (cursor inside "")
s = "word"
-- press ciqworld (cursor inside ``)
s = "this's a `world`"
```- And others easy-used textobjects without pressing extra keys or leaving main area of keyboard:
- `ia`|`aa`: alias of `i<`|`a<` (for )
- `ir`|`ar`: alias of `i[`|`a[` (for \[sth.\])### Installation
Install the plugin with your favourite package manager:
```lua
use({
"XXiaoA/ns-textobject.nvim",
after = "nvim-surround",
config = function()
require("ns-textobject").setup({
-- your configuration here
-- or just left empty to use defaluts
})
end
})
```### Configuration
```lua
{
auto_mapping = {
-- automatically mapping for nvim-surround's aliases
aliases = true,
-- for nvim-surround's surrounds
surrounds = true,
},
disable_builtin_mapping = {
enabled = true,
-- list of char which shouldn't mapping by auto_mapping
chars = { "b", "B", "t", "`", "'", '"', "{", "}", "(", ")", "[", "]", "<", ">" },
},
}
```### TODO
- [x] new option to disable auto mapping for builtin textobject (ib, etc.)
- [x] support nvim-surround