Home

Awesome

Create scratch file

Create temporary playground files effortlessly. Find them later without worrying about filenames or locations.

Scratch Intro

Install & Config

-- use lazy.nvim
{
  "LintaoAmons/scratch.nvim",
  event = "VeryLazy",
}
<details> <summary>Detailed Configuration</summary>

Check my neovim config as real life example

return {
  "LintaoAmons/scratch.nvim",
  config = function()
    require("scratch").setup({
      scratch_file_dir = vim.fn.stdpath("cache") .. "/scratch.nvim", -- where your scratch files will be put
      filetypes = { "lua", "js", "sh", "ts" }, -- you can simply put filetype here
      filetype_details = { -- or, you can have more control here
        json = {}, -- empty table is fine
        ["project-name.md"] = {
          subdir = "project-name" -- group scratch files under specific sub folder
        },
        ["yaml"] = {},
        go = {
          requireDir = true, -- true if each scratch file requires a new directory
          filename = "main", -- the filename of the scratch file in the new directory
          content = { "package main", "", "func main() {", "  ", "}" },
          cursor = {
            location = { 4, 2 },
            insert_mode = true,
          },
        },
      },
      window_cmd = "rightbelow vsplit", -- 'vsplit' | 'split' | 'edit' | 'tabedit' | 'rightbelow vsplit'
      use_telescope = true,
      localKeys = {
        {
          filenameContains = { "sh" },
          LocalKeys = {
            {
              cmd = "<CMD>RunShellCurrentLine<CR>",
              key = "<C-r>",
              modes = { "n", "i", "v" },
            },
          },
        },
      },
    })
  end,
  event = "VeryLazy",
}

Modify config at runtime, no need to restart nvim

To check your current configuration, simply type :lua = vim.g.scratch_config

And if you want to modify the config, for example add a new filetype, just call the setup function with your updated config again.

Or you can change the vim.g.scratch_config global veriable directly

</details>

Commands & Keymapps

All commands are started with Scratch, and no default keymappings.

CommandDescription
ScratchCreates a new scratch file in the specified scratch_file_dir directory in your configuration.
ScratchWithNameAllows the creation of a new scratch file with a user-specified filename, including the file extension.
ScratchOpenOpens an existing scratch file from the scratch_file_dir.
ScratchOpenFzfUses fuzzy finding to search through the contents of scratch files and open a selected file.

Keybinding recommandation:

vim.keymap.set("n", "<M-C-n>", "<cmd>Scratch<cr>")
vim.keymap.set("n", "<M-C-o>", "<cmd>ScratchOpen<cr>")

FIND MORE USER FRIENDLY PLUGINS MADE BY ME


<a href="https://lintao-index.pages.dev/getSupport/"> <img src="https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#white" /> </a>