Repository: neovim/neovim
File: runtime/lua/vim/_defaults.lua (Lua)

Code before:
    if cmd.bang then
      vim.print(vim.inspect_pos())
    else
      vim.show_pos()
    end
  end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true })

  vim.api.nvim_create_user_command('InspectTree', function(cmd)
    local opts = { lang = cmd.fargs[1] }

    if cmd.mods ~= '' or cmd.count ~= 0 then
      local count = cmd.count ~= 0 and cmd.count or ''
      local new = cmd.mods ~= '' and 'new' or 'vnew'

      opts.command = ('%s %s%s'):format(cmd.mods, count, new)
    end

    vim.treesitter.inspect_tree(opts)
  end, { desc = 'Inspect treesitter language tree for buffer', count = true, nargs = '?' })

  vim.api.nvim_create_user_command('EditQuery', function(cmd)
    vim.treesitter.query.edit(cmd.fargs[1])
  end, {
    desc = 'Edit treesitter query',
    nargs = '?',
    complete = vim.treesitter.language._complete,
  })

  vim.api.nvim_create_user_command('Open', function(cmd)
    vim.ui.open(assert(cmd.fargs[1]))
  end, {
    desc = 'Open file with system default handler. See :help vim.ui.open()',
    nargs = 1,
    complete = 'file',
  })
end

--- Default mappings
do
  --- Default maps for * and # in visual mode.
  ---
  --- See |v_star-default| and |v_#-default|
  do
    local function _visual_search(forward)
      assert(forward == 0 or forward == 1)
      local pos = vim.fn.getpos('.')
      local vpos = vim.fn.getpos('v')
      local mode = vim.fn.mode()
      local chunks = vim.fn.getregion(pos, vpos, { type = mode })
      local esc_chunks = vim
        .iter(chunks)

Review comment (performance):
perf nit: vim.ts is [lazy loaded](https://github.com/neovim/neovim/blob/7cd5356a6f89a46d83bbba9b7f6496b67f054629/runtime/lua/vim/treesitter.lua#L6) so let's wrap this to avoid eager-loading it:
```suggestion
    complete = function(...) return vim.treesitter.language._complete(...) end,
```

Code after:
    if cmd.bang then
      vim.print(vim.inspect_pos())
    else
      vim.show_pos()
    end
  end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true })

  vim.api.nvim_create_user_command('InspectTree', function(cmd)
    local opts = { lang = cmd.fargs[1] }

    if cmd.mods ~= '' or cmd.count ~= 0 then
      local count = cmd.count ~= 0 and cmd.count or ''
      local new = cmd.mods ~= '' and 'new' or 'vnew'

      opts.command = ('%s %s%s'):format(cmd.mods, count, new)
    end

    vim.treesitter.inspect_tree(opts)
  end, { desc = 'Inspect treesitter language tree for buffer', count = true, nargs = '?' })

  vim.api.nvim_create_user_command('EditQuery', function(cmd)
    vim.treesitter.query.edit(cmd.fargs[1])
  end, {
    desc = 'Edit treesitter query',
    nargs = '?',
    complete = function()
      return vim.treesitter.language._complete()
    end,
  })

  vim.api.nvim_create_user_command('Open', function(cmd)
    vim.ui.open(assert(cmd.fargs[1]))
  end, {
    desc = 'Open file with system default handler. See :help vim.ui.open()',
    nargs = 1,
    complete = 'file',
  })
end

--- Default mappings
do
  --- Default maps for * and # in visual mode.
  ---
  --- See |v_star-default| and |v_#-default|
  do
    local function _visual_search(forward)
      assert(forward == 0 or forward == 1)
      local pos = vim.fn.getpos('.')
      local vpos = vim.fn.getpos('v')
      local mode = vim.fn.mode()
      local chunks = vim.fn.getregion(pos, vpos, { type = mode })