From 273545e803d66b626eeec19ec225c336957c23f1 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sun, 24 Sep 2023 06:08:11 -0400 Subject: Update 3 to my nvim config --- lua/ben/core/init.lua | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'lua/ben/core/init.lua') diff --git a/lua/ben/core/init.lua b/lua/ben/core/init.lua index e5bb0a2..5d8b7b0 100644 --- a/lua/ben/core/init.lua +++ b/lua/ben/core/init.lua @@ -6,12 +6,6 @@ vim.g.mapleader = ";" -- Space is quicker than Shift+Semicolon vim.keymap.set("n", "", ":") --- fm -> File Manager -vim.keymap.set("n", "fm", "Exp") - --- Tree View for the netrw File Manager -vim.g.netrw_liststyle = 3 - -- Set encoding to UTF-8 vim.opt.encoding = "utf-8" @@ -74,3 +68,38 @@ vim.api.nvim_set_keymap("n", "w", ":update", { silent = true }) -- Remove trailing white spaces on BufWritePre vim.cmd([[autocmd BufWritePre * %s/\s\+$//e]]) + +-- Tree View for the netrw File Manager +vim.g.netrw_liststyle = 3 +vim.g.netrw_banner = 0 +-- If nvim is opened with no arguments, open the netrw file manager +local mygroup = vim.api.nvim_create_augroup("loading_netrwPlugin", { clear = true }) +vim.api.nvim_create_autocmd({ "VimEnter" }, { + pattern = { "*" }, + callback = function() + -- Getting the file name that you pass when you launch nvim, + local current_file = vim.fn.expand("%") + -- if we have already file_name, then, we edit it + if current_file ~= "" then + vim.cmd(":silent! edit " .. current_file) + else + -- We will check if the window (buffer) is the lazy nvim, as it conflict if the buffer (popup menu) is lazy + local lazy_popup_buf_exists = false + -- We will get list of all current opened buffers + local buf_list = vim.api.nvim_list_bufs() + for _, buf in ipairs(buf_list) do + -- We will obtain from the table only the filetype + local buf_ft = vim.api.nvim_buf_get_option(buf, "filetype") + if buf_ft == "lazy" then + lazy_popup_buf_exists = true + end + end -- Check if vim-floaterm is loaded + local has_floaterm, _ = pcall(require, "floaterm") + if not lazy_popup_buf_exists and not has_floaterm then + -- Then we can safely loading netrwPlugin at startup + vim.cmd(":silent! Explore") + end + end + end, + group = mygroup, +}) -- cgit v1.2.3