mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 10:41:12 +01:00
Updated Neo-tree opening files in a new tab by pressing Enter but replacing an empty buffer by opening in the same tab, Added <leader>e to open an empty buffer in a new tab, fixed Neo-tree starting on left side if Neovim is opened inside a directory
This commit is contained in:
33
init.lua
33
init.lua
@@ -1,14 +1,6 @@
|
|||||||
vim.g.mapleader = ' '
|
vim.g.mapleader = ' '
|
||||||
vim.g.maplocalleader = ' '
|
vim.g.maplocalleader = ' '
|
||||||
|
|
||||||
--[[Open Neotree on new tab]]
|
|
||||||
--vim.gpi.nvim_create_autocmd("TabNewEntered", {
|
|
||||||
-- group = vim.api.nvim_create_augroup("NeotreeOnNewTab", { clear = true }),
|
|
||||||
-- callback = vim.schedule_wrap(function()
|
|
||||||
-- vim.cmd("Neotree show")
|
|
||||||
-- end),
|
|
||||||
--})
|
|
||||||
|
|
||||||
-- [[ Install `lazy.nvim` plugin manager ]]
|
-- [[ Install `lazy.nvim` plugin manager ]]
|
||||||
-- https://github.com/folke/lazy.nvim
|
-- https://github.com/folke/lazy.nvim
|
||||||
-- `:help lazy.nvim.txt` for more info
|
-- `:help lazy.nvim.txt` for more info
|
||||||
@@ -30,6 +22,18 @@ vim.opt.rtp:prepend(lazypath)
|
|||||||
-- You can configure plugins using the `config` key.
|
-- You can configure plugins using the `config` key.
|
||||||
-- You can also configure plugins after the setup call,
|
-- You can also configure plugins after the setup call,
|
||||||
-- as they will be available in your neovim runtime.
|
-- as they will be available in your neovim runtime.
|
||||||
|
|
||||||
|
-- Disables which-key healthcheck notifications
|
||||||
|
do
|
||||||
|
local orig_notify = vim.notify
|
||||||
|
vim.notify = function(msg, ...)
|
||||||
|
if type(msg) == "string" and msg:match("which%-key") then
|
||||||
|
return -- ignore WhichKey health messages
|
||||||
|
end
|
||||||
|
return orig_notify(msg, ...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
require('lazy').setup({
|
require('lazy').setup({
|
||||||
-- NOTE: First, some plugins that don't require any configuration
|
-- NOTE: First, some plugins that don't require any configuration
|
||||||
-- Git related plugins
|
-- Git related plugins
|
||||||
@@ -287,17 +291,23 @@ vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = tr
|
|||||||
-- Diagnostic keymaps
|
-- Diagnostic keymaps
|
||||||
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
|
||||||
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
|
||||||
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
|
--vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
|
||||||
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
|
--vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
|
||||||
|
|
||||||
--[[ Custom keymaps ]]
|
--[[ Custom keymaps ]]
|
||||||
|
|
||||||
--NeoTree sync to current directory & toggle
|
--Neo-tree sync to current directory & toggle
|
||||||
vim.keymap.set('n', '<leader>n', '<Cmd>cd %:p:h | Neotree toggle float<CR>')
|
vim.keymap.set('n', '<leader>n', '<Cmd>cd %:p:h | Neotree toggle float<CR>')
|
||||||
|
|
||||||
--Terminal open in new tab
|
--Terminal open in new tab
|
||||||
vim.keymap.set('n', '<leader>t', '<Cmd>tabnew +term<CR>i')
|
vim.keymap.set('n', '<leader>t', '<Cmd>tabnew +term<CR>i')
|
||||||
|
|
||||||
|
-- Create an empty buffer in a new tab
|
||||||
|
vim.keymap.set("n", "<Leader>e", function()
|
||||||
|
vim.cmd("tabnew") -- create a new tab
|
||||||
|
vim.cmd("enew") -- create a new empty buffer in it
|
||||||
|
end, { noremap = true, silent = true })
|
||||||
|
|
||||||
-- Save current buffer (asks for filename if new/unsaved)
|
-- Save current buffer (asks for filename if new/unsaved)
|
||||||
vim.keymap.set('n', '<leader>w', function()
|
vim.keymap.set('n', '<leader>w', function()
|
||||||
if vim.api.nvim_buf_get_name(0) == "" then
|
if vim.api.nvim_buf_get_name(0) == "" then
|
||||||
@@ -646,7 +656,6 @@ mason_lspconfig.setup {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-- [[ Configure nvim-cmp ]]
|
-- [[ Configure nvim-cmp ]]
|
||||||
-- See `:help cmp`
|
-- See `:help cmp`
|
||||||
local cmp = require 'cmp'
|
local cmp = require 'cmp'
|
||||||
|
|||||||
@@ -10,13 +10,77 @@ return {
|
|||||||
"MunifTanjim/nui.nvim",
|
"MunifTanjim/nui.nvim",
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
|
|
||||||
|
-- smart_open function: If there's an empty "No Name" buffer, replace it and open files in the same tab
|
||||||
|
local function smart_open(state)
|
||||||
|
local node = state.tree:get_node()
|
||||||
|
if not node then return end
|
||||||
|
local path = node:get_id()
|
||||||
|
|
||||||
|
-- Get the window in the current tab that is NOT Neo-tree
|
||||||
|
local wins = vim.api.nvim_tabpage_list_wins(0)
|
||||||
|
local target_buf = nil
|
||||||
|
for _, win in ipairs(wins) do
|
||||||
|
local buf = vim.api.nvim_win_get_buf(win)
|
||||||
|
local bufname = vim.api.nvim_buf_get_name(buf)
|
||||||
|
local buftype = vim.api.nvim_buf_get_option(buf, "buftype")
|
||||||
|
local modified = vim.api.nvim_buf_get_option(buf, "modified")
|
||||||
|
-- find a window with empty, unmodified buffer
|
||||||
|
if bufname == "" and buftype == "" and not modified then
|
||||||
|
target_buf = buf
|
||||||
|
vim.api.nvim_set_current_win(win)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if target_buf then
|
||||||
|
-- replace the empty buffer
|
||||||
|
vim.cmd("edit " .. path)
|
||||||
|
else
|
||||||
|
-- otherwise open in new tab
|
||||||
|
require("neo-tree.sources.filesystem.commands").open_tabnew(state)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
require('neo-tree').setup {
|
require('neo-tree').setup {
|
||||||
filesystem = {
|
-- Open Neo-tree in a floating window in middle at first launch when Neovim is opened inside a directory with "nvim ."
|
||||||
filtered_items = {
|
close_if_last_window = true, -- close Neo-tree if it's the last window
|
||||||
|
popup_border_style = "rounded",
|
||||||
|
enable_git_status = true,
|
||||||
|
enable_diagnostics = true,
|
||||||
|
default_component_configs = {
|
||||||
|
indent = {
|
||||||
|
padding = 1,
|
||||||
|
indent_size = 2,
|
||||||
|
},
|
||||||
|
icon = {
|
||||||
|
folder_closed = "",
|
||||||
|
folder_open = "",
|
||||||
|
folder_empty = "ﰊ",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
window = {
|
||||||
|
position = "float", -- this makes Neo-tree open in the middle
|
||||||
|
width = 40,
|
||||||
|
mapping_options = {
|
||||||
|
noremap = true,
|
||||||
|
nowait = true,
|
||||||
|
},
|
||||||
|
mappings = {
|
||||||
|
["<cr>"] = smart_open, -- Enter → always open file in new tab if there's no empty buffer
|
||||||
|
["t"] = "noop", -- disable t
|
||||||
|
},
|
||||||
|
},
|
||||||
|
filesystem = {
|
||||||
|
follow_current_file = true,
|
||||||
|
use_libuv_file_watcher = true,
|
||||||
|
hijack_netrw_behavior = "open_default",
|
||||||
|
filtered_items = {
|
||||||
visible = true, -- This is what you want: If you set this to `true`, all "hide" just mean "dimmed out"
|
visible = true, -- This is what you want: If you set this to `true`, all "hide" just mean "dimmed out"
|
||||||
hide_dotfiles = false,
|
hide_dotfiles = false,
|
||||||
hide_gitignored = true,
|
hide_gitignored = true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}, }
|
}
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user