Skip to content

Commit a06dea1

Browse files
authored
feat!: Pattern/function-defined modifications. (#113)
* refactor!: Restructure user configuration. * refactor!: Use strict typing for configuration. * TODO: Write translation layer. * feat: Some semblance of a working prototype. * fix: Indexing issue, edge case with first line. * fix: Reverse search patterns. * chore!: Remove arguments from function calls. * fix: Quote configuration, non-pattern based finds. * fix: Get HTML tags (mostly) working. * For better accuracy/to avoid edge cases, probably use `it/at`. * fix: Smart quotes, somehow passes all test cases. * feat: Add pattern-based deletions. * fix: Find function error. * fix: Deletions not occurring on same line. * feat: Enable `change.replacement` omission. * docs: Better comment the code, introduce config helpers. * docs: Update type annotations. * fix: Deletion error when setting up custom `ds"`. * refactor!: Move `invalid_key_behavior` back in `delimiters`. * fix: Some HTML Lua patterns. * chore: Minor changes (patterns, annotations, etc.). * refactor: Omit requirement for modify pattern. * feat: Initial translation layer. * feat: Finish translation layer. * style: Use translation layer on default configuration. * style: Use translation layer for more config. * fix: Aliasing issues. * fix: Proper invalid key behavior for `add`. * feat: Implement invalid key behavior for `find`. * feat: Implement invalid key behavior for delete. * refactor: Provide config helpers. * fix: Function Lua expression. * fix: Invalid key behavior streamlining. * feat!: Convert default invalid key behavior to NOOP. * refactor!: Abstract text-objects code into separate file. (#117) * refactor!: Remove special-case code for whitespace. Breaking change: Cases like `cs<>` have slightly different behavior; it will remove a space character if only one side has it, e.g. `cs<>` on ``` < hello world> ``` will yield ``` <hello world> ``` * refactor: Remove more code, document text-objects. * chore: Code cleanup. * chore: Remove extraneous `require`. * refactor: Migrate lookbehind code to `textobjects`. * fix: Match `delete` with `change.target` for open pairs. * fix: Function calls have two selections. * When a delimiter does not exist, a selection { pos, pos - 1 } is returned to signify an empty selection. * fix: Issue with modifying surrounds on first column. * fix: Modifying surrounds at { 1, 1 }. * fix: HTML change whole tag via `T`. * docs: Initial rewrite for help docs. * docs: Rename sections, add configuration. * docs: Finish rewriting help docs. * fix: Round down columns to nearest valid index. * fix: Modifications via pattern-based selections. * feat: Prefer surrounds that start near the cursor. * fix: Re-enable aliases (oops). * feat: Add soft deprecation warnings. * tests: Rewrite tests. * docs: Link to `delimiters` section as necessary. * docs: Add `i` key description. * docs: Update README. * feat!: Change default `invalid_key_behavior`. * refactor!: Rename `highlight_motion` to `highlight`. * refactor!: Use term `surrounds` for configuration. * chore: Validate inputs for pattern-matching. * Fix a few left-over places where `delimiters` is still used. * Add deprecation warning about using `surrounds` for configuration. * fix: Type-casting to integer. * docs: Link to external resources. * fix: Blockwise visual map with `gS`. * tests: Test open/close whitespace. * docs: Clean up help docs, remove more `delimiters`. * feat: Use nightly `cancelreturn` in `get_input()`. * fix: Incompatibility with `targets.vim`. * fix: Insert surrounds on last column. * When querying the user for input, the column gets clamped to the nearest valid column, i.e. #line. This fix grabs the cursor position before clamping occurs, allowing for proper insertion at the end of the line. * style: Simplify default configuration. * fix: Invalid key behavior for single characters.
1 parent 306a928 commit a06dea1

18 files changed

+2364
-1219
lines changed

.github/workflows/integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ jobs:
5050
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
5151
5252
- name: Run tests
53-
run: nvim --headless --noplugin -c 'packadd plenary.nvim' -c "PlenaryBustedDirectory tests/"
53+
run: nvim --headless --noplugin -c 'packadd plenary.nvim' -c "PlenaryBustedDirectory tests/ { minimal_init = 'tests/minimal_init.lua' }"

README.md

+30-59
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ Surround selections, stylishly :sunglasses:
88

99
## :sparkles: Features
1010

11-
* Add/change/remove surrounding pairs and HTML tags
12-
* Change *only* the surrounding HTML tag's element type, and leave its
13-
attributes
11+
* Add/delete/change surrounding pairs
12+
* Function calls and HTML tags out-of-the-box
1413
* Dot-repeat previous actions
1514
* Set buffer-local mappings and surrounds
16-
* Surround using powerful pairs that depend on user input
1715
* Jump to the *nearest* surrounding pair for modification
1816
* Use a single character as an alias for several text-objects
1917
* E.g. `q` is aliased to <code>\`,',"</code>, so <code>csqb</code> replaces
2018
the *nearest* set of quotes with parentheses
21-
* Highlight the section that you are about to surround, as a visual indicator
19+
* Surround using powerful pairs that depend on user input
20+
* Modify custom surrounds
21+
* First-class support for text-objects and Lua patterns
22+
* Highlight selections for visual feedback
2223

2324
For more information, see [`:h
2425
nvim-surround`](https://github.com/kylechui/nvim-surround/blob/main/doc/nvim-surround.txt).
@@ -40,64 +41,34 @@ use({
4041

4142
## :rocket: Usage
4243

43-
Information on how to use this plugin can be found in [the
44-
wiki](https://github.com/kylechui/nvim-surround/wiki).
45-
46-
## :gear: Configuration
47-
48-
### The Basics
49-
50-
All delimiter keys should be one character *exactly*, and *unique*. In the
51-
`delimiters` table, each value is either a pair of strings, representing the
52-
left and right surrounding pair, or a function returning a pair of strings.
53-
Multi-line strings are represented by tables of strings, with each string
54-
representing a new line.
55-
56-
> Looking for inspiration/examples? Want to share some cool surrounds that
57-
> you've made? You can visit the [surrounds
58-
> showcase](https://github.com/kylechui/nvim-surround/discussions/53) to see a
59-
> community-made list of custom surrounds!
60-
61-
### Modifying Defaults
44+
The three "core" operations of `add`/`delete`/`change` can be done with the
45+
keymaps `ys{motion}{char}`, `ds{char}`, and `cs{target}{replacement}`,
46+
respectively. For the following examples, `*` will denote the cursor position:
47+
48+
```help
49+
Old text Command New text
50+
--------------------------------------------------------------------------------
51+
surr*ound_words ysiw) (surround_words)
52+
*make strings ys$" "make strings"
53+
[delete ar*ound me!] ds] delete around me!
54+
remove <b>HTML t*ags</b> dst remove HTML tags
55+
'change quot*es' cs'" "change quotes"
56+
<b>or tag* types</b> csth1<CR> <h1>or tag types</h1>
57+
delete(functi*on calls) dsf function calls
58+
```
6259

63-
To change a preset, give the corresponding key a new value. To disable any
64-
functionality, simply set the corresponding key's value to `false`. For example,
60+
Detailed information on how to use this plugin can be found in [`:h
61+
nvim-surround.usage`](https://github.com/kylechui/nvim-surround/blob/main/doc/nvim-surround.txt).
6562

66-
```lua
67-
require("nvim-surround").setup({
68-
delimiters = {
69-
pairs = { -- Remaps "a" and "b"
70-
["a"] = {
71-
{ "this", "has", "several", "lines" },
72-
"single line",
73-
},
74-
["b"] = function()
75-
return {
76-
"hello",
77-
"world",
78-
}
79-
end,
80-
},
81-
HTML = { -- Disables HTML-style mappings
82-
["t"] = false,
83-
["T"] = false,
84-
},
85-
},
86-
highlight_motion = { -- Disables highlights
87-
duration = false,
88-
},
89-
})
90-
```
63+
## :gear: Configuration
9164

92-
For buffer-local configurations, just call
93-
`require("nvim-surround").buffer_setup` for any buffer that you would like to
94-
configure. This can be especially useful for setting filetype-specific surrounds
95-
by calling `buffer_setup` inside `ftplugin/[filetype].lua`.
65+
The default configuration is found
66+
[here](https://github.com/kylechui/nvim-surround/blob/main/lua/nvim-surround/config.lua).
67+
Simply call `require("nvim-surround").setup` or
68+
`require("nvim-surround").buffer_setup` with the desired options.
9669

97-
For more information, see [`:h
98-
nvim-surround`](https://github.com/kylechui/nvim-surround/blob/main/doc/nvim-surround.txt),
99-
or the [default
100-
configuration](https://github.com/kylechui/nvim-surround/blob/main/lua/nvim-surround/config.lua).
70+
More information on how to configure this plugin can be found in [`:h
71+
nvim-surround.configuration`](https://github.com/kylechui/nvim-surround/blob/main/doc/nvim-surround.txt).
10172

10273
## Contributing
10374

0 commit comments

Comments
 (0)