Skip to content
The Chat Archive
o4-mini-2025-04-16· OpenAI LMArena Human Preference 140K

Mappings are not being applied here: [code] Suggest changes.

  1. User

    Mappings are not being applied here:

    -- AstroCore provides a central place to modify mappings, vim options, autocommands, and more!
    -- Configuration documentation can be found with `:h astrocore`
    
    return {
      "AstroNvim/astrocore",
      opts = {
        -- Configure core features of AstroNvim
        features = {
          large_buf = { size = 1024 * 256, lines = 10000 }, -- set global limits for large files for disabling features like treesitter
          autopairs = true, -- enable autopairs at start
          cmp = true, -- enable completion at start
          diagnostics_mode = 3, -- diagnostic mode on start (0 = off, 1 = no signs/virtual text, 2 = no virtual text, 3 = on)
          highlighturl = true, -- highlight URLs at start
          notifications = true, -- enable notifications at start
        },
        -- Diagnostics configuration (for vim.diagnostics.config({...})) when diagnostics are on
        diagnostics = {
          virtual_text = true,
          underline = true,
        },
        -- vim options can be configured here
        options = {
          opt = { -- vim.opt.<key>
            relativenumber = true, -- sets vim.opt.relativenumber
            number = true, -- sets vim.opt.number
            signcolumn = "yes", -- sets vim.opt.signcolumn to yes
            mouse = "", -- Disable the mouse
            clipboard = "unnamedplus", -- Enable clipboard access
    
            -- Localization and spell check options
            spell = true, -- sets vim.opt.spell
            spelllang = { "en_us", "pt_br" },
            -- rtp:append("~/.config/nvim/")
    
            -- Softwrap options
            wrap = true, -- Enable line wrapping
            linebreak = true, -- Break lines at "breakat" characters, thus not splitting words
            breakindent = true, -- Preserve indentation when breaking lines
            whichwrap = "b,s,h,l", -- Set keys which can make the cursor wrap lines
    
            -- Set tab length
            shiftwidth = 0, -- Set to zero to return the same value as tabstop
            tabstop = 4,
          },
          g = { -- vim.g.<key>
            -- configure global vim variables (vim.g)
            -- NOTE: `mapleader` and `maplocalleader` must be set in the AstroNvim opts or before `lazy.setup`
            -- This can be found in the `lua/lazy_setup.lua` file
          },
        },
      },
      mappings = function()
        local no_operation = {
          ["<Down>"] = "<nop>",
          ["<End>"] = "<nop>",
          ["<PageDown>"] = "<nop>",
          ["<PageUp>"] = "<nop>",
          ["<Up>"] = "<nop>",
        }
    
        local keep_selection = {
          [">"] = { ">gv", desc = "Indent selection" },
          ["<"] = { "<gv", desc = "Dedent selection" },
        }
    
        local mappings = {
          n = no_operation,
          i = no_operation,
          o = no_operation,
        }
    
        mappings.v = vim.tbl_deep_extend("force", mappings, no_operation, keep_selection)
    
        return mappings
      end,
    }
    

    Suggest changes.

  2. Assistant

    Here are a few things that are preventing your mappings from ever making it into AstroNvim, along with a working example.

    1. AstroNvim’s core plugin only reads mappings from opts.mappings, not from a top-level mappings key in your lazy.nvim spec.
    2. Your no-op mappings are plain strings, but Astro expects each mapping to be a table { cmd, desc = "…" }.
    3. You’re doing
      vim.tbl_deep_extend("force", mappings, no_operation, keep_selection)
      
      where the first table you pass is your entire mappings table (i,n,o), so you end up with a deeply nested mess. Instead you want to start off with a fresh table and merge in just the two mode-specific subtables.

    —
    Below is a drop-in replacement. Just move the mappings = function() … end inside your opts block, convert every mapping to a { cmd, desc } table, and use an empty {} as the base for your vim.tbl_deep_extend in visual mode.

    return {
      "AstroNvim/astrocore",
      opts = {
        -- … your existing features / diagnostics / options here …
    
        -- ⇣ Add this inside opts! ⇣
        mappings = function()
          -- 1) Define a generic "disable arrow keys" mapping
          local no_op = {
            ["<Down>"]     = { "<nop>", desc = "Disable Down arrow" },
            ["<Up>"]       = { "<nop>", desc = "Disable Up arrow" },
            ["<PageDown>"] = { "<nop>", desc = "Disable PgDn"      },
            ["<PageUp>"]   = { "<nop>", desc = "Disable PgUp"      },
            ["<Home>"]     = { "<nop>", desc = "Disable Home"      },
            ["<End>"]      = { "<nop>", desc = "Disable End"       },
          }
    
          -- 2) In visual mode we also want to keep the selection after indent/dedent
          local keep_selection = {
            [">"] = { ">gv", desc = "Indent selection and reselect" },
            ["<"] = { "<gv", desc = "Dedent selection and reselect" },
          }
    
          -- 3) Build the final table
          return {
            n = no_op,
            i = no_op,
            o = no_op,
            v = vim.tbl_deep_extend("force", {}, no_op, keep_selection),
          }
        end,
      },
    }
    

    Explanation:

    • We moved mappings under the opts key so that AstroNvim actually sees it.
    • We turned each mapping into a table { "<nop>", desc = "…"} so that it includes a description and is in the shape Astro expects.
    • For visual mode, we start with a clean {} and merge in both no_op and keep_selection so arrows stay disabled and </> get gv.

    Save that, reload Neovim, and you should see your arrow-key disablements and persistent visual indents come to life. 🚀

  3. User

    Let's continue from here:

      mappings = function()
        local no_operation = {
          ["<Down>"] = "<nop>",
          ["<End>"] = "<nop>",
          ["<PageDown>"] = "<nop>",
          ["<PageUp>"] = "<nop>",
          ["<Up>"] = "<nop>",
        }
    
        local keep_selection = {
          [">"] = { ">gv", desc = "Indent selection" },
          ["<"] = { "<gv", desc = "Dedent selection" },
        }
    
        return {
          n = no_operation,
          i = no_operation,
          o = no_operation,
          v = vim.tbl_deep_extend("force", {}, no_operation, keep_selection)
        }
      end,
    

    Solve the following error:

    2025-05-14T16:43:30 lazy.nvim  ERROR Failed to run `config` for astrocore
    
    ...ity/lua/astrocommunity/diagnostics/trouble-nvim/init.lua:11: attempt to index local 'maps' (a function value)
    
    # stacktrace:
      - /astrocommunity/lua/astrocommunity/diagnostics/trouble-nvim/init.lua:11 _in_ **values**
      - ~/.config/nvim/lua/lazy_setup.lua:1
      - ~/.config/NixOS/nixos/home-manager/modules/terminal/astronvim/nvim/init.lua:18
    Press ENTER or type command to continue
    
  4. Assistant

    It turned out that the community “trouble-nvim” integration is doing something like:

    local maps = opts.mappings
    for mode,mode_maps in pairs(maps) do … end
    

    so as soon as you hand it a function instead of a table, you get:

    attempt to index local 'maps' (a function value)
    

    The fix

    You need to give opts.mappings a table, not a function. You can still build that table programmatically—you just have to call your builder immediately (or inline it), so that by the time AstroNvim / astrocommunity reads it, it’s already a plain Lua table.

    Here are two equivalent ways to do it:

    1. Inline IIFE (Immediately-Invoked Function Expression)
    return {
      "AstroNvim/astrocore",
      opts = {
        mappings = (function()
          -- your two mapping subtables
          local no_op = {
            ["<Down>"]     = { "<nop>", desc = "Disable Down" },
            ["<Up>"]       = { "<nop>", desc = "Disable Up"   },
            ["<PageDown>"] = { "<nop>", desc = "Disable PgDn" },
            ["<PageUp>"]   = { "<nop>", desc = "Disable PgUp" },
            ["<Home>"]     = { "<nop>", desc = "Disable Home" },
            ["<End>"]      = { "<nop>", desc = "Disable End"  },
          }
          local keep_selection = {
            [">"] = { ">gv", desc = "Indent selection"   },
            ["<"] = { "<gv", desc = "Dedent selection"   },
          }
          return {
            n = no_op,
            i = no_op,
            o = no_op,
            v = vim.tbl_deep_extend("force", {}, no_op, keep_selection),
          }
        end)(),
      },
    }
    
    1. Define locals up-front and then a literal table
    -- in your ~/.config/nvim/lua/…
    local no_op = {
      ["<Down>"]     = { "<nop>", desc = "Disable Down" },
      ["<Up>"]       = { "<nop>", desc = "Disable Up"   },
      ["<PageDown>"] = { "<nop>", desc = "Disable PgDn" },
      ["<PageUp>"]   = { "<nop>", desc = "Disable PgUp" },
      ["<Home>"]     = { "<nop>", desc = "Disable Home" },
      ["<End>"]      = { "<nop>", desc = "Disable End"  },
    }
    local keep_selection = {
      [">"] = { ">gv", desc = "Indent selection" },
      ["<"] = { "<gv", desc = "Dedent selection" },
    }
    
    return {
      "AstroNvim/astrocore",
      opts = {
        mappings = {
          n = no_op,
          i = no_op,
          o = no_op,
          v = vim.tbl_deep_extend("force", {}, no_op, keep_selection),
        },
      },
    }
    

    Either way you end up with opts.mappings being a table of tables, and the trouble-nvim integration will be able to pairs() over it without ever seeing a function.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.