Last active
January 10, 2022 01:57
-
-
Save VonHeikemen/a0a58cab2c910065420ecf5f4102c58c to your computer and use it in GitHub Desktop.
Neovim: Use backspace when `buftype=prompt`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Taken from here: | |
-- https://github.com/neovim/neovim/issues/14116#issuecomment-977555102 | |
function PromptBackspace() | |
-- Have to know the length of the prompt | |
local prompt = 2 | |
local cursor = vim.api.nvim_win_get_cursor(0) | |
local line = cursor[1] | |
local col = cursor[2] | |
if col ~= prompt then | |
vim.api.nvim_buf_set_text(0, line - 1, col - 1, line - 1, col, {''}) | |
vim.api.nvim_win_set_cursor(0, {line, col - 1}) | |
end | |
end | |
vim.api.nvim_buf_set_keymap( | |
0, | |
'i', | |
'<Bs>', | |
'<cmd>lua PromptBackspace()<CR>', | |
{noremap = true} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This also works.