Replace nvim-tree with drex.nvim for vim-vinegar replacement

This commit is contained in:
Tyler Hallada 2023-12-01 15:26:00 -05:00
parent a7dcacdd91
commit 75dacaf7bc
4 changed files with 67 additions and 14 deletions

View File

@ -390,6 +390,13 @@ return require('packer').startup(function(use)
require('plugins.rest-nvim') require('plugins.rest-nvim')
end, end,
} }
use {
'theblob42/drex.nvim',
requires = 'kyazdani42/nvim-web-devicons',
config = function()
require('plugins.drex-nvim')
end,
}
use { use {
'folke/which-key.nvim', 'folke/which-key.nvim',
config = function() config = function()

44
lua/plugins/drex-nvim.lua Normal file
View File

@ -0,0 +1,44 @@
local drex = require('drex')
local elements = require('drex.elements')
-- open the home directory
vim.keymap.set('n', '~', '<CMD>Drex ~<CR>', {})
-- 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'] = {
['~'] = '<CMD>Drex ~<CR>',
['-'] = '<CMD>lua require("drex.elements").open_parent_directory()<CR>',
['.'] = function()
local element = require('drex.utils').get_element(vim.api.nvim_get_current_line())
local left = vim.api.nvim_replace_termcodes('<left>', true, false, true)
vim.api.nvim_feedkeys(': ' .. element .. string.rep(left, #element + 1), 'n', true)
end,
['<CR>'] = 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,
})

View File

@ -1,4 +1,5 @@
require('lualine').setup({ require('lualine').setup({
extensions = { 'drex' },
sections = { sections = {
lualine_c = { lualine_c = {
require('auto-session-library').current_session_name, require('auto-session-library').current_session_name,

View File

@ -1,9 +1,9 @@
require('nvim-tree').setup({ require('nvim-tree').setup({
hijack_netrw = true, -- hijack_netrw = true,
hijack_directories = { -- hijack_directories = {
enable = true, -- enable = true,
auto_open = true, -- auto_open = true,
}, -- },
view = { view = {
mappings = { mappings = {
list = { list = {
@ -17,14 +17,15 @@ require('nvim-tree').setup({
}, },
}) })
local function toggle_replace() -- local function toggle_replace()
local view = require('nvim-tree.view') -- local view = require('nvim-tree.view')
if view.is_visible() then -- if view.is_visible() then
view.close() -- view.close()
else -- else
require('nvim-tree').open_replacing_current_buffer() -- require('nvim-tree').open_replacing_current_buffer()
end -- end
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', '<leader>n', [[<Cmd>NvimTreeToggle<CR>]], { noremap = true, silent = true }) vim.keymap.set('n', '<leader>n', [[<Cmd>NvimTreeToggle<CR>]], { noremap = true, silent = true })