Created
July 23, 2024 01:18
-
-
Save towry/41ff484a898c81a8ca23b644d7e513ef to your computer and use it in GitHub Desktop.
use neo-tree buffers to switch buffers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- depends: folke/flash.nvim | |
return { | |
"nvim-neo-tree/neo-tree.nvim", | |
opts = { | |
sources = { "filesystem", "buffers" }, | |
source_selector = { | |
sources = { | |
{ source = "filesystem", display_name = " File" }, | |
{ source = "buffers", display_name = " Buffers" }, | |
}, | |
}, | |
event_handlers = { | |
{ | |
event = "neo_tree_window_after_open", | |
handler = function(args) | |
vim.cmd([[setlocal number]]) | |
if args.source == "buffers" then | |
vim.cmd([[hi link NeoTreeDirectoryName NeoTreeDimText]]) | |
vim.cmd([[hi link NeoTreeDirectoryIcon NeoTreeDimText]]) | |
else | |
vim.cmd([[hi clear NeoTreeDirectoryName]]) | |
vim.cmd([[hi clear NeoTreeDirectoryIcon]]) | |
end | |
end, | |
}, | |
}, | |
window = { | |
popup = { -- settings that apply to float position only | |
size = { | |
height = "60%", | |
width = "70%", | |
}, | |
position = "50%", -- 50% means center it | |
-- you can also specify border here, if you want a different setting from | |
-- the global popup_border_style. | |
}, | |
}, | |
commands = { | |
reveal_node_in_tree = function(state) | |
local node = state.tree:get_node() | |
if (node.type == "directory" or node:has_children()) and node:is_expanded() then return end | |
require("neo-tree.command").execute({ | |
source = "filesystem", | |
position = state.current_position, | |
action = "focus", | |
reveal_file = node.path, | |
}) | |
end | |
flash_jump = function() | |
require("flash").jump({ | |
search = { | |
mode = "search", | |
max_length = 0, | |
exclude = { | |
function(win) return vim.bo[vim.api.nvim_win_get_buf(win)].filetype ~= "neo-tree" end, | |
}, | |
}, | |
label = { | |
after = { 0, 1 }, | |
before = false, | |
style = "overlay", | |
reuse = "all", | |
}, | |
pattern = "\\.[a-z0-9]\\+\\s#\\d\\+\\s", | |
action = function(match, state) | |
vim.api.nvim_win_call(match.win, function() vim.api.nvim_win_set_cursor(match.win, { match.pos[1], 0 }) end) | |
state:restore() | |
end, | |
highlight = { | |
backdrop = false, | |
matches = false, | |
groups = { | |
match = "DiffAdd", | |
current = "DiffAdd", | |
label = "DiffAdd", | |
}, | |
}, | |
}) | |
end, | |
flash_jump_open = function(tree_state) | |
require("flash").jump({ | |
labels = "asdfghjklwertyuiopzxcvbnm1234567890", | |
search = { | |
mode = "search", | |
max_length = 0, | |
exclude = { | |
function(win) return vim.bo[vim.api.nvim_win_get_buf(win)].filetype ~= "neo-tree" end, | |
}, | |
}, | |
label = { | |
after = { 0, 1 }, | |
before = false, | |
style = "overlay", | |
reuse = "lowercase", | |
}, | |
action = function(match, state) | |
state:restore() | |
vim.schedule(function() | |
if not vim.api.nvim_win_is_valid(match.win) then return end | |
vim.api.nvim_win_call(match.win, function() | |
vim.api.nvim_win_set_cursor(match.win, { match.pos[1], 0 }) | |
---@diagnostic disable-next-line: missing-parameter | |
require("neo-tree.sources.common.commands").open(tree_state) | |
end) | |
end) | |
end, | |
pattern = "\\.[a-z0-9]\\+\\s#\\d\\+\\s", | |
highlight = { | |
backdrop = false, | |
matches = false, | |
groups = { | |
match = "DiffDelete", | |
current = "DiffDelete", | |
label = "DiffDelete", | |
}, | |
}, | |
}) | |
end, | |
}, | |
filesystem = { | |
window = { | |
mappings = { | |
["V"] = "open_vsplit", | |
}, | |
}, | |
}, | |
buffers = { | |
group_empty_dirs = true, -- when true, empty directories will be grouped together | |
window = { | |
mappings = { | |
["<esc>"] = false, | |
["s"] = "flash_jump", | |
["-"] = "flash_jump_open", | |
["e"] = { "reveal_node_in_tree", desc = "Reveal node in tree", nowait = true }, | |
}, | |
}, | |
}, | |
}, | |
keys = { | |
{ | |
"-", | |
"<cmd>Neotree source=buffers float reveal action=focus<cr>", | |
desc = "Open buffers", | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment