Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cenk1cenk2/scratch.nvim
Create scratch buffers in Neovim.
https://github.com/cenk1cenk2/scratch.nvim
neovim-plugin nvim-plugin
Last synced: about 4 hours ago
JSON representation
Create scratch buffers in Neovim.
- Host: GitHub
- URL: https://github.com/cenk1cenk2/scratch.nvim
- Owner: cenk1cenk2
- License: mit
- Created: 2024-09-16T12:58:00.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-16T17:37:20.000Z (2 months ago)
- Last Synced: 2024-09-17T17:07:24.959Z (2 months ago)
- Topics: neovim-plugin, nvim-plugin
- Language: Lua
- Homepage:
- Size: 32.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# scratch.nvim
Create scratch buffers in Neovim.
## Features
- Create scratch buffers in a given filetype.
- Uses autocommands instead of `wipe` to close scratch buffers, so you can execute commands while the buffer is open.
- Execute the given file quickly.## Installation
### `lazy.nvim`
```lua
{
"cenk1cenk2/scratch.nvim",
}
```## Configuration
### Setup
Plugin requires no setup by default. However if you want to change the default settings for good, then you can call it.
```lua
require("scratch").setup({
-- your custom configuration
})
```You can find the default configuration file and available options [here](https://github.com/cenk1cenk2/scratch.nvim/blob/main/lua/scratch/config.lua).
## Usage
You can assign the following commands to keybindings.
### Create a Scratch Buffer
Trigger a `vim.ui.select` to create a scratch buffer of selected type. The default behavior is to create the file in your current working directory.
```lua
require("scratch").create()
```To skip the prompt and create a scratch buffer of a specific type, you can pass the filetype as an argument.
```lua
require("scratch").create({ filetype = "lua" })
```If you do not want to create the buffer in your current directory, you can set it to use a temporary file.
```lua
require("scratch").create({ cwd = false })
```If you want to use a specific relative directory to your current working directory, you can set it to use a relative directory.
```lua
require("scratch").create({ cwd = "relative/path" })
```### Execute a Scratch Buffer
Trigger a `vim.ui.input` to execute a scratch buffer.
This command does not do much on its own, but you can combine it with other plugins to make sense.
An example usage with `toggleterm.nvim` is as follows.
```lua
require("scratch").execute(function(opts)
-- callback arguments (opts) would be:
---@field filename string
---@field path string
---@field bufnr number
---@field command stringlocal Terminal = require("toggleterm.terminal").Terminal
local terminal = Terminal.create_terminal({
cmd = ("%s -c '%s %s'"):format(vim.o.shell, opts.command, opts.path),
close_on_exit = false,
dir = vim.uv.cwd(),
}):open()
end)
```