Skip to main content
Glama
laktek
by laktek

reload_buffer

Refresh a Neovim buffer from disk after external file edits to ensure the editor displays current content.

Instructions

Reload a buffer from disk. Use this after editing a file externally to refresh the buffer in Neovim.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe file path of the buffer to reload

Implementation Reference

  • The main handler function that finds the Neovim instance, locates the buffer by path, and executes the Neovim command to reload it from disk using 'buffer ${bufnr} | edit!'.
    export async function reloadBuffer(bufferPath) {
      const instances = await getNvimInstancesInCwd();
    
      for (const { nvim } of instances) {
        try {
          const buffers = await nvim.buffers;
    
          for (const buf of buffers) {
            const name = await buf.name;
            if (name === bufferPath) {
              // Use nvim command to reload the buffer from disk
              const bufnr = buf.id;
              await nvim.command(`buffer ${bufnr} | edit!`);
    
              return { success: true, path: bufferPath };
            }
          }
        } catch (error) {
          console.error("Error reloading buffer:", error.message);
        }
      }
    
      throw new Error(`Buffer not found: ${bufferPath}`);
    }
  • The tool schema definition including name, description, and input schema requiring a 'path' parameter.
    {
      name: "reload_buffer",
      description:
        "Reload a buffer from disk. Use this after editing a file externally to refresh the buffer in Neovim.",
      inputSchema: {
        type: "object",
        properties: {
          path: {
            type: "string",
            description: "The file path of the buffer to reload",
          },
        },
        required: ["path"],
      },
    },
  • index.js:274-284 (registration)
    The code in the CallToolRequest handler that routes calls to 'reload_buffer' to the reloadBuffer function and formats the response.
    if (name === "reload_buffer") {
      const result = await reloadBuffer(args.path);
      return {
        content: [
          {
            type: "text",
            text: `Successfully reloaded buffer: ${result.path}`,
          },
        ],
      };
    }
  • index.js:12-19 (registration)
    Import of the reloadBuffer handler function from lib/nvim-operations.js.
      getCurrentBuffer,
      listOpenBuffers,
      getBufferContent,
      updateBuffer,
      reloadBuffer,
      reloadAllBuffers,
      openFile,
    } from "./lib/nvim-operations.js";

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/laktek/nvim-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server