From 71074dd17195c63a9da3adc60dc1af58b73691a4 Mon Sep 17 00:00:00 2001 From: Micah Effiong Date: Thu, 8 Jun 2023 01:03:05 +0100 Subject: [PATCH] added nvim-tree and setup keymap to toggle file-browser --- init.lua | 9 +++++++- lua/custom/init.lua | 2 ++ lua/custom/keymaps/init.lua | 12 ++++++++++ lua/custom/plugins/nvim-tree.lua | 39 ++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 lua/custom/init.lua create mode 100644 lua/custom/keymaps/init.lua create mode 100644 lua/custom/plugins/nvim-tree.lua diff --git a/init.lua b/init.lua index d5b7f4d2..da2950bd 100644 --- a/init.lua +++ b/init.lua @@ -41,6 +41,13 @@ P.S. You can delete this when you're done too. It's your config now :) vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' +-- disable netrw at the very start of your init.lua +-- needed for nvim-tree +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +-- vim.o.guifont = 'Inconsolata LGC Nerd Font' + -- Install package manager -- https://github.com/folke/lazy.nvim -- `:help lazy.nvim.txt` for more info @@ -513,7 +520,7 @@ cmp.setup { } -- custom settings -pcall(require('custom.options')) +pcall(require('custom')) -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/custom/init.lua b/lua/custom/init.lua new file mode 100644 index 00000000..00d3f769 --- /dev/null +++ b/lua/custom/init.lua @@ -0,0 +1,2 @@ +require 'custom.keymaps' +require 'custom.options' diff --git a/lua/custom/keymaps/init.lua b/lua/custom/keymaps/init.lua new file mode 100644 index 00000000..53a01a9c --- /dev/null +++ b/lua/custom/keymaps/init.lua @@ -0,0 +1,12 @@ +-- toggle nvim tree +vim.keymap.set( + 'n', + '', + require('nvim-tree.api').tree.toggle, + { + desc = 'nvim-tree: Toggle tree', + noremap = true, + silent = true, + nowait = true + } +) diff --git a/lua/custom/plugins/nvim-tree.lua b/lua/custom/plugins/nvim-tree.lua new file mode 100644 index 00000000..119de2e6 --- /dev/null +++ b/lua/custom/plugins/nvim-tree.lua @@ -0,0 +1,39 @@ +-- NVIM tree +-- a file explore plugin + +local function on_nvim_tree_attach(bufnr) + local api = require("nvim-tree.api") + + local function opts(desc) + return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + + -- default mappings + api.config.mappings.default_on_attach(bufnr) + + -- custom mappings + -- vim.keymap.set('n', '', api.tree.change_root_to_parent, opts('Up')) + -- vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help')) + vim.keymap.set('n', '', api.tree.toggle, opts('Toggle tree')) +end + +return { + "nvim-tree/nvim-tree.lua", + version = "*", + -- + -- after = "nvim-web-devicons", + -- requires = "nvim-tree/nvim-web-devicons", + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + config = function() + require("nvim-tree").setup { + update_cwd = true, + update_focused_file = { + enable = true + }, + respect_buf_cwd = true, + on_attach = on_nvim_tree_attach, + } + end, +}