From 75dacaf7bcd0b94838e6f803005a523eb7faf4ad Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Fri, 1 Dec 2023 15:26:00 -0500 Subject: [PATCH] Replace nvim-tree with drex.nvim for vim-vinegar replacement --- lua/install-plugins.lua | 7 ++++++ lua/plugins/drex-nvim.lua | 44 ++++++++++++++++++++++++++++++++++++ lua/plugins/lualine-nvim.lua | 1 + lua/plugins/nvim-tree.lua | 29 ++++++++++++------------ 4 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 lua/plugins/drex-nvim.lua diff --git a/lua/install-plugins.lua b/lua/install-plugins.lua index d740c12..d5f0bab 100644 --- a/lua/install-plugins.lua +++ b/lua/install-plugins.lua @@ -390,6 +390,13 @@ return require('packer').startup(function(use) require('plugins.rest-nvim') end, } + use { + 'theblob42/drex.nvim', + requires = 'kyazdani42/nvim-web-devicons', + config = function() + require('plugins.drex-nvim') + end, + } use { 'folke/which-key.nvim', config = function() diff --git a/lua/plugins/drex-nvim.lua b/lua/plugins/drex-nvim.lua new file mode 100644 index 0000000..1bf3f9b --- /dev/null +++ b/lua/plugins/drex-nvim.lua @@ -0,0 +1,44 @@ +local drex = require('drex') +local elements = require('drex.elements') + +-- open the home directory +vim.keymap.set('n', '~', 'Drex ~', {}) +-- open parent DREX buffer and focus current file +vim.keymap.set('n', '-', function() + local path = vim.fn.expand('%:p') + if path == '' then + drex.open_directory_buffer() -- open at cwd + else + drex.open_directory_buffer(vim.fn.fnamemodify(path, ':h')) + elements.focus_element(0, path) + end +end, {}) + +require('drex.config').configure({ + hijack_netrw = true, + keybindings = { + ['n'] = { + ['~'] = 'Drex ~', + ['-'] = 'lua require("drex.elements").open_parent_directory()', + ['.'] = function() + local element = require('drex.utils').get_element(vim.api.nvim_get_current_line()) + local left = vim.api.nvim_replace_termcodes('', true, false, true) + vim.api.nvim_feedkeys(': ' .. element .. string.rep(left, #element + 1), 'n', true) + end, + [''] = function() + local line = vim.api.nvim_get_current_line() + + if require('drex.utils').is_open_directory(line) then + elements.collapse_directory() + else + elements.expand_element() + end + end, + } + }, + on_enter = function() + vim.opt_local.number = false + vim.opt_local.relativenumber = false + vim.opt_local.signcolumn = 'no' + end, +}) diff --git a/lua/plugins/lualine-nvim.lua b/lua/plugins/lualine-nvim.lua index 012e269..3b56aba 100644 --- a/lua/plugins/lualine-nvim.lua +++ b/lua/plugins/lualine-nvim.lua @@ -1,4 +1,5 @@ require('lualine').setup({ + extensions = { 'drex' }, sections = { lualine_c = { require('auto-session-library').current_session_name, diff --git a/lua/plugins/nvim-tree.lua b/lua/plugins/nvim-tree.lua index d193eec..71eb744 100644 --- a/lua/plugins/nvim-tree.lua +++ b/lua/plugins/nvim-tree.lua @@ -1,9 +1,9 @@ require('nvim-tree').setup({ - hijack_netrw = true, - hijack_directories = { - enable = true, - auto_open = true, - }, + -- hijack_netrw = true, + -- hijack_directories = { + -- enable = true, + -- auto_open = true, + -- }, view = { mappings = { list = { @@ -17,14 +17,15 @@ require('nvim-tree').setup({ }, }) -local function toggle_replace() - local view = require('nvim-tree.view') - if view.is_visible() then - view.close() - else - require('nvim-tree').open_replacing_current_buffer() - end -end +-- local function toggle_replace() +-- local view = require('nvim-tree.view') +-- if view.is_visible() then +-- view.close() +-- else +-- require('nvim-tree').open_replacing_current_buffer() +-- end +-- end -vim.keymap.set('n', '-', function() toggle_replace() end, { noremap = true, silent = true }) +-- swapping this out with drex.nvim instead +-- vim.keymap.set('n', '-', function() toggle_replace() end, { noremap = true, silent = true }) vim.keymap.set('n', 'n', [[NvimTreeToggle]], { noremap = true, silent = true })