From ad010bd91c69568d8d55b158aaeb8a56990219e1 Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Tue, 17 Jun 2025 09:13:53 +0930 Subject: [PATCH] feat: add telescope fuzzy searching for / key --- .config/nvim/lua/core/options.lua | 84 ++++++++++++++--------- .config/nvim/lua/plugins/telescope.lua | 92 +++++++++++++++++--------- .local/bin/unused-files.sh | 8 +++ 3 files changed, 122 insertions(+), 62 deletions(-) create mode 100644 .local/bin/unused-files.sh diff --git a/.config/nvim/lua/core/options.lua b/.config/nvim/lua/core/options.lua index dee495d..5c00d6d 100644 --- a/.config/nvim/lua/core/options.lua +++ b/.config/nvim/lua/core/options.lua @@ -2,50 +2,70 @@ vim.g.mapleader = ' ' vim.opt.clipboard = 'unnamedplus' -vim.opt.hlsearch = false -vim.opt.incsearch = true -vim.opt.ignorecase = true +-- Search Configuration +vim.opt.hlsearch = false -- Don't highlight search results after searching +vim.opt.incsearch = true -- Show search matches as you type +vim.opt.ignorecase = true -- Ignore case when searching +vim.opt.smartcase = true -- Override ignorecase if search contains uppercase letters -vim.opt.mouse = 'nv' -vim.opt.smartcase = true -vim.opt.linebreak = true +-- Mouse Configuration +vim.opt.mouse = 'nv' -- Enable mouse in normal and visual modes only -vim.opt.smartindent = true +-- Text Formatting +vim.opt.linebreak = true -- Break lines at word boundaries when wrapping +vim.opt.smartindent = true -- Automatically indent new lines intelligently -vim.opt.swapfile = false -vim.opt.backup = false -vim.opt.undodir = vim.fn.expand('~/.cache/nvim/undodir') -vim.opt.undofile = true +-- File Management +vim.opt.swapfile = false -- Don't create swap files +vim.opt.backup = false -- Don't create backup files +vim.opt.undodir = vim.fn.expand('~/.cache/nvim/undodir') -- Directory for undo files +vim.opt.undofile = true -- Save undo history to file for persistence -vim.opt.encoding = 'utf-8' -vim.opt.number = true -vim.opt.relativenumber = true +-- Character Encoding +vim.opt.encoding = 'utf-8' -- Set file encoding to UTF-8 -vim.opt.tabstop = 4 -vim.opt.softtabstop = 4 -vim.opt.expandtab = true -vim.opt.shiftwidth = 4 -vim.opt.smarttab = true +-- Line Numbers +vim.opt.number = true -- Show absolute line numbers +vim.opt.relativenumber = true -- Show relative line numbers (hybrid numbering) -vim.opt.scrolloff = 8 -vim.opt.signcolumn = 'yes' -vim.opt.isfname:append('@-@') +-- Indentation and Tabs +vim.opt.tabstop = 4 -- Number of spaces a tab character represents +vim.opt.softtabstop = 4 -- Number of spaces to use when inserting/deleting tabs +vim.opt.expandtab = true -- Convert tabs to spaces +vim.opt.shiftwidth = 4 -- Number of spaces to use for each indentation level +vim.opt.smarttab = true -- Use shiftwidth for tabs at beginning of line -vim.opt.pumheight = 10 +-- Scrolling and Display +vim.opt.scrolloff = 8 -- Keep 8 lines visible above/below cursor when scrolling +vim.opt.signcolumn = 'yes' -- Always show the sign column (for git, lsp, etc.) -vim.opt.updatetime = 50 +-- File Name Handling +vim.opt.isfname:append('@-@') -- Include @ and - characters in file names -vim.opt.colorcolumn = "80" -vim.opt.cursorline = true +-- Completion Menu +vim.opt.pumheight = 10 -- Limit popup menu height to 10 items -vim.opt.formatoptions = 'tqj' +-- Performance +vim.opt.updatetime = 50 -- Faster completion and CursorHold events (milliseconds) -vim.opt.splitbelow = true -vim.opt.splitright = true -vim.opt.diffopt:append('vertical') +-- Visual Guides +vim.opt.colorcolumn = "80" -- Show vertical line at column 80 +vim.opt.cursorline = true -- Highlight the current line -vim.opt.termguicolors = true +-- Text Formatting Options +vim.opt.formatoptions = 'tqj' -- t: auto-wrap text, q: format comments, j: remove comment leader when joining lines +-- Window Splitting +vim.opt.splitbelow = true -- Open horizontal splits below current window +vim.opt.splitright = true -- Open vertical splits to the right of current window + +-- Diff Mode +vim.opt.diffopt:append('vertical') -- Show diffs in vertical splits + +-- Colors +vim.opt.termguicolors = true -- Enable 24-bit RGB colors in terminal + +-- Command Line (Neovim 0.8+) if vim.fn.has("nvim-0.8") == 1 then - vim.opt.cmdheight = 0 + vim.opt.cmdheight = 0 -- Hide command line when not in use (requires Neovim 0.8+) end diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua index f8f0fb1..ed14135 100644 --- a/.config/nvim/lua/plugins/telescope.lua +++ b/.config/nvim/lua/plugins/telescope.lua @@ -10,6 +10,7 @@ return { config = function() local telescope = require("telescope") local actions = require("telescope.actions") + local action_state = require('telescope.actions.state') local previewers = require("telescope.previewers") local previewers_utils = require("telescope.previewers.utils") local sorters = require("telescope.sorters") @@ -35,30 +36,30 @@ return { end telescope.setup({ - defaults = vim.tbl_extend( - "force", - require("telescope.themes").get_ivy(), - { - file_sorter = sorters.get_fzy_sorter, - color_devicons = true, - buffer_previewer_maker = truncate_large_files, - - initial_mode = "insert", - selection_strategy = "reset", - sorting_strategy = "ascending", - path_display = { "truncate" }, + defaults = { + file_sorter = sorters.get_fzy_sorter, + color_devicons = true, + buffer_previewer_maker = truncate_large_files, + + initial_mode = "insert", + selection_strategy = "reset", + sorting_strategy = "ascending", + path_display = { "truncate" }, + + layout_config = { + prompt_position = "top", + }, - mappings = { - i = { - [""] = actions.move_selection_next, - [""] = actions.move_selection_previous, - [""] = actions.cycle_history_next, - [""] = actions.cycle_history_prev, - [""] = actions.smart_send_to_qflist + actions.open_qflist, - }, + mappings = { + i = { + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + [""] = actions.smart_send_to_qflist + actions.open_qflist, }, - } - ), + }, + }, pickers = { diagnostics = { initial_mode = "normal", @@ -67,14 +68,6 @@ return { }, }, }, - themes = { - ivy = { - layout_strategy = 'bottom_pane', - layout_config = { - height = 50, - }, - }, - }, extensions = { undo = { side_by_side = true, @@ -126,6 +119,11 @@ return { keymap.set("n", "fr", builtin.resume, {}) + keymap.set("n", "ss", builtin.spell_suggest, {}) + + keymap.set("n", "ql", builtin.quickfix, {}) + keymap.set("n", "qhl", builtin.quickfixhistory, {}) + keymap.set("n", "fb", builtin.buffers, {}) keymap.set("n", "fo", builtin.oldfiles, {}) @@ -171,5 +169,39 @@ return { end) vim.keymap.set("n", "u", "Telescope undo") + + keymap.set("n", "/", function() + builtin.current_buffer_fuzzy_find({ + attach_mappings = function(prompt_bufnr, map) + -- Override the default select action + map('i', '', function() + local selection = action_state.get_selected_entry() + local prompt = action_state.get_current_line() + + actions.close(prompt_bufnr) + + -- Set the search register to the prompt text + if prompt and prompt ~= "" then + vim.fn.setreg('/', prompt) + end + + -- Jump to the selected result with proper error handling + if selection then + -- Try different possible field names for line/column + local line = selection.lnum or selection.line_number or selection.row or 1 + local col = selection.col or selection.column or selection.start_col or 0 + + -- Ensure we have valid numbers + if type(line) == "number" and type(col) == "number" then + -- Vim uses 1-based indexing for lines, 0-based for columns + vim.api.nvim_win_set_cursor(0, { line, col }) + end + end + end) + + return true + end, + }) + end, {}) end, } diff --git a/.local/bin/unused-files.sh b/.local/bin/unused-files.sh new file mode 100644 index 0000000..a20a961 --- /dev/null +++ b/.local/bin/unused-files.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +find app/frontend/src -type f -name "*.vue" | while read -r file; do + filename=$(basename "$file" .vue) + if ! grep -r "$filename" app/frontend/src --exclude="$(basename "$file")" > /dev/null 2>&1; then + echo "Not Used: $file" + fi +done