Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/notomo/waitevent.nvim
Neovim plugin to avoid nested nvim
https://github.com/notomo/waitevent.nvim
neovim neovim-plugin
Last synced: 12 days ago
JSON representation
Neovim plugin to avoid nested nvim
- Host: GitHub
- URL: https://github.com/notomo/waitevent.nvim
- Owner: notomo
- License: mit
- Created: 2023-02-14T13:42:23.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-09T05:16:12.000Z (about 1 year ago)
- Last Synced: 2023-10-09T06:25:52.883Z (about 1 year ago)
- Topics: neovim, neovim-plugin
- Language: Lua
- Homepage:
- Size: 62.5 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-neovim-pluginlist - notomo/waitevent.nvim - commit/notomo/waitevent.nvim) ![](https://img.shields.io/github/commit-activity/y/notomo/waitevent.nvim) (New features / EDITOR)
README
# waitevent.nvim
This plugin provides the way to avoid nested nvim.
## Requirements
- Neovim nightly. This plugin uses `nvim -ll {script}`.
## Example
```lua
-- Use for git command editor.
-- This editor finishes the process on save or close.
vim.env.GIT_EDITOR = require("waitevent").editor({
open = function(ctx, path)
vim.cmd.split(path)
ctx.lcd()
vim.bo.bufhidden = "wipe"
end,
})-- Use for `nvim {file_path}` in :terminal.
-- This editor finishes the process as soon as open.
-- The fowllowing shell settings is convinient (optional).
-- `export EDITOR=nvim` in .bash_profile
-- `alias nvim="${EDITOR}"` in .bashrc
vim.env.EDITOR = require("waitevent").editor({
done_events = {},
cancel_events = {},
})-- all default options
local default = {
open = function(ctx, ...)
local paths = { ... }
for _, path in ipairs(paths) do
vim.cmd.tabedit(path)
ctx.tcd()
vim.bo.bufhidden = "wipe"
end
if #paths == 0 then
vim.cmd.tabedit()
ctx.tcd()
vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.split(ctx.stdin, "\n", { plain = true }))
vim.bo.modified = false
vim.bo.bufhidden = "wipe"
end
if ctx.row then
local row = math.min(ctx.row, vim.api.nvim_buf_line_count(0))
vim.api.nvim_win_set_cursor(0, { row, 0 })
end
end,done_events = {
"BufWritePost",
},
on_done = function(ctx)
if vim.api.nvim_win_is_valid(ctx.window_id_after_open) and #vim.api.nvim_list_wins() > 1 then
vim.api.nvim_win_close(ctx.window_id_after_open, true)
end
if not vim.api.nvim_win_is_valid(ctx.window_id_before_open) then
return
end
vim.api.nvim_set_current_win(ctx.window_id_before_open)
end,cancel_events = {
"BufUnload",
"BufDelete",
"BufWipeout",
},
on_canceled = function(ctx)
if not vim.api.nvim_win_is_valid(ctx.window_id_before_open) then
return
end
vim.api.nvim_set_current_win(ctx.window_id_before_open)
end,
}
require("waitevent").editor(default)
```