Skip to content
The Chat Archive
claude-instant-1· Anthropic Arena Human Preference 55K

Write a basic neovim plugin template in Lua.

  1. User

    Write a basic neovim plugin template in Lua.

  2. Assistant

    Here is a basic template for a Neovim plugin written in Lua:

    -- Plugin name
    local M = {}
    
    -- Define global variables/functions here
    
    -- Called when plugin is loaded
    M.on_load = function()
    
      -- Initialize plugin
      print("Plugin loaded!")
    
    end
    
    -- Called on each Vim/Neovim startup
    M.on_init = function()
    
      -- Register commands/mappings here
      
    end
    
    -- Expose plugin functions/commands
    function M.hello()
      print("Hello from the plugin!")
    end
    
    return M
    

    The key parts:

    • M table defines the plugin namespace
    • on_load runs when plugin is loaded
    • on_init runs each time Neovim starts
    • Functions like hello() expose commands
    • Return M at the end to register the plugin

    This provides a basic template to build out plugin functionality through additional functions, commands, autocommands etc. The plugin would be loaded by requiring this file from init.vim/init.lua.

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