This commit is contained in:
Ray Elliott 2026-07-07 01:02:07 +01:00
commit b1967bc6a1
7 changed files with 89 additions and 1 deletions

View file

@ -1,4 +1,46 @@
local map = vim.keymap.set
local last_file_buf
local previous_file_buf
local function is_real_file_buffer(buf)
return vim.api.nvim_buf_is_valid(buf)
and vim.bo[buf].buflisted
and vim.bo[buf].buftype == ''
and vim.bo[buf].filetype ~= 'netrw'
and vim.api.nvim_buf_get_name(buf) ~= ''
end
local function is_netrw_buffer(buf)
if not vim.api.nvim_buf_is_valid(buf) then
return false
end
return vim.bo[buf].filetype == 'netrw' or vim.api.nvim_buf_get_name(buf):match('NetrwTreeListing$') ~= nil
end
local function switch_to_buffer(buf)
vim.cmd('buffer ' .. buf)
end
local function switch_to_native_alternate()
pcall(vim.cmd, 'buffer #')
end
local function jump_to_alternate_file()
local alternate = vim.fn.bufnr('#')
if is_real_file_buffer(alternate) then
switch_to_buffer(alternate)
return
end
if is_netrw_buffer(alternate) and is_real_file_buffer(previous_file_buf) then
switch_to_buffer(previous_file_buf)
return
end
switch_to_native_alternate()
end
-- Netrw configuration for file browsing
-- Native Neovim file explorer (no plugins required)
@ -56,10 +98,28 @@ end, { desc = 'Netrw: Tab at project root', silent = true })
map('n', '<leader>nr', function()
vim.cmd('Explore ' .. vim.fn.fnameescape(vim.g.project_root))
end, { desc = 'Netrw: Open at project root', silent = true })
map('n', '<C-6>', jump_to_alternate_file, { desc = 'Buffer: Alternate file skipping netrw', silent = true })
map('n', '<C-^>', jump_to_alternate_file, { desc = 'Buffer: Alternate file skipping netrw', silent = true })
vim.api.nvim_create_autocmd('BufEnter', {
desc = 'Track recent real file buffers for alternate-buffer jumps',
callback = function(args)
local buf = args.buf
if is_real_file_buffer(buf) and buf ~= last_file_buf then
previous_file_buf = last_file_buf
last_file_buf = buf
end
end,
})
-- Enable line numbers in netrw buffers
vim.api.nvim_create_autocmd('FileType', {
pattern = 'netrw',
desc = 'Configure netrw buffer-local options',
callback = function()
vim.bo.buflisted = false
vim.opt_local.number = true
vim.opt_local.relativenumber = true
end,

View file

@ -93,6 +93,10 @@ return {
configure("bashls")
configure("marksman")
configure("intelephense", {
init_options = {
storagePath = vim.fn.stdpath("cache") .. "/intelephense",
globalStoragePath = vim.fn.stdpath("data") .. "/intelephense",
},
single_file_support = false,
})