From d74b68eba2dba3c15ab7a949630fe6cb15754734 Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Thu, 6 Jun 2024 21:20:43 +0930 Subject: [PATCH] feat: update some minor config stuff --- .config/nvim/lua/tovi/core/remaps.lua | 6 +- .config/nvim/lua/tovi/plugins/copilot.lua | 84 ++++---- .config/nvim/lua/tovi/plugins/formatting.lua | 28 +-- .config/nvim/lua/tovi/plugins/fugitive.lua | 77 ++++--- .config/nvim/lua/tovi/plugins/gitsigns.lua | 6 +- .config/nvim/lua/tovi/plugins/harpoon.lua | 14 +- .config/nvim/lua/tovi/plugins/linting.lua | 10 +- .../nvim/lua/tovi/plugins/lsp/lspconfig.lua | 9 +- .config/nvim/lua/tovi/plugins/lsp/mason.lua | 10 +- .config/nvim/lua/tovi/plugins/lualine.lua | 16 +- .config/nvim/lua/tovi/plugins/nvim-cmp.lua | 18 +- .../nvim/lua/tovi/plugins/nvim-treesitter.lua | 59 +++--- .config/nvim/lua/tovi/plugins/oil.lua | 188 ++++++++---------- .config/nvim/lua/tovi/plugins/telescope.lua | 102 +++++----- 14 files changed, 300 insertions(+), 327 deletions(-) diff --git a/.config/nvim/lua/tovi/core/remaps.lua b/.config/nvim/lua/tovi/core/remaps.lua index f3625c3..0cacfd0 100644 --- a/.config/nvim/lua/tovi/core/remaps.lua +++ b/.config/nvim/lua/tovi/core/remaps.lua @@ -10,7 +10,9 @@ vim.keymap.set("n", "hs", "split", { desc = "Open horizontal sp vim.keymap.set("n", "vs", "vsplit", { desc = "Open vertical spilt" }) -- Spell-check -vim.keymap.set("n", "o", vim.cmd("setlocal spell! spelllang=en_au"), { desc = "Toggle spell check" }) +vim.keymap.set("n", "o", function() + vim.cmd("setlocal spell! spelllang=en_au") +end, { desc = "Toggle spell check" }) -- Map Q to nop vim.keymap.set("n", "Q", "", { desc = "Remap Q to because Q is the worst" }) @@ -47,4 +49,4 @@ vim.keymap.set( { desc = "Search and replace for word under cursor" } ) -vim.keymap.set('t', '', "", { silent = true }) +vim.keymap.set("t", "", "", { silent = true }) diff --git a/.config/nvim/lua/tovi/plugins/copilot.lua b/.config/nvim/lua/tovi/plugins/copilot.lua index 1c3eeef..62fb03b 100644 --- a/.config/nvim/lua/tovi/plugins/copilot.lua +++ b/.config/nvim/lua/tovi/plugins/copilot.lua @@ -1,41 +1,51 @@ return { - 'zbirenbaum/copilot.lua', - cmd = "Copilot", - event = "InsertEnter", - config = function() - require("copilot").setup({ - panel = { - enabled = true, - auto_refresh = false, - keymap = { - jump_prev = "[[", - jump_next = "]]", - accept = "", - refresh = "gr", - open = "" + { + 'zbirenbaum/copilot.lua', + cmd = "Copilot", + event = "InsertEnter", + config = function() + require("copilot").setup({ + panel = { + enabled = true, + auto_refresh = false, + keymap = { + jump_prev = "[[", + jump_next = "]]", + accept = "", + refresh = "gr", + open = "" + }, + layout = { + position = "bottom", -- | top | left | right + ratio = 0.4 + }, }, - layout = { - position = "bottom", -- | top | left | right - ratio = 0.4 + suggestion = { + enabled = false, + auto_trigger = true, + debounce = 75, + keymap = { + accept = ",,", + accept_word = false, + accept_line = false, + next = "", + prev = "", + dismiss = "", + }, }, - }, - suggestion = { - enabled = true, - auto_trigger = true, - debounce = 75, - keymap = { - accept = ",,", - accept_word = false, - accept_line = false, - next = "", - prev = "", - dismiss = "", - }, - }, - filetypes = { - }, - copilot_node_command = 'node', -- Node.js version must be > 18.x - server_opts_overrides = {}, - }) - end, + copilot_node_command = 'node', -- Node.js version must be > 18.x + server_opts_overrides = {}, + }) + end, + }, + { + "zbirenbaum/copilot-cmp", + event = "BufEnter", + dependencies = { + "zbirenbaum/copilot.lua", + }, + config = function() + require("copilot_cmp").setup() + end, + } } diff --git a/.config/nvim/lua/tovi/plugins/formatting.lua b/.config/nvim/lua/tovi/plugins/formatting.lua index 2f6974e..e499973 100644 --- a/.config/nvim/lua/tovi/plugins/formatting.lua +++ b/.config/nvim/lua/tovi/plugins/formatting.lua @@ -8,26 +8,26 @@ return { formatters_by_ft = { lua = { "stylua" }, go = { "goimports", "gofmt" }, - javascript = { "prettier" }, - typescript = { "prettier" }, - vue = { "prettier" }, - css = { "prettier" }, - html = { "prettier" }, - markdown = { "prettier" }, + javascript = { "prettierd" }, + typescript = { "prettierd" }, + vue = { "prettierd" }, + css = { "prettierd" }, + html = { "prettierd" }, + markdown = { "prettierd" }, json = { "fixjson" }, rust = { "rustfmt" }, shell = { "shfmt", "shellcheck" }, python = { "isort", "black" }, php = { "phpcbf" } }, - -- format_on_save = { - -- lsp_fallback = true, - -- async = false, - -- timeout_ms = 500, - -- }, - -- format_after_save = { - -- lsp_fallback = true, - -- }, + format_on_save = { + lsp_fallback = true, + async = false, + timeout_ms = 500, + }, + format_after_save = { + lsp_fallback = true, + }, log_level = vim.log.levels.WARN, notify_on_error = false, }) diff --git a/.config/nvim/lua/tovi/plugins/fugitive.lua b/.config/nvim/lua/tovi/plugins/fugitive.lua index 3d87fe8..7e0888b 100644 --- a/.config/nvim/lua/tovi/plugins/fugitive.lua +++ b/.config/nvim/lua/tovi/plugins/fugitive.lua @@ -7,47 +7,40 @@ return { vim.opt.diffopt = vim.opt.diffopt + "vertical" vim.opt.display = vim.opt.display + "lastline" - local function gitBlame(lines) - local current_file = vim.fn.expand('%:p') - local range = lines[1] .. "," .. lines[2] - local cmd = string.format("git -C %s blame -C -C -C -L %s %s | awk '{print $1}'", vim.fn.shellescape(vim.fn.fnamemodify(current_file, ':h')), range, vim.fn.fnamemodify(current_file, ':t')) - - local handle = io.popen(cmd) - local result = handle:read("*a") - handle:close() - - return result - end - - vim.keymap.set('n', 'gC', function () - vim.cmd(string.format('Git show %s', gitBlame({vim.fn.line('.'), vim.fn.line('.')}))) - end) - - local options = { noremap = true, silent = true } - - vim.keymap.set('n', 'gg', 'Git', options) - vim.keymap.set('n', 'gp', 'Git push', options) - vim.keymap.set('n', 'gP', 'Git pull', options) - vim.keymap.set('n', 'ga', 'Git add .', options) - vim.keymap.set('n', 'gA', 'Git add', options) - vim.keymap.set('n', 'gc', 'Git commit', options) - -- vim.keymap.set('n', 'gC', 'Git commit -a', options) - - vim.keymap.set('v', 'gl', function () - local startPos = vim.fn.getpos("'<") - local endPos = vim.fn.getpos("'>") - - local startLine = startPos[2] - local endLine = endPos[2] - - if (startLine == 0 or endLine == 0) - then - vim.notify(vim.inspect(vim.fn.getpos("'<")) .. " to " .. vim.inspect(vim.fn.getpos("'>"))) - -- vim.notify('Error getting start or end line', vim.log.levels.ERROR) - return - end - - vim.cmd(string.format('Git log -L %d,%d:%s', startLine, endLine, vim.fn.expand("%:."))) - end, options); + local fugitive_augroup = vim.api.nvim_create_augroup("fugitive_mappings", { clear = true }) + + local function set_fugitive_mappings() + local opts = { noremap = true, silent = true } + + vim.api.nvim_buf_set_keymap(0, "n", "gp", "Git push", opts) + vim.api.nvim_buf_set_keymap(0, "n", "gP", "Git pull", opts) + vim.api.nvim_buf_set_keymap(0, "n", "gc", "Git commit", opts) + end + + -- Create an autocmd to trigger the function when entering a Fugitive buffer + vim.api.nvim_create_autocmd("FileType", { + group = fugitive_augroup, + pattern = "fugitive", + callback = set_fugitive_mappings, + }) + + local opts = { noremap = true, silent = true } + + vim.keymap.set("n", "gg", "Git", opts) + + vim.keymap.set("v", "gl", function() + local startPos = vim.fn.getpos("'<") + local endPos = vim.fn.getpos("'>") + + local startLine = startPos[2] + local endLine = endPos[2] + + if startLine == 0 or endLine == 0 then + vim.notify(vim.inspect(vim.fn.getpos("'<")) .. " to " .. vim.inspect(vim.fn.getpos("'>"))) + return + end + + vim.cmd(string.format("Git log -L %d,%d:%s", startLine, endLine, vim.fn.expand("%:."))) + end, opts) end, } diff --git a/.config/nvim/lua/tovi/plugins/gitsigns.lua b/.config/nvim/lua/tovi/plugins/gitsigns.lua index 8867575..0edfbe7 100644 --- a/.config/nvim/lua/tovi/plugins/gitsigns.lua +++ b/.config/nvim/lua/tovi/plugins/gitsigns.lua @@ -2,9 +2,9 @@ return { "lewis6991/gitsigns.nvim", event = { "BufReadPre", "BufNewFile" }, config = function () - require('gitsigns').setup { + require('gitsigns').setup({ signs = { - add = {hl = 'GitSignsAdd' , text = '│', numhl='GitSignsAddNr' , linehl='GitSignsAddLn'}, + add = {hl = 'GitSignsAdd' , text = '+', numhl='GitSignsAddNr' , linehl='GitSignsAddLn'}, change = {hl = 'GitSignsChange', text = '│', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'}, delete = {hl = 'GitSignsDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'}, topdelete = {hl = 'GitSignsDelete', text = '‾', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'}, @@ -43,6 +43,6 @@ return { yadm = { enable = false }, - } + }) end } diff --git a/.config/nvim/lua/tovi/plugins/harpoon.lua b/.config/nvim/lua/tovi/plugins/harpoon.lua index ba7993a..0e2560d 100644 --- a/.config/nvim/lua/tovi/plugins/harpoon.lua +++ b/.config/nvim/lua/tovi/plugins/harpoon.lua @@ -1,6 +1,6 @@ return { "ThePrimeagen/harpoon", - branch = "harpoon2", + branch = "harpoon2", dependencies = { "nvim-lua/plenary.nvim", }, @@ -13,27 +13,27 @@ return { local keymap = vim.keymap - keymap.set("n", "a", function () + keymap.set("n", "a", function() harpoon:list():add() end, { desc = "Mark file with harpoon" }) - keymap.set("n", "", function () + keymap.set("n", "", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end, { desc = "Toggle quick menu for harpoon" }) - keymap.set("n", "", function() + keymap.set("n", "1", function() harpoon:list():select(1) end, { desc = "Go to first harpoon file" }) - keymap.set("n", "", function() + keymap.set("n", "2", function() harpoon:list():select(2) end, { desc = "Go to second harpoon file" }) - keymap.set("n", "", function() + keymap.set("n", "3", function() harpoon:list():select(3) end, { desc = "Go to third harpoon file" }) - keymap.set("n", "", function() + keymap.set("n", "4", function() harpoon:list():select(4) end, { desc = "Go to fourth harpoon file" }) end, diff --git a/.config/nvim/lua/tovi/plugins/linting.lua b/.config/nvim/lua/tovi/plugins/linting.lua index 10bcc4c..6088633 100644 --- a/.config/nvim/lua/tovi/plugins/linting.lua +++ b/.config/nvim/lua/tovi/plugins/linting.lua @@ -9,10 +9,6 @@ return { WARNING = vim.diagnostic.severity.WARN, } - lint.linters.ecs = { - cmd = "ecs", - } - lint.linters.phpcs = { cmd = 'phpcs', stdin = true, @@ -55,9 +51,9 @@ return { } lint.linters_by_ft = { - javascript = { "eslint" }, - typescript = { "eslint" }, - vue = { "eslint" }, + javascript = { "eslint_d" }, + typescript = { "eslint_d" }, + vue = { "eslint_d" }, json = { "jsonlint" }, markdown = { "markdownlint" }, php = { "phpcs" }, diff --git a/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua b/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua index 8122823..20a4ecd 100644 --- a/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua +++ b/.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua @@ -13,7 +13,7 @@ return { -- import cmp-nvim-lsp plugin local cmp_nvim_lsp = require("cmp_nvim_lsp") - local keymap = vim.keymap -- for conciseness + local keymap = vim.keymap local opts = { noremap = true, silent = true } local on_attach = function(_, bufnr) @@ -81,9 +81,6 @@ return { opts.desc = "Show documentation for what is under cursor" keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor - - opts.desc = "Restart LSP" - keymap.set("n", "rs", ":LspRestart", opts) -- mapping to restart lsp if necessary end -- override default floating window border if not set @@ -150,7 +147,6 @@ return { }) local function get_typescript_server_path(root_dir) - local global_ts = base_path .. '/typescript/lib' local found_ts = '' local function check_dir(path) @@ -167,7 +163,7 @@ return { end lspconfig.volar.setup({ - -- capabilities = capabilities, + capabilities = capabilities, on_attach = on_attach, filetypes = { "javascript", @@ -247,6 +243,5 @@ return { capabilities = capabilities, on_attach = on_attach, }) - end, } diff --git a/.config/nvim/lua/tovi/plugins/lsp/mason.lua b/.config/nvim/lua/tovi/plugins/lsp/mason.lua index d611712..deacabd 100644 --- a/.config/nvim/lua/tovi/plugins/lsp/mason.lua +++ b/.config/nvim/lua/tovi/plugins/lsp/mason.lua @@ -30,13 +30,9 @@ return { "tsserver", "html", "cssls", - "tailwindcss", - "svelte", "lua_ls", "emmet_ls", - -- "pyright", "intelephense", - -- "gopls", }, automatic_installation = true, }) @@ -44,14 +40,14 @@ return { mason_tool_installer.setup({ ensure_installed = { "prettier", - "eslint_d", + "prettierd", + "eslint", + "eslint_d", "jsonlint", "markdownlint", "phpcbf", "phpcs", - -- "gospel", "golangci-lint", - -- "pylint", "hadolint", "gofumpt", "goimports", diff --git a/.config/nvim/lua/tovi/plugins/lualine.lua b/.config/nvim/lua/tovi/plugins/lualine.lua index b15d9d4..c07a40c 100644 --- a/.config/nvim/lua/tovi/plugins/lualine.lua +++ b/.config/nvim/lua/tovi/plugins/lualine.lua @@ -1,30 +1,34 @@ return { "nvim-lualine/lualine.nvim", - dependencies = { "nvim-tree/nvim-web-devicons" }, + dependencies = { + "nvim-tree/nvim-web-devicons", + "letieu/harpoon-lualine", + }, config = function() local lualine = require("lualine") local lazy_status = require("lazy.status") lualine.setup({ options = { - theme = 'kanagawa', - component_separators = { left = '', right = '' }, - section_separators = { left = '', right = '' }, + theme = "kanagawa", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + globalstatus = true, }, sections = { lualine_b = { - { "diagnostics" }, { "branch" }, { "diff" }, + { "diagnostics" }, }, lualine_c = { { "filename", file_status = true, path = 1 }, + { "harpoon2" }, }, lualine_x = { { lazy_status.updates, cond = lazy_status.has_updates, - color = { fg = "#ff9e64" }, }, { "fileformat" }, { "filetype" }, diff --git a/.config/nvim/lua/tovi/plugins/nvim-cmp.lua b/.config/nvim/lua/tovi/plugins/nvim-cmp.lua index 4d658b6..0de8f41 100644 --- a/.config/nvim/lua/tovi/plugins/nvim-cmp.lua +++ b/.config/nvim/lua/tovi/plugins/nvim-cmp.lua @@ -2,12 +2,13 @@ return { "hrsh7th/nvim-cmp", event = "InsertEnter", dependencies = { - "hrsh7th/cmp-buffer", -- source for text in buffer - "hrsh7th/cmp-path", -- source for file system paths - "L3MON4D3/LuaSnip", -- snippet engine - "saadparwaiz1/cmp_luasnip", -- for autocompletion - "rafamadriz/friendly-snippets", -- useful snippets - "onsails/lspkind.nvim", -- vs-code like pictograms + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "rafamadriz/friendly-snippets", + "onsails/lspkind.nvim", "kristijanhusak/vim-dadbod-completion", }, config = function() @@ -41,8 +42,8 @@ return { mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.select_prev_item(), -- previous suggestion [""] = cmp.mapping.select_next_item(), -- next suggestion - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), -- show completion suggestions [""] = cmp.mapping.abort(), -- close completion window [""] = cmp.mapping.confirm({ select = true }), @@ -76,6 +77,7 @@ return { -- sources for autocompletion sources = cmp.config.sources({ { name = "nvim_lsp" }, + { name = "copilot" }, { name = "luasnip" }, { name = "buffer" }, { name = "path" }, diff --git a/.config/nvim/lua/tovi/plugins/nvim-treesitter.lua b/.config/nvim/lua/tovi/plugins/nvim-treesitter.lua index ac40c75..cedef10 100644 --- a/.config/nvim/lua/tovi/plugins/nvim-treesitter.lua +++ b/.config/nvim/lua/tovi/plugins/nvim-treesitter.lua @@ -3,23 +3,12 @@ return { "nvim-treesitter/nvim-treesitter", event = { "BufReadPre", "BufNewFile" }, build = ":TSUpdate", - dependencies = { - "windwp/nvim-ts-autotag", - }, config = function() -- import nvim-treesitter plugin local treesitter = require("nvim-treesitter.configs") -- configure treesitter treesitter.setup({ - -- enable syntax highlighting - highlight = { - enable = true, - }, - -- enable indentation - indent = { enable = true }, - -- enable autotagging (w/ nvim-ts-autotag plugin) - autotag = { enable = true }, -- ensure these language parsers are installed ensure_installed = { "json", @@ -40,33 +29,35 @@ return { "dockerfile", "gitignore", "php", - "blade", - }, - -- enable nvim-ts-context-commentstring plugin for commenting tsx and jsx - context_commentstring = { - enable = true, - enable_autocmd = false, }, -- auto install above language parsers auto_install = true, - }) + -- enable syntax highlighting + highlight = { + enable = true, + }, + -- enable indentation + indent = { enable = true }, + -- enable autotagging + autotag = { enable = true }, + }) - local parser_config = require "nvim-treesitter.parsers".get_parser_configs() + local parser_config = require("nvim-treesitter.parsers").get_parser_configs() - parser_config.blade = { - install_info = { - url = "https://github.com/EmranMR/tree-sitter-blade", - files = { "src/parser.c" }, - branch = "main", - }, - filetype = "blade" - } + parser_config.blade = { + install_info = { + url = "https://github.com/EmranMR/tree-sitter-blade", + files = { "src/parser.c" }, + branch = "main", + }, + filetype = "blade", + } - vim.filetype.add({ - pattern = { - ['.*%.blade%.php'] = 'blade', - } - }) - end, - }, + vim.filetype.add({ + pattern = { + [".*%.blade%.php"] = "blade", + }, + }) + end, + }, } diff --git a/.config/nvim/lua/tovi/plugins/oil.lua b/.config/nvim/lua/tovi/plugins/oil.lua index e9af7b3..1e8dac3 100644 --- a/.config/nvim/lua/tovi/plugins/oil.lua +++ b/.config/nvim/lua/tovi/plugins/oil.lua @@ -1,105 +1,89 @@ return { - 'stevearc/oil.nvim', - opts = {}, - -- Optional dependencies - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function () - require("oil").setup({ - default_file_explorer = true, - -- columns = { - -- "icon", - -- "permissions", - -- "size", - -- "mtime", - -- }, - buf_options = { - buflisted = false, - bufhidden = "hide", - }, - win_options = { - wrap = false, - signcolumn = "no", - cursorcolumn = false, - foldcolumn = "0", - spell = false, - list = false, - conceallevel = 3, - concealcursor = "nvic", - }, - delete_to_trash = false, - skip_confirm_for_simple_edits = false, - prompt_save_on_select_new_entry = true, - cleanup_delay_ms = 2000, - keymaps = { - ["g?"] = "actions.show_help", - [""] = "actions.select", - [""] = "actions.select_vsplit", - [""] = false, - [""] = "actions.select_tab", - [""] = "actions.preview", - [""] = "actions.close", - [""] = false, - ["-"] = "actions.parent", - ["_"] = "actions.open_cwd", - ["`"] = "actions.cd", - ["~"] = "actions.tcd", - ["gs"] = "actions.change_sort", - ["gx"] = "actions.open_external", - ["g."] = "actions.toggle_hidden", - }, - use_default_keymaps = false, - view_options = { - show_hidden = true, - is_hidden_file = function(name, bufnr) - return vim.startswith(name, ".") - end, - is_always_hidden = function(name, bufnr) - return false - end, - sort = { - { "type", "asc" }, - { "name", "asc" }, - }, - }, - float = { - padding = 2, - max_width = 0, - max_height = 0, - border = "rounded", - win_options = { - winblend = 0, - }, - override = function(conf) - return conf - end, - }, - preview = { - max_width = 0.9, - min_width = { 40, 0.4 }, - width = nil, - max_height = 0.9, - min_height = { 5, 0.1 }, - height = nil, - border = "rounded", - win_options = { - winblend = 0, - }, - }, - progress = { - max_width = 0.9, - min_width = { 40, 0.4 }, - width = nil, - max_height = { 10, 0.9 }, - min_height = { 5, 0.1 }, - height = nil, - border = "rounded", - minimized_border = "none", - win_options = { - winblend = 0, - }, - }, - }) + "stevearc/oil.nvim", + opts = {}, + -- Optional dependencies + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + require("oil").setup({ + default_file_explorer = true, + buf_options = { + buflisted = false, + bufhidden = "hide", + }, + win_options = { + wrap = false, + signcolumn = "no", + cursorcolumn = false, + foldcolumn = "0", + spell = false, + list = false, + conceallevel = 3, + concealcursor = "nvic", + }, + delete_to_trash = false, + skip_confirm_for_simple_edits = false, + prompt_save_on_select_new_entry = true, + cleanup_delay_ms = 2000, + keymaps = { + ["g?"] = "actions.show_help", + [""] = "actions.select", + [""] = "actions.select_vsplit", + [""] = false, + [""] = "actions.select_tab", + [""] = "actions.preview", + [""] = "actions.close", + [""] = false, + ["-"] = "actions.parent", + ["_"] = "actions.open_cwd", + ["`"] = "actions.cd", + ["~"] = "actions.tcd", + ["gs"] = "actions.change_sort", + ["gx"] = "actions.open_external", + ["g."] = "actions.toggle_hidden", + }, + use_default_keymaps = false, + view_options = { + show_hidden = true, + is_hidden_file = function(name, bufnr) + return vim.startswith(name, ".") + end, + is_always_hidden = function(name, bufnr) + return false + end, + sort = { + { "type", "asc" }, + { "name", "asc" }, + }, + }, + preview = { + max_width = 0.9, + min_width = { 40, 0.4 }, + width = nil, + max_height = 0.9, + min_height = { 5, 0.1 }, + height = nil, + border = "rounded", + win_options = { + winblend = 0, + }, + }, + progress = { + max_width = 0.9, + min_width = { 40, 0.4 }, + width = nil, + max_height = { 10, 0.9 }, + min_height = { 5, 0.1 }, + height = nil, + border = "rounded", + minimized_border = "none", + win_options = { + winblend = 0, + }, + }, + }) - vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory" }) - end + vim.keymap.set("n", "-", function() + vim.cmd("Oil") + end, { desc = "Open parent directory" }) + end, } diff --git a/.config/nvim/lua/tovi/plugins/telescope.lua b/.config/nvim/lua/tovi/plugins/telescope.lua index e6f657e..8422b36 100644 --- a/.config/nvim/lua/tovi/plugins/telescope.lua +++ b/.config/nvim/lua/tovi/plugins/telescope.lua @@ -5,7 +5,7 @@ return { { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, "nvim-tree/nvim-web-devicons", "debugloop/telescope-undo.nvim", - "nvim-telescope/telescope-ui-select.nvim", + "nvim-telescope/telescope-ui-select.nvim", }, config = function() local telescope = require("telescope") @@ -20,6 +20,7 @@ return { opts = opts or {} filepath = vim.fn.expand(filepath) + ---@diagnostic disable-next-line: undefined-field vim.loop.fs_stat(filepath, function(_, stat) if not stat then return @@ -36,7 +37,6 @@ return { telescope.setup({ defaults = { file_sorter = sorters.get_fzy_sorter, - prompt_prefix = " >", color_devicons = true, buffer_previewer_maker = truncate_large_files, @@ -84,40 +84,41 @@ return { }, }, }, - ["ui-select"] = { - require("telescope.themes").get_dropdown({}) - }, + ["ui-select"] = { + require("telescope.themes").get_dropdown({}), + }, }, }) telescope.load_extension("fzf") telescope.load_extension("undo") - telescope.load_extension("ui-select") + telescope.load_extension("ui-select") - local git_branches = function() - builtin.git_branches({ - attach_mappings = function(_, map) - map("i", "", actions.git_delete_branch) - map("n", "", actions.git_delete_branch) - return true - end, - }) - end + -- We cache the results of "git rev-parse" + -- Process creation is expensive in Windows, so this reduces latency + local is_inside_work_tree = {} + + local project_files = function() + local cwd = vim.fn.getcwd() + if is_inside_work_tree[cwd] == nil then + vim.fn.system("git rev-parse --is-inside-work-tree") + is_inside_work_tree[cwd] = vim.v.shell_error == 0 + end - local find_files = function() - local ran, errorMessage = pcall(function() + if is_inside_work_tree[cwd] then builtin.git_files({ show_untracked = true, hidden = true }) - end) - if not ran then - builtin.find_files({ hidden = true }) + else + builtin.find_files({}) end end -- set keymaps local keymap = vim.keymap -- for conciseness - keymap.set("n", "", function () builtin.live_grep({ hidden = true }) end, {}) - keymap.set("n", "", find_files, {}) + keymap.set("n", "", function() + builtin.live_grep({ hidden = true }) + end, {}) + keymap.set("n", "", project_files, {}) keymap.set("n", "fr", builtin.resume, {}) @@ -127,43 +128,42 @@ return { keymap.set("n", "m", builtin.marks, {}) keymap.set("n", "ch", builtin.command_history, {}) - keymap.set("n", "gb", git_branches, {}) - - keymap.set("n", "vh", builtin.help_tags, {}) + keymap.set("n", "gb", function() + builtin.git_branches({ + attach_mappings = function(_, map) + map("i", "", actions.git_delete_branch) + map("n", "", actions.git_delete_branch) + return true + end, + }) + end, {}) - keymap.set("n", "ds", builtin.lsp_document_symbols, {}) - keymap.set("n", "ws", builtin.lsp_workspace_symbols, {}) - keymap.set("n", "dws", builtin.lsp_dynamic_workspace_symbols, {}) + keymap.set("n", "gc", builtin.git_commits, {}) - keymap.set("n", "gf", function () - builtin.grep_string({ - search = vim.fn.expand(""), - }) - end) + keymap.set("n", "vh", builtin.help_tags, {}) - keymap.set("n", "gF", function () - builtin.grep_string({ - search = vim.fn.expand(""), - }) - end) + keymap.set("n", "ds", builtin.lsp_document_symbols, {}) + keymap.set("n", "ws", builtin.lsp_workspace_symbols, {}) + keymap.set("n", "dws", builtin.lsp_dynamic_workspace_symbols, {}) - keymap.set("n", "gD", function () - builtin.find_files({ - search_file = vim.fn.expand(""), - }) - end) + keymap.set("n", "gf", function() + builtin.grep_string({ + search = vim.fn.expand(""), + }) + end) - vim.keymap.set("n", "u", "Telescope undo") + keymap.set("n", "gF", function() + builtin.grep_string({ + search = vim.fn.expand(""), + }) + end) - local function telescopeDotfiles() + keymap.set("n", "gD", function() builtin.find_files({ - prompt_title = "< VimRC >", - cwd = vim.fn.expand("~/dotfiles"), - hidden = true, + search_file = vim.fn.expand(""), }) - end - - vim.api.nvim_create_user_command('TelescopeDotfiles', telescopeDotfiles, {}) + end) + vim.keymap.set("n", "u", "Telescope undo") end, }