Nixvim: how to add userCommands

I am not getting how to implement the following from Tinymist Docs in Nixvim

vim.api.nvim_create_user_command("OpenPdf", function()
  local filepath = vim.api.nvim_buf_get_name(0)
  if filepath:match("%.typ$") then
    local pdf_path = filepath:gsub("%.typ$", ".pdf")
    vim.system({ "open", pdf_path })
  end
end, {})

Thats how I am currently trying to do it with no success.

programs.nixvim.userCommands = {
      "Hallo" = {
        command = ''
          function()
            print("Hallo, NixVim!")
          end
        '';
      };

      "OpenPdf" = {
        command = ''
          function()
            local filepath = vim.api.nvim_buf_get_name(0)
            if filepath:match("%.typ$") then
              local pdf_path = filepath:gsub("%.typ$", ".pdf")
              vim.system({ "xdg-open", pdf_path })
            end
          end
        '';
      };
};

Have you tried with command.__raw? If I understand the docs correctly you are currently passing the functions as Lua strings, not Lua code.

There’s also the mkRaw utility function.

1 Like

Thank you .__raw was the solution