Skip to content

Commit 9738a47

Browse files
authored
Merge pull request #112 from Sam-programs/doc
doc: add more customization examples
2 parents b0009c0 + 8b671db commit 9738a47

File tree

1 file changed

+64
-38
lines changed

1 file changed

+64
-38
lines changed

readme.md

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -59,42 +59,18 @@ k = function()
5959
end
6060
end
6161
```
62+
## Default configuration
6263

63-
## ⚙️Customization
64-
65-
Call the setup function with your options as arguments.
66-
67-
After the rewrite you can also use any function. So you could for example map
68-
`<space><tab>` to jump with luasnip like this:
69-
70-
```lua
71-
i = {
72-
[" "] = {
73-
["<tab>"] = function()
74-
-- Defer execution to avoid side-effects
75-
vim.defer_fn(function()
76-
-- set undo point
77-
vim.o.ul = vim.o.ul
78-
require("luasnip").expand_or_jump()
79-
end, 1)
80-
end
81-
}
82-
}
83-
```
84-
85-
### Disable mappings
86-
To disable keys set them to `false` in the configuration.
87-
You can also disable all default mappings by setting the `default_mappings` option to false.
88-
89-
<details>
90-
<summary>Default Config</summary>
64+
To disable all default mappings set the `default_mappings` option to false.
65+
To disable specific mappings set their key to `false` in the configuration. There's an example in the Customization section.
9166

9267
```lua
9368
-- lua, default settings
9469
require("better_escape").setup {
95-
timeout = vim.o.timeoutlen,
96-
default_mappings = true,
70+
timeout = vim.o.timeoutlen, -- after `timeout` passes, you can press the escape key and the plugin will ignore it
71+
default_mappings = true, -- setting this to false removes all the default mappings
9772
mappings = {
73+
-- i for insert
9874
i = {
9975
j = {
10076
-- These can all also be functions
@@ -104,8 +80,8 @@ require("better_escape").setup {
10480
},
10581
c = {
10682
j = {
107-
k = "<Esc>",
108-
j = "<Esc>",
83+
k = "<C-c>",
84+
j = "<C-c>",
10985
},
11086
},
11187
t = {
@@ -126,26 +102,76 @@ require("better_escape").setup {
126102
},
127103
}
128104
```
105+
## ⚙️Customization
129106

130-
</details>
107+
Call the setup function with your options as arguments:
108+
```lua
109+
require("better_escape").setup {
110+
timeout = vim.o.timeoutlen, -- after `timeout` passes, you can press the escape key and the plugin will ignore it
111+
default_mappings = true, -- setting this to false removes all the default mappings
112+
mappings = {
113+
-- mode = {
114+
-- firstkey = {
115+
-- secondkey = "Escape key", -- make a key press "Escape key"
116+
-- secondkey = false, -- disable a key
117+
-- },
118+
-- }
119+
}
120+
}
121+
```
122+
123+
Here how you can configure Insert-mode:
124+
```lua
125+
mappings = {
126+
-- i for insert, other modes are the first letter too
127+
i = {
128+
-- map kj to exit insert mode
129+
k = {
130+
j = "<Esc>",
131+
},
132+
-- map jk and jj to exit insert mode
133+
j = {
134+
k = "<Esc>",
135+
j = "<Esc>",
136+
},
137+
-- disable jj
138+
j = {
139+
j = false,
140+
},
141+
}
142+
}
143+
```
144+
145+
You can also use a function instead of keys. So you could for example map
146+
`<space><tab>` to jump with luasnip like this:
147+
148+
```lua
149+
i = {
150+
[" "] = {
151+
["<tab>"] = function()
152+
-- Defer execution to avoid side-effects
153+
vim.defer_fn(function()
154+
-- set undo point
155+
vim.o.ul = vim.o.ul
156+
require("luasnip").expand_or_jump()
157+
end, 1)
158+
end
159+
}
160+
}
161+
```
131162

132163
## API
133164

134165
`require("better_escape").waiting` is a boolean indicating that it's waiting for
135166
a mapped sequence to complete.
136167

137-
<details>
138-
<summary>Statusline example</summary>
139-
140168
```lua
141169
function escape_status()
142170
local ok, m = pcall(require, 'better_escape')
143171
return ok and m.waiting and '' or ""
144172
end
145173
```
146174

147-
</details>
148-
149175
## ❤️ Support
150176

151177
If you like the projects I do and they can help you in your life you can support

0 commit comments

Comments
 (0)