Skip to content

Instantly share code, notes, and snippets.

@mhartington
Created March 15, 2025 23:44
Show Gist options
  • Save mhartington/867f924044449c8d52b02ae50e2c8704 to your computer and use it in GitHub Desktop.
Save mhartington/867f924044449c8d52b02ae50e2c8704 to your computer and use it in GitHub Desktop.
local function save_opts()
original_opts = vim.o
end
local function hide_stuff()
vim.o.fillchars = "stl: ,stlnc: ,vert: ,diff: ,msgsep: ,eob: ,horiz: ,horizup: ,horizdown: "
vim.o.number = false
vim.o.relativenumber = false
vim.o.showtabline=0
end
local function resize_pads()
local ui = vim.api.nvim_list_uis()[1]
local width = ui.width
local height = ui.height
local padding_width = math.floor((width / 2 ) / 2)
for pos, id in pairs(vim.t.padding) do
if pos == "l" or pos == "r" then
api.nvim_win_set_width(vim.t.padding[pos].winId, padding_width)
end
if pos == "t" or pos == "b" then
api.nvim_win_set_height(vim.t.padding[pos].winId, 0)
end
end
end
local function init_pad(command)
vim.cmd(command)
vim.bo.buftype = "nofile"
vim.bo.bufhidden = "wipe"
vim.bo.modifiable = false
vim.bo.buflisted = false
vim.bo.swapfile = false
vim.wo.number = false
vim.wo.relativenumber = false
vim.wo.cursorline = false
vim.wo.cursorcolumn = false
vim.wo.winfixwidth = true
vim.wo.winfixheight = true
vim.wo.statusline = ""
local bufnr = api.nvim_get_current_buf()
local winId = api.nvim_get_current_win()
vim.api.nvim_create_autocmd({ "CursorMoved", "WinEnter" }, {
buffer = bufnr,
nested = true,
callback = function(ev)
vim.api.nvim_set_current_win(vim.t.main.winId)
end,
})
vim.api.nvim_set_current_win(vim.t.main.winId)
return {winId = winId, bufnr=bufnr}
end
local function toggle_off()
vim.o = original_opts
vim.cmd("tabclose")
end
local function toggle_on()
save_opts()
local origina_tab = vim.fn.tabpagenr()
vim.cmd("tab split")
vim.t.main = {
bufnr = api.nvim_get_current_buf(),
winId = api.nvim_get_current_win(),
}
vim.t.padding = {
l = init_pad("vertical topleft new"),
r = init_pad("vertical botright new"),
t = init_pad("topleft new"),
b = init_pad("botright new"),
}
resize_pads()
hide_stuff()
end
vim.api.nvim_create_user_command("Zen", function()
if vim.g.zen_enabled then
toggle_off()
vim.g.zen_enabled = false
else
toggle_on()
vim.g.zen_enabled = true
end
end, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment