Skip to content

Commit 5b11e24

Browse files
authored
feat: introduce exclude option (#6)
1 parent b455da4 commit 5b11e24

File tree

4 files changed

+100
-18
lines changed

4 files changed

+100
-18
lines changed

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,40 @@ Default : `nil`
5151

5252
By default, this plugin doesn't remap the `<Del>` key to use the blackhole register (and it will work as the old `x` key). By setting `override_del` to true, `<Del>` key will not cut any more and not afect your current yank.
5353

54+
### `exclude`
55+
56+
Default: `{}`
57+
58+
For some reason, you may doesn't want `cutlass` to override some keys, you can exclude mappings to be set by adding this to the exclude option using format `"{mode}{key}"`.
59+
60+
Eg. If you want to exclude `s` key in normal mode, sets `exclude` option to `{ "ns" }` ; If you want to exclude `<bs>` key in select mode, sets `exclude` option to `{ "s<bs>" }`.
61+
5462
## Integration
5563

64+
<details>
65+
<summary><b>svermeulen/vim-yoink</b></summary>
66+
5667
If you have [svermeulen/vim-yoink](https://github.com/svermeulen/vim-yoink) installed, it will work seemlessly as original [svermeulen/vim-cutlass](https://github.com/svermeulen/vim-cutlass). Just follow the [integration instructions](https://github.com/svermeulen/vim-yoink#integration-with-vim-cutlass).
5768

58-
## FAQ
69+
</details>
70+
71+
<details>
72+
<summary><b>ggandor/lightspeed.nvim</b></summary>
5973

60-
**What if I don't want cutlass to remap the `s` key ?**
74+
When you're using plugins like [ggandor/lightspeed.nvim](https://github.com/ggandor/lightspeed.nvim), you should not want cutlass to remap the `s` key. You can do this using the `exclude` option:
6175

62-
When you're using plugins like [ggandor/lightspeed.nvim](https://github.com/ggandor/lightspeed.nvim), you should not want cutlass to remap the `s` key. Cutlass only map keys if no mapping has been set before.
63-
So, just check that you are calling the `setup` function after the lightspeed's `setup` function.
76+
```lua
77+
use({
78+
"gbprod/cutlass.nvim",
79+
config = function()
80+
require("cutlass").setup({
81+
exclude = { "ns", "nS" },
82+
})
83+
end
84+
})
85+
```
6486

65-
(This advice could apply to other plugins ;) )
87+
</details>
6688

6789
## Credits
6890

doc/cutlass.nvim.txt

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Table of Contents *cutlass.nvim-table-of-contents*
88
- Usage |cutlass.nvim-usage|
99
- Configuration |cutlass.nvim-configuration|
1010
- Integration |cutlass.nvim-integration|
11-
- FAQ |cutlass.nvim-faq|
1211
- Credits |cutlass.nvim-credits|
1312

1413
==============================================================================
@@ -81,25 +80,45 @@ By default, this plugin doesn’t remap the `<Del>` key to use the blackhole
8180
register (and it will work as the old `x` key). By setting `override_del` to
8281
true, `<Del>` key will not cut any more and not afect your current yank.
8382

83+
`EXCLUDE` ~
84+
85+
Default: `{}`
86+
87+
For some reason, you may doesn’t want `cutlass` to override some keys, you
88+
can exclude mappings to be set by adding this to the exclude option using
89+
format `"{mode}{key}"`.
90+
91+
Eg. If you want to exclude `s` key in normal mode, sets `exclude` option to `{
92+
"ns" }` ; If you want to exclude `<bs>` key in select mode, sets `exclude`
93+
option to `{ "s<bs>" }`.
94+
8495
INTEGRATION *cutlass.nvim-integration*
8596

97+
svermeulen/vim-yoink ~
98+
8699
If you have svermeulen/vim-yoink <https://github.com/svermeulen/vim-yoink>
87100
installed, it will work seemlessly as original svermeulen/vim-cutlass
88101
<https://github.com/svermeulen/vim-cutlass>. Just follow the integration
89102
instructions
90103
<https://github.com/svermeulen/vim-yoink#integration-with-vim-cutlass>.
91104

92-
FAQ *cutlass.nvim-faq*
93-
94-
**What if I don’t want cutlass to remap the `s` key ?**
105+
ggandor/lightspeed.nvim ~
95106

96107
When you’re using plugins like ggandor/lightspeed.nvim
97108
<https://github.com/ggandor/lightspeed.nvim>, you should not want cutlass to
98-
remap the `s` key. Cutlass only map keys if no mapping has been set before. So,
99-
just check that you are calling the `setup` function after the lightspeed’s
100-
`setup` function.
109+
remap the `s` key. You can do this using the `exclude` option:
110+
111+
>
112+
use({
113+
"gbprod/cutlass.nvim",
114+
config = function()
115+
require("cutlass").setup({
116+
exclude = { "ns", "nS" },
117+
})
118+
end
119+
})
120+
<
101121

102-
(This advice could apply to other plugins ;) )
103122

104123
CREDITS *cutlass.nvim-credits*
105124

lua/cutlass.lua

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
local cutlass = {}
22

33
local function with_defaults(options)
4+
local flip = function(t)
5+
local flipped = {}
6+
for _, value in pairs(t) do
7+
flipped[value] = true
8+
end
9+
10+
return flipped
11+
end
12+
413
return {
514
cut_key = options.cut_key or nil,
615
override_del = options.override_del or nil,
16+
exclude = options.exclude and flip(options.exclude) or {},
717
}
818
end
919

@@ -34,7 +44,7 @@ function cutlass.override_delete_and_change_bindings()
3444

3545
for _, override in ipairs(overrides) do
3646
for _, mode in ipairs(override.modes) do
37-
if vim.fn.maparg(override.lhs, mode) == "" then
47+
if not cutlass.options.exclude[mode .. override.lhs] and vim.fn.maparg(override.lhs, mode) == "" then
3848
map(mode, override.lhs, override.rhs, keymap_opts)
3949
end
4050
end
@@ -54,11 +64,18 @@ function cutlass.override_select_bindings()
5464
-- Add a map for every printable character to copy to black hole register
5565
for char_nr = 33, 126 do
5666
local char = vim.fn.nr2char(char_nr)
57-
map("s", char, '<c-o>"_c' .. escape_rhs(char), keymap_opts)
67+
if not cutlass.options.exclude["s" .. char] then
68+
map("s", char, '<c-o>"_c' .. escape_rhs(char), keymap_opts)
69+
end
70+
end
71+
72+
if not cutlass.options.exclude["s<bs>"] then
73+
map("s", "<bs>", '<c-o>"_c', keymap_opts)
5874
end
5975

60-
map("s", "<bs>", '<c-o>"_c', keymap_opts)
61-
map("s", "<space>", '<c-o>"_c<space>', keymap_opts)
76+
if not cutlass.options.exclude["s<space>"] then
77+
map("s", "<space>", '<c-o>"_c<space>', keymap_opts)
78+
end
6279
end
6380

6481
function cutlass.create_cut_bindings()

spec/cutlass_spec.lua

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ end
1010

1111
describe("Options should be set correctly", function()
1212
it("should take default values", function()
13+
vim.cmd("mapclear")
1314
cutlass.setup()
1415
assert(cutlass.options.cut_key == nil)
1516
end)
1617
end)
1718

1819
describe("Overrides delete and change mappings", function()
1920
it("should map change and delete keys", function()
21+
vim.cmd("mapclear")
2022
cutlass.setup()
2123
local mappings = get_mappings("n")
2224

@@ -27,6 +29,7 @@ describe("Overrides delete and change mappings", function()
2729
end)
2830

2931
it("should map change and delete keys in x mode", function()
32+
vim.cmd("mapclear")
3033
cutlass.setup()
3134
local mappings = get_mappings("x")
3235

@@ -37,9 +40,10 @@ describe("Overrides delete and change mappings", function()
3740
end)
3841

3942
it("should not override already mapped keys", function()
43+
vim.cmd("mapclear")
4044
vim.api.nvim_set_keymap("n", "d", "gv", { noremap = true, silent = true })
41-
4245
cutlass.setup()
46+
4347
local mappings = get_mappings("n")
4448

4549
assert(mappings["d"].rhs == "gv")
@@ -48,6 +52,7 @@ end)
4852

4953
describe("Overrides select mode", function()
5054
it("should overrides select mode", function()
55+
vim.cmd("mapclear")
5156
cutlass.setup()
5257
local mappings = get_mappings("s")
5358

@@ -67,6 +72,7 @@ end)
6772

6873
describe("Create cut mappings", function()
6974
it("should map cut keys if setup", function()
75+
vim.cmd("mapclear")
7076
cutlass.setup({
7177
cut_key = "m",
7278
})
@@ -78,3 +84,21 @@ describe("Create cut mappings", function()
7884
assert(mappings["mm"].rhs, "dd")
7985
end)
8086
end)
87+
88+
describe("Exclude option", function()
89+
it("should not map excluded mapping", function()
90+
vim.cmd("mapclear")
91+
cutlass.setup({
92+
exclude = { "ns", "nS", "sa", "s<bs>", "s<space>" },
93+
})
94+
local mappings = get_mappings("n")
95+
96+
assert(nil == mappings["s"])
97+
assert(nil == mappings["S"])
98+
99+
mappings = get_mappings("s")
100+
assert(nil == mappings["a"])
101+
assert(nil == mappings["<bs>"])
102+
assert(nil == mappings["<space>"])
103+
end)
104+
end)

0 commit comments

Comments
 (0)