Skip to content

Commit 18889a4

Browse files
committed
docs(jump): add example of custom "stop jumping" mapping
Related to #1803
1 parent 8f0969d commit 18889a4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

doc/mini-jump.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ It stores various information used in this module. All elements, except
108108
`jumping`, is about the latest jump. They are used as default values for
109109
similar arguments.
110110

111+
Usage ~
112+
This can be used to define mappings which depend on state; either as
113+
a standalone mapping or part of |MiniKeymap.map_multistep()|. For example: >lua
114+
115+
-- Stop jumping after pressing `<Esc>`
116+
local jump_stop = function()
117+
if not MiniJump.state.jumping then return '<Esc>' end
118+
MiniJump.stop_jumping()
119+
end
120+
local opts = { expr = true, desc = 'Stop jumping' }
121+
vim.keymap.set({ 'n', 'x', 'o' }, '<Esc>', jump_stop, opts)
122+
<
111123
Class ~
112124
{JumpingState}
113125

lua/mini/jump.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ MiniJump.config = {
137137
--- `jumping`, is about the latest jump. They are used as default values for
138138
--- similar arguments.
139139
---
140+
---@usage This can be used to define mappings which depend on state; either as
141+
--- a standalone mapping or part of |MiniKeymap.map_multistep()|. For example: >lua
142+
---
143+
--- -- Stop jumping after pressing `<Esc>`
144+
--- local jump_stop = function()
145+
--- if not MiniJump.state.jumping then return '<Esc>' end
146+
--- MiniJump.stop_jumping()
147+
--- end
148+
--- local opts = { expr = true, desc = 'Stop jumping' }
149+
--- vim.keymap.set({ 'n', 'x', 'o' }, '<Esc>', jump_stop, opts)
150+
--- <
140151
---@class JumpingState
141152
---
142153
---@field target __jump_target

0 commit comments

Comments
 (0)