Browse Source

Neovim: Improve file browsing

master
Riyyi 1 week ago
parent
commit
98cf182406
  1. 1
      .config/nvim/lazy-lock.json
  2. 11
      .config/nvim/lua/keybind-functions.lua
  3. 9
      .config/nvim/lua/keybinds.lua
  4. 12
      .config/nvim/lua/selection.lua

1
.config/nvim/lazy-lock.json

@ -29,6 +29,7 @@
"rainbow-delimiters.nvim": { "branch": "master", "commit": "c7e489756b5455f922ce79ac374a4ede594f4a20" }, "rainbow-delimiters.nvim": { "branch": "master", "commit": "c7e489756b5455f922ce79ac374a4ede594f4a20" },
"sqlite.lua": { "branch": "master", "commit": "d0ffd703b56d090d213b497ed4eb840495f14a11" }, "sqlite.lua": { "branch": "master", "commit": "d0ffd703b56d090d213b497ed4eb840495f14a11" },
"telescope-all-recent.nvim": { "branch": "main", "commit": "267e9e5fd13a6e9a4cc6ffe00452d446d040401d" }, "telescope-all-recent.nvim": { "branch": "main", "commit": "267e9e5fd13a6e9a4cc6ffe00452d446d040401d" },
"telescope-file-browser.nvim": { "branch": "master", "commit": "626998e5c1b71c130d8bc6cf7abb6709b98287bb" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" },
"telescope-recent-files": { "branch": "main", "commit": "3a7a1b9c6b52b6ff7938c59f64c87a05e013dff8" }, "telescope-recent-files": { "branch": "main", "commit": "3a7a1b9c6b52b6ff7938c59f64c87a05e013dff8" },
"telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },

11
.config/nvim/lua/keybind-functions.lua

@ -33,7 +33,7 @@ end
M.file_config = function() M.file_config = function()
builtin.find_files({ builtin.find_files({
prompt_title = "Nvim Config", prompt_title = "Nvim Config",
cwd = "~/.config/nvim", cwd = vim.fn.stdpath("config"),
hidden = true, hidden = true,
no_ignore = true, no_ignore = true,
-- path_display = { "shorten" }, -- path_display = { "shorten" },
@ -41,7 +41,7 @@ M.file_config = function()
end end
M.file_find = function() M.file_find = function()
builtin.find_files({ telescope.extensions.file_browser.file_browser({
cwd = F.get_current_directory(), cwd = F.get_current_directory(),
hidden = true, hidden = true,
no_ignore = true, no_ignore = true,
@ -49,18 +49,13 @@ M.file_find = function()
end end
M.file_find_home = function() M.file_find_home = function()
builtin.find_files({ telescope.extensions.file_browser.file_browser({
cwd = "~", cwd = "~",
hidden = true, hidden = true,
no_ignore = true, no_ignore = true,
}) })
end end
M.file_find_root = function()
local cwd = F.get_current_directory():gsub("^/", "")
builtin.find_files({ default_text = cwd, cwd = "/" })
end
M.file_find_recent = function() M.file_find_recent = function()
telescope.extensions.recent_files.pick() telescope.extensions.recent_files.pick()
end end

9
.config/nvim/lua/keybinds.lua

@ -85,7 +85,6 @@ M.setup = function()
K("n", "<leader>fc", F.file_config, { desc = "Config file" }) K("n", "<leader>fc", F.file_config, { desc = "Config file" })
K("n", "<leader>ff", F.file_find, { desc = "Find file" }) K("n", "<leader>ff", F.file_find, { desc = "Find file" })
K("n", "<leader>fh", F.file_find_home, { desc = "Find file in ~" }) K("n", "<leader>fh", F.file_find_home, { desc = "Find file in ~" })
K("n", "<leader>f/", F.file_find_root, { desc = "Find file in root" })
K("n", "<leader>fr", F.file_find_recent, { desc = "Find recent file" }) K("n", "<leader>fr", F.file_find_recent, { desc = "Find recent file" })
K("n", "<leader>fs", F.file_save, { desc = "Save file" }) K("n", "<leader>fs", F.file_save, { desc = "Save file" })
@ -220,11 +219,19 @@ end
M.telescope_default_mappings = function() M.telescope_default_mappings = function()
local actions = require("telescope.actions") local actions = require("telescope.actions")
return { return {
n = {
["<M-h>"] = actions.close,
["<M-j>"] = actions.move_selection_next,
["<M-k>"] = actions.move_selection_previous,
["<M-l>"] = actions.select_default,
},
i = { i = {
["<M-h>"] = actions.close, ["<M-h>"] = actions.close,
["<M-j>"] = actions.move_selection_next, ["<M-j>"] = actions.move_selection_next,
["<M-k>"] = actions.move_selection_previous, ["<M-k>"] = actions.move_selection_previous,
["<M-l>"] = actions.select_default, ["<M-l>"] = actions.select_default,
["<Tab>"] = actions.select_default,
} }
} }
end end

12
.config/nvim/lua/selection.lua

@ -15,6 +15,7 @@ return {
end, end,
}, },
-- Extensions -- Extensions
"nvim-telescope/telescope-file-browser.nvim",
"smartpde/telescope-recent-files", "smartpde/telescope-recent-files",
}, },
extensions = { extensions = {
@ -38,10 +39,17 @@ return {
path = vim.fn.stdpath("cache") .. "/telescope_history", path = vim.fn.stdpath("cache") .. "/telescope_history",
}, },
mappings = require("keybinds").telescope_default_mappings() mappings = require("keybinds").telescope_default_mappings(),
},
extensions = {
file_browser = {
hide_parent_dir = true, -- hide "../"
prompt_path = true, -- set path as prompt prefix
},
}, },
}) })
require("telescope").load_extension("fzf") require("telescope").load_extension("fzf")
require("telescope").load_extension "file_browser"
require("telescope").load_extension("recent_files") require("telescope").load_extension("recent_files")
--- ┌──────────────────────────────────────────────────┐ --- ┌──────────────────────────────────────────────────┐
@ -85,7 +93,7 @@ return {
-- Width -- Width
prompt.width = max_columns - (bs ~= 0 and search_condensed == 0 and bs or 0) prompt.width = max_columns - (bs ~= 0 and search_condensed == 0 and bs or 0)
results.width = max_columns - (bs ~= 0 and search_condensed == 0 and bs or 0) results.width = max_columns - (bs ~= 0 and search_condensed == 0 and bs or 0)
preview.width = math.floor(max_columns * 0.5) preview.width = math.floor(max_columns * 0.75)
-- Line (position), coordinates start at top-left -- Line (position), coordinates start at top-left
prompt.line = max_lines - results.height + search_condensed - bs -- take overlapping border into account prompt.line = max_lines - results.height + search_condensed - bs -- take overlapping border into account

Loading…
Cancel
Save