diff --git a/lua/custom/keymaps/files.lua b/lua/custom/keymaps/files.lua index 0c6a68b..ebb24a5 100644 --- a/lua/custom/keymaps/files.lua +++ b/lua/custom/keymaps/files.lua @@ -2,13 +2,13 @@ -- local wk = require 'which-key' -local neotree_utils = require 'custom.plugins.neotree' +local neotree_helper = require 'custom.plugins.neotree-helper' local bufremove = require 'mini.bufremove' wk.add { mode = { 'n', 'v' }, { 'F', group = 'Fichier' }, -- group - { 'Fe', neotree_utils.smart_open, desc = 'Parcourir fichiers' }, + { 'Fe', neotree_helper.smart_open, desc = 'Parcourir fichiers' }, { 'Fc', bufremove.delete, desc = 'Fermer buffer', silent = true }, { 'Fr', 'source %', desc = 'Recharger buffer', silent = true }, { 'Fs', 'w', desc = 'Sauver buffer', silent = true }, @@ -19,7 +19,7 @@ wk.add { { '', 'source %', desc = 'Recharger buffer', silent = true, hidden = true }, { '', 'w', desc = 'Sauver buffer', silent = true, hidden = true }, { '', bufremove.delete, desc = 'Fermer buffer', silent = true, hidden = true }, - { '', neotree_utils.smart_open, desc = 'Parcourir fichiers', silent = true, hidden = true }, + { '', neotree_helper.smart_open, desc = 'Parcourir fichiers', silent = true, hidden = true }, } -- The line beneath this is called `modeline`. See `:help modeline` diff --git a/lua/custom/plugins/neotree-helper.lua b/lua/custom/plugins/neotree-helper.lua new file mode 100644 index 0000000..83db40f --- /dev/null +++ b/lua/custom/plugins/neotree-helper.lua @@ -0,0 +1,88 @@ +-- Neo-tree helper module +-- +local M = {} + +-- Function to get confirmation input (compatible with different neo-tree versions) +local function get_confirmation(msg, callback) + -- Try the modern approach first + local ok, inputs = pcall(require, 'neo-tree.ui.inputs') + if ok and inputs and inputs.confirm then + return inputs.confirm(msg, callback) + end + + -- Fallback to vim.ui.input for compatibility + vim.ui.input({ + prompt = msg .. ' (y/N): ', + }, function(input) + local confirmed = input and (input:lower() == 'y' or input:lower() == 'yes') + callback(confirmed) + end) +end + +-- Smart open a neo-tree window +function M.smart_open() + local bufname = vim.api.nvim_buf_get_name(0) + local filetype = vim.bo.filetype + local is_real_file = vim.fn.filereadable(bufname) == 1 + + -- Si c'est le dashboard ministarter, ouvrir dans le home + if filetype == 'ministarter' then + vim.cmd('Neotree toggle reveal=false position=float dir=' .. vim.fn.expand '~') + -- Si c'est un fichier réel, révéler le fichier dans l'arborescence + elseif is_real_file and bufname ~= '' then + vim.cmd 'Neotree position=left reveal=true' + -- Sinon, ouvrir dans le répertoire de travail courant + else + vim.cmd('Neotree position=left reveal_force_cwd=true dir=' .. vim.fn.getcwd()) + end +end + +-- Trash the target +function M.trash(state) + local node = state.tree:get_node() + if node.type == 'message' then + return + end + + local _, name = require('neo-tree.utils').split_path(node.path) + local msg = string.format("Are you sure you want to trash '%s'?", name) + + get_confirmation(msg, function(confirmed) + if not confirmed then + return + end + vim.api.nvim_command('silent !trash-put ' .. vim.fn.shellescape(node.path)) + require('neo-tree.sources.manager').refresh(state.name) + end) +end + +-- Trash the selections (visual mode) +function M.trash_visual(state, selected_nodes) + local paths_to_trash = {} + for _, node in ipairs(selected_nodes) do + if node.type ~= 'message' then + table.insert(paths_to_trash, node.path) + end + end + + if #paths_to_trash == 0 then + return + end + + local msg = 'Are you sure you want to trash ' .. #paths_to_trash .. ' items?' + get_confirmation(msg, function(confirmed) + if not confirmed then + return + end + for _, path in ipairs(paths_to_trash) do + vim.api.nvim_command('silent !trash-put ' .. vim.fn.shellescape(path)) + end + require('neo-tree.sources.manager').refresh(state.name) + end) +end + +return M + +-- The line beneath this is called `modeline`. See `:help modeline` +-- vim: ts=2 sts=2 sw=2 et + diff --git a/lua/custom/plugins/neotree.lua b/lua/custom/plugins/neotree.lua deleted file mode 100644 index 967f825..0000000 --- a/lua/custom/plugins/neotree.lua +++ /dev/null @@ -1,26 +0,0 @@ --- Neo-tree helper module --- - -local M = {} - -function M.smart_open() - local bufname = vim.api.nvim_buf_get_name(0) - local filetype = vim.bo.filetype - local is_real_file = vim.fn.filereadable(bufname) == 1 - - -- Si c'est le dashboard ministarter, ouvrir dans le home - if filetype == 'ministarter' then - vim.cmd('Neotree toggle reveal=false position=float dir=' .. vim.fn.expand '~') - -- Si c'est un fichier réel, révéler le fichier dans l'arborescence - elseif is_real_file and bufname ~= '' then - vim.cmd 'Neotree position=left reveal=true' - -- Sinon, ouvrir dans le répertoire de travail courant - else - vim.cmd('Neotree position=float reveal_force_cwd=true dir=' .. vim.fn.getcwd()) - end -end - -return M - --- The line beneath this is called `modeline`. See `:help modeline` --- vim: ts=2 sts=2 sw=2 et diff --git a/lua/kickstart/core/options.lua b/lua/kickstart/core/options.lua index 7784d87..7234c85 100644 --- a/lua/kickstart/core/options.lua +++ b/lua/kickstart/core/options.lua @@ -81,5 +81,15 @@ vim.o.scrolloff = 10 -- See `:help 'confirm'` vim.o.confirm = true +-- Indentation : espaces par défaut +vim.opt.expandtab = true -- convertit les tabs en espaces +vim.opt.tabstop = 2 -- largeur visuelle d'un tab +vim.opt.shiftwidth = 2 -- indentation à 2 espaces +vim.opt.softtabstop = 2 -- nombre d'espaces quand tu tapes + +-- indentation auto intelligente +vim.opt.smartindent = true + -- The line beneath this is called `modeline`. See `:help modeline` --- vim: ts=2 sts=2 sw=2 et \ No newline at end of file +-- vim: ts=2 sts=2 sw=2 et + diff --git a/lua/kickstart/plugins/neo-tree.lua b/lua/kickstart/plugins/neo-tree.lua index 6c7d062..fe85a32 100644 --- a/lua/kickstart/plugins/neo-tree.lua +++ b/lua/kickstart/plugins/neo-tree.lua @@ -1,6 +1,8 @@ -- Neo-tree is a Neovim plugin to browse the file system -- https://github.com/nvim-neo-tree/neo-tree.nvim +local neotree_helper = require 'custom.plugins.neotree-helper' + return { 'nvim-neo-tree/neo-tree.nvim', version = '*', @@ -8,20 +10,54 @@ return { 'nvim-lua/plenary.nvim', 'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended 'MunifTanjim/nui.nvim', - 'folke/snacks.nvim', -- optional + 'folke/snacks.nvim', -- optional for image preview + 'saifulapm/neotree-file-nesting-config', -- optional for VSCode like file nesting }, lazy = false, keys = { - { '\\', ':Neotree reveal', desc = 'NeoTree reveal', silent = true }, + -- { '', ':Neotree reveal', desc = 'NeoTree reveal', silent = true }, }, opts = { + hide_root_node = true, -- recommanded config for VSCode like file nesting + retain_hidden_root_indent = true, -- recommanded config for VSCode like file nesting filesystem = { + filtered_items = { + show_hidden_count = false, -- recommanded config for VSCode like file nesting + never_show = { -- recommanded config for VSCode like file nesting + '.DS_Store', + }, + }, window = { mappings = { - ['\\'] = 'close_window', + [''] = { + 'close_window', + desc = 'close neo-tree', + }, + ['T'] = { + 'trash', + desc = 'trash file', + }, }, }, + commands = { + trash = neotree_helper.trash, + trash_visual = neotree_helper.trash_visual, + }, + }, + default_component_configs = { + indent = { + with_expanders = true, + expander_collapsed = '', + expander_expanded = '', + }, }, }, + config = function(_, opts) + -- Adding rules from plugin + opts.nesting_rules = require('neotree-file-nesting-config').nesting_rules + require('neo-tree').setup(opts) + end, } +-- The line beneath this is called `modeline`. See `:help modeline` +-- vim: ts=2 sts=2 sw=2 et diff --git a/lua/kickstart/plugins/snacks.lua b/lua/kickstart/plugins/snacks.lua index f05a63f..312d7d7 100644 --- a/lua/kickstart/plugins/snacks.lua +++ b/lua/kickstart/plugins/snacks.lua @@ -7,22 +7,26 @@ return { 'folke/snacks.nvim', priority = 1000, lazy = false, - ---@type snacks.Config - -- opts = { - -- -- your configuration comes here - -- -- or leave it empty to use the default settings - -- -- refer to the configuration section below - -- bigfile = { enabled = true }, - -- dashboard = { enabled = true }, - -- explorer = { enabled = true }, - -- indent = { enabled = true }, - -- input = { enabled = true }, - -- picker = { enabled = true }, - -- notifier = { enabled = true }, - -- quickfile = { enabled = true }, - -- scope = { enabled = true }, - -- scroll = { enabled = true }, - -- statuscolumn = { enabled = true }, - -- words = { enabled = true }, + -- -@type snacks.Config + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + bigfile = { enabled = false }, + dashboard = { enabled = false }, + explorer = { enabled = false }, + indent = { enabled = false }, + input = { enabled = false }, + picker = { enabled = false }, + notifier = { enabled = false }, + quickfile = { enabled = false }, + scope = { enabled = false }, + scroll = { enabled = false }, + statuscolumn = { enabled = false }, + words = { enabled = false }, + image = { + enabled = true, + }, + }, }, }