Skip to content

fix: only run checktime if not in command line window#5

Open
tandetat wants to merge 2 commits intoCannon07:mainfrom
tandetat:fix/user-command
Open

fix: only run checktime if not in command line window#5
tandetat wants to merge 2 commits intoCannon07:mainfrom
tandetat:fix/user-command

Conversation

@tandetat
Copy link
Copy Markdown

The checktime command reloads buffers that changed on disk. It can't run inside the command-line window (q: / q/). When CursorHold or FocusGained fires while you're in that window, Neovim throws E11:

Error in CursorHold Autocommands for "*":
E11: Invalid in command-line window; <CR> executes, CTRL-C quits: checktime

Copy link
Copy Markdown
Owner

@Cannon07 Cannon07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! The getcmdwintype() guard is the right approach for avoiding E11.

One small thing: the indentation in the code snippet is slightly off — vim.o.autoread is at the top level but vim.api.nvim_create_autocmd is indented by 2 spaces. Since this is a standalone snippet, they should be at the same level:

vim.o.autoread = true
vim.api.nvim_create_autocmd(
  { "FocusGained", "BufEnter", "CursorHold" },
  {
    callback = function()
      if vim.fn.getcmdwintype() == "" then
        vim.cmd("checktime")
      end
    end,
  }
)

The markdown formatting cleanups look good too.

@tandetat
Copy link
Copy Markdown
Author

Fixed it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants