aboutsummaryrefslogtreecommitdiffstats
path: root/nvim/lua/plugins/oil.lua
blob: 9a2ca218235889c83948ff6fe4fdacd3b9f95f79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
local oil_winnr = nil
return {
    'stevearc/oil.nvim',
    lazy = false,
    dependencies = 'nvim-tree/nvim-web-devicons',
    opts = {
        default_file_explorer = true,
    },
    keys = { {
        "<leader>ef",
        function()
            if not oil_winnr or not vim.api.nvim_win_is_valid(oil_winnr) then
                vim.cmd("topleft vsplit +Oil")
                oil_winnr = vim.api.nvim_get_current_win()
                return
            end

            local focused_win = vim.api.nvim_get_current_win() == oil_winnr
            local correct_type = vim.bo[vim.api.nvim_win_get_buf(oil_winnr)].ft == "oil"

            if focused_win and correct_type then
                vim.api.nvim_win_close(oil_winnr, false)
                oil_winnr = nil
            elseif not correct_type then
                vim.cmd("topleft vsplit +Oil")
                oil_winnr = vim.api.nvim_get_current_win()
            else
                vim.api.nvim_set_current_win(oil_winnr)
            end
        end,
        desc = "Toggle Oil file explorer in a far left split, similar to :Lexplore"
    } },
    cmd = "Oil"
}