feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706)
## Description LazyVim comes with a bunch of smaller QoL plugin like features, but it's not easy for non LazyVim users to use them. That's why I started working on [snacks.nvim](https://github.com/folke/snacks.nvim), a collection of small QoL plugins for Neovim. Snacks also includes a bunch of new improvements to these features. This PR fully integrates with snacks. ## Todo - [ ] add proper deprecations where needed - [ ] create snacks docs - [ ] document all the new improvements relevant to LazyVim users ## Closes - [ ] #4492 - [ ] #4333 - [ ] #4687 ## Screenshots <!-- Add screenshots of the changes if applicable. --> ## Checklist - [ ] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines.
This commit is contained in:
@ -1,13 +1,5 @@
|
||||
---@class lazyvim.util.terminal
|
||||
---@overload fun(cmd: string|string[], opts: LazyTermOpts): LazyFloat
|
||||
local M = setmetatable({}, {
|
||||
__call = function(m, ...)
|
||||
return m.open(...)
|
||||
end,
|
||||
})
|
||||
|
||||
---@type table<string,LazyFloat>
|
||||
local terminals = {}
|
||||
local M = {}
|
||||
|
||||
---@param shell? string
|
||||
function M.setup(shell)
|
||||
@ -40,58 +32,4 @@ function M.setup(shell)
|
||||
end
|
||||
end
|
||||
|
||||
---@class LazyTermOpts: LazyCmdOptions
|
||||
---@field interactive? boolean
|
||||
---@field esc_esc? boolean
|
||||
---@field ctrl_hjkl? boolean
|
||||
|
||||
-- Opens a floating terminal (interactive by default)
|
||||
---@param cmd? string[]|string
|
||||
---@param opts? LazyTermOpts
|
||||
function M.open(cmd, opts)
|
||||
opts = vim.tbl_deep_extend("force", {
|
||||
ft = "lazyterm",
|
||||
size = { width = 0.9, height = 0.9 },
|
||||
backdrop = LazyVim.has("edgy.nvim") and not cmd and 100 or nil,
|
||||
}, opts or {}, { persistent = true }) --[[@as LazyTermOpts]]
|
||||
|
||||
local termkey = vim.inspect({ cmd = cmd or "shell", cwd = opts.cwd, env = opts.env, count = vim.v.count1 })
|
||||
|
||||
if terminals[termkey] and terminals[termkey]:buf_valid() then
|
||||
terminals[termkey]:toggle()
|
||||
else
|
||||
terminals[termkey] = require("lazy.util").float_term(cmd, opts)
|
||||
local buf = terminals[termkey].buf
|
||||
vim.b[buf].lazyterm_cmd = cmd
|
||||
if opts.esc_esc == false then
|
||||
vim.keymap.set("t", "<esc>", "<esc>", { buffer = buf, nowait = true })
|
||||
end
|
||||
if opts.ctrl_hjkl == false then
|
||||
vim.keymap.set("t", "<c-h>", "<c-h>", { buffer = buf, nowait = true })
|
||||
vim.keymap.set("t", "<c-j>", "<c-j>", { buffer = buf, nowait = true })
|
||||
vim.keymap.set("t", "<c-k>", "<c-k>", { buffer = buf, nowait = true })
|
||||
vim.keymap.set("t", "<c-l>", "<c-l>", { buffer = buf, nowait = true })
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "gf", function()
|
||||
local f = vim.fn.findfile(vim.fn.expand("<cfile>"))
|
||||
if f ~= "" then
|
||||
vim.cmd("close")
|
||||
vim.cmd("e " .. f)
|
||||
end
|
||||
end, { buffer = buf })
|
||||
|
||||
vim.api.nvim_create_autocmd("BufEnter", {
|
||||
buffer = buf,
|
||||
callback = function()
|
||||
vim.cmd.startinsert()
|
||||
end,
|
||||
})
|
||||
|
||||
vim.cmd("noh")
|
||||
end
|
||||
|
||||
return terminals[termkey]
|
||||
end
|
||||
|
||||
return M
|
||||
|
Reference in New Issue
Block a user