Skip to content

Commit 5547113

Browse files
authored
Merge pull request #16 from ntk148v/feat/mini.files
Feat/mini.files
2 parents 7ba0f96 + 53a0731 commit 5547113

File tree

5 files changed

+113
-115
lines changed

5 files changed

+113
-115
lines changed

README.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ tree ~/.config/nvim
174174
| [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) | Nvim Treesitter configurations and abstraction layer |
175175
| [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) | Auto completion plugin |
176176
| [LuaSnip](https://github.com/L3MON4D3/LuaSnip) | Snippet Engine for Neovim written in Lua |
177-
| [nvim-tree.lua](https://github.com/kyazdani42/nvim-tree.lua) - | A File Explorer written In Lua |
178177
| [nvim-autopairs](https://github.com/windwp/nvim-autopairs) | A super powerful autopairs for Neovim |
179178
| [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) | Lua `fork` of vim-web-devicons for neovim |
180179
| [lualine.nvim](https://github.com/nvim-lualine/lualine.nvim) | A blazing fast and easy to configure neovim statusline plugin written in pure lua. |
@@ -186,6 +185,7 @@ tree ~/.config/nvim
186185
| [zbirenbaum/copilot.lua](https://github.com/zbirenbaum/copilot.lua) | Fully featured & enhanced replacement for copilot.vim complete with API for interacting with Github Copilot |
187186
| [zbirenbaum/copilot-cmp](https://github.com/zbirenbaum/copilot-cmp) | Lua plugin to turn github copilot into a cmp source |
188187
| [CopilotC-Nvim/CopilotChat.nvim](https://github.com/CopilotC-Nvim/CopilotChat.nvim) | Chat with GitHub Copilot in Neovim |
188+
| [nvim-mini/mini.files](https://github.com/nvim-mini/mini.files) | Navigate and manipulate file system. Part of 'mini.nvim' library. |
189189

190190
### 5.2. LSP
191191

@@ -244,24 +244,23 @@ Once loaded, Copilot will start providing suggestions and chat capabilities. You
244244

245245
These are the default keymaps, in the following shortcuts, the `<leader>`+` key is set up to `` (space) character, check: [keymaps.lua](./nvim/lua/core/keymaps.lua).
246246

247-
| Shortcut | Mode | Description |
248-
| ------------------------------ | ------ | --------------------------------------------- |
249-
| <kbd>kk</kbd> | Insert | Esc with `kk` |
250-
| <kbd>rr</kbd> | Normal | Reload configuration file |
251-
| <kbd>tt</kbd> | Normal | Create terminal |
252-
| `<leader>`+<kbd>s</kbd> | Normal | Save file |
253-
| `<leader>`+<kbd>q</kbd> | Normal | Save (close all windows) and exit from Neovim |
254-
| `<leader>`+<kbd>n</kbd> | Normal | Open NvimTree |
255-
| `<leader>`+<kbd>nr</kbd> | Normal | Refresh NvimTree |
256-
| `<leader>`+<kbd>nf</kbd> | Normal | Find file in NvimTree |
257-
| `<leader>`+<kbd>ff</kbd> | Normal | Open Telescope to find files |
258-
| `<leader>`+<kbd>fg</kbd> | Normal | Open Telescope to do live grep |
259-
| `<leader>`+<kbd>fb</kbd> | Normal | Open Telescope to list buffers |
260-
| `<leader>`+<kbd>fh</kbd> | Normal | Open Telescope to show help |
261-
| `<leader>`+<kbd>fo</kbd> | Normal | Open Telescope to show recent opened files |
262-
| `<leader>`+<kbd>cm</kbd> | Normal | Open Telescope to list git commits |
263-
| `<leader>`+<kbd>wh/j/k/l</kbd> | Normal | Move around splits |
264-
| <kbd>mm</kbd> | Normal | Comment/Uncomment line |
247+
| Shortcut | Mode | Description |
248+
| ------------------------------ | ------ | ------------------------------------------------ |
249+
| <kbd>kk</kbd> | Insert | Esc with `kk` |
250+
| <kbd>rr</kbd> | Normal | Reload configuration file |
251+
| <kbd>tt</kbd> | Normal | Create terminal |
252+
| `<leader>`+<kbd>s</kbd> | Normal | Save file |
253+
| `<leader>`+<kbd>q</kbd> | Normal | Save (close all windows) and exit from Neovim |
254+
| `<leader>`+<kbd>fm</kbd> | Normal | Open mini.files (Directory of the current files) |
255+
| `<leader>`+<kbd>fM</kbd> | Normal | Open mini.files (cwd) |
256+
| `<leader>`+<kbd>ff</kbd> | Normal | Open Telescope to find files |
257+
| `<leader>`+<kbd>fg</kbd> | Normal | Open Telescope to do live grep |
258+
| `<leader>`+<kbd>fb</kbd> | Normal | Open Telescope to list buffers |
259+
| `<leader>`+<kbd>fh</kbd> | Normal | Open Telescope to show help |
260+
| `<leader>`+<kbd>fo</kbd> | Normal | Open Telescope to show recent opened files |
261+
| `<leader>`+<kbd>cm</kbd> | Normal | Open Telescope to list git commits |
262+
| `<leader>`+<kbd>wh/j/k/l</kbd> | Normal | Move around splits |
263+
| <kbd>mm</kbd> | Normal | Comment/Uncomment line |
265264

266265
There are many default keymaps, you can check it using `:map` command. There are also other variants:
267266

lua/mappings.lua

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,21 @@ map("n", "<leader>fb", builtin.buffers, { desc = "Open Telescope to list buffers
5353
map("n", "<leader>fh", builtin.help_tags, { desc = "Open Telescope to show help" })
5454
map("n", "<leader>fo", builtin.oldfiles, { desc = "Open Telescope to list recent files" })
5555
map("n", "<leader>cm", builtin.git_commits, { desc = "Open Telescope to list git commits" })
56-
-- NvimTree
57-
map("n", "<leader>n", ":NvimTreeToggle<CR>", { desc = "Toggle NvimTree sidebar" }) -- open/close
58-
map("n", "<leader>nr", ":NvimTreeRefresh<CR>", { desc = "Refresh NvimTree" }) -- refresh
59-
map("n", "<leader>nf", ":NvimTreeFindFile<CR>", { desc = "Search file in NvimTree" }) -- search file
56+
57+
-- Mini.files
58+
map(
59+
"n",
60+
"<leader>fm",
61+
function() require("mini.files").open(vim.api.nvim_buf_get_name(0), true) end,
62+
{ desc = "Open mini.files (Directory of Current File)"}
63+
)
64+
65+
map(
66+
"n",
67+
"<leader>fM",
68+
function() require("mini.files").open(vim.uv.cwd(), true) end,
69+
{ desc = "Open mini.files (cwd)"}
70+
)
6071

6172
-- LSP
6273
map(

lua/plugins/configs/mini-files.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--
2+
-- ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗
3+
-- ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║
4+
-- ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║
5+
-- ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║
6+
-- ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║
7+
-- ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝
8+
--
9+
-- File: plugins/configs/mini-files.lua
10+
-- Description: mini-files config
11+
-- Author: Kien Nguyen-Tuan <kiennt2609@gmail.com>
12+
return {
13+
windows = {
14+
preview = true,
15+
},
16+
options = {
17+
use_as_default_explorer = true,
18+
},
19+
}

lua/plugins/configs/tree.lua

Lines changed: 0 additions & 85 deletions
This file was deleted.

lua/plugins/init.lua

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,68 @@
1313
local builtin_plugins = {
1414
{ "nvim-lua/plenary.nvim" },
1515
-- File explore
16-
-- nvim-tree.lua - A file explorer tree for neovim written in lua
16+
-- mini.files
1717
{
18-
"nvim-tree/nvim-tree.lua",
19-
dependencies = {
20-
"nvim-tree/nvim-web-devicons",
21-
opt = true,
22-
},
23-
opts = function() require "plugins.configs.tree" end,
18+
"nvim-mini/mini.files",
19+
lazy = false,
20+
opts = require "plugins.configs.mini-files",
21+
config = function(_, opts)
22+
require("mini.files").setup(opts)
23+
24+
local show_dotfiles = true
25+
local filter_show = function(fs_entry) return true end
26+
local filter_hide = function(fs_entry) return not vim.startswith(fs_entry.name, ".") end
27+
28+
local toggle_dotfiles = function()
29+
show_dotfiles = not show_dotfiles
30+
local new_filter = show_dotfiles and filter_show or filter_hide
31+
require("mini.files").refresh { content = { filter = new_filter } }
32+
end
33+
34+
local map_split = function(buf_id, lhs, direction, close_on_file)
35+
local rhs = function()
36+
local new_target_window
37+
local cur_target_window = require("mini.files").get_explorer_state().target_window
38+
if cur_target_window ~= nil then
39+
vim.api.nvim_win_call(cur_target_window, function()
40+
vim.cmd("belowright " .. direction .. " split")
41+
new_target_window = vim.api.nvim_get_current_win()
42+
end)
43+
44+
require("mini.files").set_target_window(new_target_window)
45+
require("mini.files").go_in { close_on_file = close_on_file }
46+
end
47+
end
48+
49+
local desc = "Open in " .. direction .. " split"
50+
if close_on_file then desc = desc .. " and close" end
51+
vim.keymap.set("n", lhs, rhs, { buffer = buf_id, desc = desc })
52+
end
53+
54+
vim.api.nvim_create_autocmd("User", {
55+
pattern = "MiniFilesBufferCreate",
56+
callback = function(args)
57+
local buf_id = args.data.buf_id
58+
59+
vim.keymap.set(
60+
"n",
61+
opts.mappings and opts.mappings.toggle_hidden or "g.",
62+
toggle_dotfiles,
63+
{ buffer = buf_id, desc = "Toggle hidden files" }
64+
)
65+
66+
map_split(buf_id, opts.mappings and opts.mappings.go_in_horizontal or "<C-w>s", "horizontal", false)
67+
map_split(buf_id, opts.mappings and opts.mappings.go_in_vertical or "<C-w>v", "vertical", false)
68+
map_split(
69+
buf_id,
70+
opts.mappings and opts.mappings.go_in_horizontal_plus or "<C-w>S",
71+
"horizontal",
72+
true
73+
)
74+
map_split(buf_id, opts.mappings and opts.mappings.go_in_vertical_plus or "<C-w>V", "vertical", true)
75+
end,
76+
})
77+
end,
2478
},
2579
-- Formatter
2680
-- Lightweight yet powerful formatter plugin for Neovim

0 commit comments

Comments
 (0)