AutoHotkey is an esoteric scripting language that only runs on Windows, so it does not have wide support among popular code editors. With that said, there is a VS Code plugin that includes a language server, which improves the DX of writing AHK scripts. To use it in Neovim however requires some manual configuration.

Clone & build the plugin

Ensure Node.js is installed and set up properly. Now git clone https://github.com/thqby/vscode-autohotkey2-lsp into a suitable directory, then run the following commands in order:

  1. npm ci
  2. npm run vscode:prepublish

This will use esbuild to build the language server so that the following Neovim config has something to point to.

Configure nvim-lspconfig

Assuming a LazyVim or lazy.nvim setup, modify the nvim-lspconfig configuration as follows:

return {
  "neovim/nvim-lspconfig",
  opts = function (_, opts)
    -- Add this section
    require("lspconfig.configs").ahk2 = {
      default_config = {
        cmd = {
          "node",
          -- NOTE: Ensure this file path (the language server) is correct
          vim.fn.expand("D:/dev/vscode-autohotkey2-lsp/server/dist/server.js"),
          "--stdio"
        },
        filetypes = { "ahk", "autohotkey", "ah2" },
        init_options = {
          locale = "en-us",
          InterpreterPath = "C:/Program Files/AutoHotkey/v2/AutoHotkey.exe",
        },
        single_file_support = true,
        flags = { debounce_text_changes = 500 },
      }
    }
 
    return vim.tbl_deep_extend(
      "force",
      opts,
      {
        ahk2 = {}
        -- existing lspconfig opts overrides can go here
        -- e.g. 
        -- html = {
        --   filetypes = { "html", "templ", "htmlangular" },
        -- },
      }
    )
  end
}

Now restart Neovim and open any .ahk file. Check that the basic LSP functions are available:

  • press K to view tooltips
  • bad syntax should result in error highlighting
  • run :LspInfo to see that the server is started and attached to the buffer

What about syntax highlighting?

For some reason, even though LSP does not normally affect syntax highlighting, I’ve found that syntax highlighting is slightly better with this configuration than without. Tangentially, I’m not even sure why default Neovim (even without LazyVim) has any syntax highlighting for .ahk files in the first place!