Closed ghost closed 2 years ago
This is possible, but could I ask for what purpose you want this? I want to make sure that any solution I add is addressing the root of the need in the best way possible.
sure. i use dressing.nvim for lsp rename prompt and i want it to behave like the vscode rename input which preselects the name. this is useful because sometimes i want to change the whole name which i just start typing the name and because the text is selected it gets removed. but sometimes i just want to modify the name slightly (to fix a typo for example) then i just use arrow keys to navigate and edit the text.
Ah, gotcha! I think this is a feature that makes sense in VSCode, but maybe doesn't map as well to vim. Are you familiar with insert mode <C-u>
(see :help i_CTRL-U
)? That's a single keypress to clear the default value. While you could start with the default text selected in visual or select mode, each of those comes with some downsides. Visual mode isn't any faster, as you'd still have to use c
or s
to delete the text, and select mode is terrible if you're doing anything besides replacing all of the text (have to <Esc>
before doing what you actually want to do, e.g. A
for appending).
Given this, do you still want the option to have the default text selected? And if so, in visual or select mode?
thanks. i didn't know about the <c-u>
keymap. perhaps i was trying to solve a vim problem the vscode way :)
i don't know how common this problem is but for anyone having the same problem although <c-u>
is a very good option i mapped lsp rename to <A-r>
with this
for _,mode in ipairs({'n','i','v'}) do
vim.api.nvim_set_keymap(mode,'<A-r>',[[&filetype == "DressingInput" ? "<c-u>" : "<cmd>lua vim.lsp.buf.rename()<CR>"]],{
expr = true,
silent = true
})
end
so if i press
Nice! Love the custom mapping 🙂
is it possible to add a new option to input configs so that the default value in the input window is automatically selected. i tried with and
nvim_feedkeys
and autocmds but i couldn't get it to work