How to escape double quotes in this command

How to write the auto command bellow in lua?

augroup vimStartup | au!
    autocmd BufRead * call setpos('.', getpos("'\""))
augroup end

The idea is porting all my augroups using the function helper I have below, but those dowuble escaped quotes are blowing my mind.

I already have this helper

--- This function is taken from https://github.com/norcalli/nvim_utils
function nvim_create_augroups(definitions)
  for group_name, definition in pairs(definitions) do
    api.nvim_command('augroup '..group_name)
    api.nvim_command('autocmd!')
    for _, def in ipairs(definition) do
      local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
      api.nvim_command(command)
    end
    api.nvim_command('augroup END')
  end
end

local autocmds = {
  terminal_job = {
    { "TermOpen", "*", "startinsert" };
    { "TermOpen", "*", "setlocal listchars= nonumber norelativenumber" };
  };
  resize_windows_proportionally = {
    { "VimResized", "*", ":wincmd =" };
  };
  toggle_search_highlighting = {
    { "InsertEnter", "*", "setlocal nohlsearch" };
  };
  lua_highlight = {
    { "TextYankPost", "*", "silent! lua vim.highlight.on_yank(timeout=2000)" };
  };
  ansi_esc_log = {
    { "BufEnter", "*.log", ":AnsiEsc" };
  };
}

nvim_create_augroups(autocmds)
-- autocommands END

Use [[ my string ]] syntax.

1 Like

It worked perfectly, below my mappings after your suggestion (thanks):

-- autocommands
--- This function is taken from https://github.com/norcalli/nvim_utils
function nvim_create_augroups(definitions)
  for group_name, definition in pairs(definitions) do
    api.nvim_command('augroup '..group_name)
    api.nvim_command('autocmd!')
    for _, def in ipairs(definition) do
      local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
      api.nvim_command(command)
    end
    api.nvim_command('augroup END')
  end
end

local autocmds = {
  terminal_job = {
    { "TermOpen", "*", [[tnoremap <buffer> <Esc> <c-\><c-n>]] };
    { "TermOpen", "*", "startinsert" };
    { "TermOpen", "*", "setlocal listchars= nonumber norelativenumber" };
  };
  restore_cursor = {
    { 'BufRead', '*', [[call setpos(".", getpos("'\""))]] };
  };
  resize_windows_proportionally = {
    { "VimResized", "*", ":wincmd =" };
  };
  toggle_search_highlighting = {
    { "InsertEnter", "*", "setlocal nohlsearch" };
  };
  lua_highlight = {
    { "TextYankPost", "*", [[silent! lua vim.highlight.on_yank() {higroup="IncSearch", timeout=400}]] };
  };
  ansi_esc_log = {
    { "BufEnter", "*.log", ":AnsiEsc" };
  };
}

nvim_create_augroups(autocmds)
-- autocommands END