aboutsummaryrefslogtreecommitdiffstats
path: root/neovim/.config/nvim/lua/plugins/filetree.lua
blob: cdee9f7bbbed3f99e5a51c2aef73530fd10a6a63 (plain)
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
return {
  "preservim/nerdtree",
  lazy = false,
  config = function()
    -- Open NERDTree when no file is specified; quit when it's the last window
    local augroup = vim.api.nvim_create_augroup("nerdtree_auto", { clear = true })

    vim.api.nvim_create_autocmd("StdinReadPre", {
      group = augroup,
      callback = function()
        vim.g.std_in = 1
      end,
    })

    vim.api.nvim_create_autocmd("VimEnter", {
      group = augroup,
      callback = function()
        if vim.fn.argc() == 0 and vim.g.std_in == nil then
          vim.cmd("NERDTree")
        end
      end,
    })

    vim.api.nvim_create_autocmd("BufEnter", {
      group = augroup,
      callback = function()
        if vim.fn.winnr("$") == 1 and vim.bo.filetype == "nerdtree" then
          vim.cmd("quit")
        end
      end,
    })
  end,
}