Modifying starting position of cursor in snacks.input?
#2953
|
I'd like to be able to start the |
Replies: 2 comments 3 replies
vim.keymap.set("n", "<Leader>cn", function()
vim.ui.input({ prompt = "New Name: ", scope = "cursor" }, function(input)
if input and #input ~= 0 then
vim.lsp.buf.rename(input)
end
end)
end) |
|
I asked Claude to lay out my solution in a straightforward, step-by-step manner, so this should be pretty easy to follow. Let me know if you need any extra help. 1. Why the cursor is at the end. vim.api.nvim_win_call(win.win, function()
vim.cmd("startinsert!")
end)The 2. 3. Config-only fix. Put it on the {
"folke/snacks.nvim",
opts = {
styles = {
input = {
on_win = function(self)
vim.schedule(function()
if not self:valid() then
return
end
vim.cmd("stopinsert")
vim.api.nvim_win_set_cursor(self.win, { 1, 0 })
end)
end,
},
},
},
}This works because 4. Want insert mode but at column 0 instead? Swap the last two lines for a cursor set followed by 5. One wrinkle once you land in normal mode: the On the snippet above — worth being precise about what it changes, because it isn't the cursor. Those linked lines are local prompt_opts = {
prompt = 'New Name: ',
default = cword,
scope = 'cursor',
}
vim.ui.input(prompt_opts, function(input) ... end)So re-passing |
I asked Claude to lay out my solution in a straightforward, step-by-step manner, so this should be pretty easy to follow. Let me know if you need any extra help.
It isn't documented because there's no option — the behaviour is hard-coded — but you can get it from config alone, without wrapping
vim.ui.input.1. Why the cursor is at the end.
lua/snacks/input.luafinishes withThe
!is theAform — insert at end of line. Nothing there reads a config key, which is why you found nothing in the docs.2.
on_winalone is too early.snacks.wininvokesopts.on_winfrom insideM:show(), andshow()runs duringSnacks.win(opts.win)…