From 9afa8477b3a3b5b298e0042e59e391357dbe5c5c Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Thu, 25 Jun 2026 17:36:24 +0200 Subject: [PATCH] fix(treesitter): incremental selection causes beeps when the bell is enabled #40414 Problem: The function visual_select() in treesitter/_select.lua is executing `:normal! v` to ensure that `gv` later goes back to character Visual mode, but doing so when mode() is already `v` first switches back to the Normal mode, then executes , which causes a beep. Solution: Check if the mode() is already `v` and avoid any switching in that case. --- runtime/lua/vim/treesitter/_select.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/lua/vim/treesitter/_select.lua b/runtime/lua/vim/treesitter/_select.lua index c3986b486d..631d9d2724 100644 --- a/runtime/lua/vim/treesitter/_select.lua +++ b/runtime/lua/vim/treesitter/_select.lua @@ -364,8 +364,10 @@ local function visual_select(range) ecol = #vim.fn.getline(erow + 1) + 1 end - -- reset visualmode() to 'v' - vim.cmd.normal({ 'v\27', bang = true }) + if vim.api.nvim_get_mode().mode ~= 'v' then + -- reset visualmode() to 'v' + vim.cmd.normal({ 'v\27', bang = true }) + end vim.fn.setpos("'<", { 0, srow + 1, scol + 1, 0 }) vim.fn.setpos("'>", { 0, erow + 1, ecol, 0 })