Change so that oil nvim opens as a static window to the left of the terminal, much like a typical solution explorer
This commit is contained in:
parent
e4ba277522
commit
c866d90c88
1 changed files with 45 additions and 3 deletions
|
|
@ -1,15 +1,57 @@
|
|||
local function get_oil_bufnr()
|
||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if vim.bo[buf].filetype == "oil" then
|
||||
return buf
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
return {
|
||||
"stevearc/oil.nvim",
|
||||
config = function()
|
||||
local oil = require("oil")
|
||||
oil.setup()
|
||||
oil.setup({
|
||||
view_options = {
|
||||
show_hidden = true,
|
||||
},
|
||||
win_options = {
|
||||
wrap = true,
|
||||
signcolumn = "no",
|
||||
cursorcolumn = false,
|
||||
foldcolumn = "0",
|
||||
spell = false,
|
||||
list = false,
|
||||
conceallevel = 3,
|
||||
concealcursor = "nvic",
|
||||
},
|
||||
})
|
||||
|
||||
require("utils").add_keymaps({
|
||||
n = {
|
||||
["<leader>o"] = {
|
||||
cmd = function()
|
||||
oil.toggle_float(vim.fn.getcwd())
|
||||
end,
|
||||
local oil_bufnr = get_oil_bufnr()
|
||||
if oil_bufnr then
|
||||
vim.api.nvim_buf_delete(oil_bufnr, { force = true })
|
||||
return
|
||||
end
|
||||
|
||||
-- Calculate the desired width (e.g., 20% of the terminal width)
|
||||
local term_width = vim.api.nvim_get_option("columns")
|
||||
local width_percentage = 0.175
|
||||
local min_width = 30
|
||||
local max_width = 50
|
||||
local calculated_width = math.floor(term_width * width_percentage)
|
||||
local final_width = math.min(math.max(calculated_width, min_width), max_width)
|
||||
|
||||
-- Open a vertical split with the calculated width on the left and open oil.nvim
|
||||
vim.cmd("topleft vertical " .. final_width .. "vnew")
|
||||
local win_id = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_win_set_option(win_id, "winfixwidth", true)
|
||||
oil.open()
|
||||
end
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue