LintaoAmons / scratch.nvim

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Breaking Change!: use setup function instead of json config. If you meet any issue, you can use tag to downgrade to previous version, like v0.13.2

Create scratch file

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

  • With other nvim's goodies.
    • with treesitter to have syntax highlighting
    • with lsp and cmp to have auto-cmp, auto-format and other lsp goodies
    • with michaelb/sniprun or metakirby5/codi.vim to run scratch file
Scratch.mp4

Install & Config

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

Check my neovim config as real life example

return {
    "LintaoAmons/scratch.nvim",
    opts = {
        scratch_file_dir = vim.fn.stdpath("cache") .. "/scratch.nvim", -- where your scratch files will be put
        filetypes = { "lua", "js", "sh" }, -- you can simply put filetype here
        filetype_details = { -- or, you can have more control here
            json = {}, -- empty table is fine
            ["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 = "edit", -- 'vsplit' | 'split' | 'edit' | 'tabedit' | 'rightbelow vsplit'
        use_telescope = true,
        localKeys = {
            {
                filenameContains = { "sh" },
                LocalKeys = {
                    {
                        cmd = "<CMD>RunShellCurrentLine<CR>",
                        key = "<C-r>",
                        modes = { "n", "i", "v" },
                    },
                },
            },
        },
    },
    event = "VeryLazy",
}

Commands & Keymapps

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

Command Description
Scratch Creates a new scratch file in the specified scratch_file_dir directory in your configuration.
ScratchWithName Allows the creation of a new scratch file with a user-specified filename, including the file extension.
ScratchOpen Opens an existing scratch file from the scratch_file_dir.
ScratchOpenFzf Uses 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


About

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

License:Other


Languages

Language:Lua 100.0%