diff --git a/lua/avante/diff.lua b/lua/avante/diff.lua
index 4705aef..7be23d9 100644
--- a/lua/avante/diff.lua
+++ b/lua/avante/diff.lua
@@ -515,7 +515,7 @@ end
 function M.choose(side)
   local bufnr = api.nvim_get_current_buf()
   if vim.fn.mode() == "v" or vim.fn.mode() == "V" or vim.fn.mode() == "" then
-    api.nvim_feedkeys(api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
+    vim.cmd("noautocmd stopinsert")
     -- have to defer so that the < and > marks are set
     vim.defer_fn(function()
       local start = api.nvim_buf_get_mark(0, "<")[1]
diff --git a/lua/avante/llm_tools/str_replace.lua b/lua/avante/llm_tools/str_replace.lua
index 9f47001..5c3f336 100644
--- a/lua/avante/llm_tools/str_replace.lua
+++ b/lua/avante/llm_tools/str_replace.lua
@@ -136,8 +136,8 @@ function M.func(opts, on_log, on_complete)
   local confirm = Helpers.confirm("Are you sure you want to apply this modification?", function(ok)
     pcall(vim.api.nvim_del_augroup_by_id, augroup)
     vim.api.nvim_set_current_win(sidebar.code.winid)
-    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
-    vim.cmd("undo")
+    vim.cmd("noautocmd stopinsert")
+    vim.cmd("noautocmd undo")
     if not ok then
       vim.api.nvim_set_current_win(current_winid)
       on_complete(false, "User canceled")
diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua
index 2173a1b..ac51062 100644
--- a/lua/avante/sidebar.lua
+++ b/lua/avante/sidebar.lua
@@ -205,7 +205,7 @@ end
 function Sidebar:shutdown()
   Llm.cancel_inflight_request()
   self:close()
-  vim.cmd("stopinsert")
+  vim.cmd("noautocmd stopinsert")
 end
 
 ---@return boolean
@@ -1371,7 +1371,7 @@ function Sidebar:apply(current_cursor)
 
           local function process(winid)
             api.nvim_set_current_win(winid)
-            api.nvim_feedkeys(api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
+            vim.cmd("noautocmd stopinsert")
             Diff.add_visited_buffer(bufnr)
             Diff.process(bufnr)
             api.nvim_win_set_cursor(winid, { 1, 0 })
@@ -1411,7 +1411,7 @@ function Sidebar:apply(current_cursor)
       insert_conflict_contents(bufnr, snippets)
       local function process(winid)
         api.nvim_set_current_win(winid)
-        api.nvim_feedkeys(api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
+        vim.cmd("noautocmd stopinsert")
         Diff.add_visited_buffer(bufnr)
         Diff.process(bufnr)
         api.nvim_win_set_cursor(winid, { 1, 0 })
@@ -1893,10 +1893,7 @@ function Sidebar:on_mount(opts)
         then
           api.nvim_set_current_win(self.input_container.winid)
           vim.defer_fn(function()
-            if Config.windows.ask.start_insert then
-              Utils.debug("starting insert")
-              vim.cmd("startinsert!")
-            end
+            if Config.windows.ask.start_insert then vim.cmd("noautocmd startinsert!") end
           end, 300)
         end
       end
@@ -2910,7 +2907,7 @@ function Sidebar:create_input_container(opts)
 
   if Utils.in_visual_mode() then
     -- Exit visual mode
-    api.nvim_feedkeys(api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
+    vim.cmd("noautocmd stopinsert")
   end
 
   self.input_container:map("n", Config.mappings.submit.normal, on_submit)
@@ -3070,14 +3067,14 @@ function Sidebar:create_input_container(opts)
     group = self.augroup,
     buffer = self.input_container.bufnr,
     callback = function()
-      if Config.windows.ask.start_insert then vim.cmd("startinsert!") end
+      if Config.windows.ask.start_insert then vim.cmd("noautocmd startinsert!") end
     end,
   })
 
   api.nvim_create_autocmd("BufLeave", {
     group = self.augroup,
     buffer = self.input_container.bufnr,
-    callback = function() vim.cmd("stopinsert") end,
+    callback = function() vim.cmd("noautocmd stopinsert") end,
   })
 
   -- Show hint in insert mode
diff --git a/lua/avante/suggestion.lua b/lua/avante/suggestion.lua
index 9292751..e06b35d 100644
--- a/lua/avante/suggestion.lua
+++ b/lua/avante/suggestion.lua
@@ -417,7 +417,7 @@ function Suggestion:accept()
       self:set_internal_move(true)
       api.nvim_win_set_cursor(0, { first_line_row, col })
       vim.cmd("normal! zz")
-      vim.cmd("startinsert")
+      vim.cmd("noautocmd startinsert")
       self:set_internal_move(false)
       return
     end
diff --git a/lua/avante/ui/prompt_input.lua b/lua/avante/ui/prompt_input.lua
index c87de0e..c630c0d 100644
--- a/lua/avante/ui/prompt_input.lua
+++ b/lua/avante/ui/prompt_input.lua
@@ -129,14 +129,14 @@ function PromptInput:open()
   self:setup_keymaps()
   self:setup_autocmds()
 
-  if self.start_insert then vim.cmd([[startinsert!]]) end
+  if self.start_insert then vim.cmd("noautocmd startinsert!") end
 end
 
 function PromptInput:close()
   if not self.bufnr then return end
   self:stop_spinner()
   self:close_shortcuts_hints()
-  if api.nvim_get_mode().mode == "i" then vim.cmd([[stopinsert]]) end
+  if api.nvim_get_mode().mode == "i" then vim.cmd("noautocmd stopinsert") end
   if self.winid and api.nvim_win_is_valid(self.winid) then
     api.nvim_win_close(self.winid, true)
     self.winid = nil
diff --git a/lua/avante/utils/init.lua b/lua/avante/utils/init.lua
index f333834..0b44379 100644
--- a/lua/avante/utils/init.lua
+++ b/lua/avante/utils/init.lua
@@ -450,7 +450,7 @@ function M.unlock_buf(bufnr)
 end
 
 function M.lock_buf(bufnr)
-  vim.cmd("stopinsert")
+  vim.cmd("noautocmd stopinsert")
   vim.bo[bufnr].readonly = true
   vim.bo[bufnr].modified = false
   vim.bo[bufnr].modifiable = false
