Repository navigation
Expand file tree
/
Copy pathfzf-lua.lua
More file actions
170 lines (152 loc) · 7.26 KB
/
Copy pathfzf-lua.lua
File metadata and controls
170 lines (152 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
return function()
-- Define common filter pattern for ripgrep
local common_filter =
"--no-ignore-vcs --glob=!*.o --glob=!*.d --glob=!bld/** --glob=!bin/** --glob=!.git/** --glob=!.cache/** --glob=!node_modules/** --glob=!build/** --glob=!compile_commands* --glob=!install/** --glob=!dist/** --glob=!coverage/** --glob=!vendor/** --glob=!*.min.js --glob=!*.min.css --glob=!*.map --glob=!.vscode/** --glob=!output/** --glob=!*.log --glob=!*.tmp --glob=!*.swp --glob=!*.swo --glob=!*.bak --glob=!*.old --glob=!*.orig --glob=!.idea/**"
require("fzf-lua").setup({
"hide",
-- Path display options
files = {
path_shorten = 9, -- Shorten directory names to first letter
formatter = "path.filename_first"
},
lsp = {
path_shorten = 9, -- Shorten directory names to first letter
formatter = "path.filename_first"
},
grep = {
path_shorten = 9, -- Shorten directory names to first letter
formatter = "path.filename_first"
},
buffers = {
path_shorten = 9, -- Shorten directory names to first letter
formatter = "path.filename_first"
},
previewers = {
builtin = {
treesitter = {
enabled = true, -- Enable treesitter preview
disabled = {}, -- Disable for specific filetypes
context = {
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
multiwindow = false, -- Enable multiwindow support.
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
min_window_height = 0, -- Minimum editor window height to enable context. Values <= 0 mean no limit.
line_numbers = true,
multiline_threshold = 20, -- Maximum number of lines to show for a single context
trim_scope = 'outer', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
mode = 'cursor', -- Line used to calculate context. Choices: 'cursor', 'topline'
-- Separator between context and content. Should be a single character string, like '-'.
-- When separator is set, the context will only show up when there are at least 2 lines above cursorline.
separator = nil,
zindex = 20, -- The Z-index of the context window
on_attach = nil -- (fun(buf: integer): boolean) return false to disable attaching
}
}
}
},
-- Open in window mode instead of popup
winopts = {
-- Configure preview window to show up as a side window
preview = {
default = "builtin",
vertical = "right:65%", -- Show preview on right side taking 45% of width
horizontal = "down:50%", -- For horizontal splits, show below with 50% height
layout = "vertical", -- Default to vertical layout
delay = 100, -- Small delay before preview
title = true, -- Show file title
scrollbar = "float",
wrap = true
},
-- Use a standard split window instead of a popup
-- split = "belowright new",
height = 0.85, -- 80% of screen height
width = 0.90, -- Full width
border = "rounded", -- Rounded corners
fullscreen = false
},
fzf_opts = {
["--layout"] = "reverse", -- Cursor at top
["--info"] = "inline",
["--cycle"] = true
}
})
-- Keymaps
local map = vim.keymap.set
local opts = {noremap = true, silent = true}
local fzf = require("fzf-lua")
-- File finding
map('n', '<leader>ff', function()
fzf.files({cmd = "rg --files " .. common_filter, line_query = true})
end, opts)
map('n', '<leader>fg', function()
fzf.live_grep({
rg_opts = common_filter ..
" --no-heading --with-filename --line-number --column --smart-case"
})
end, opts)
map('n', '<leader>fG', function()
fzf.live_grep({
rg_opts = common_filter ..
"--no-heading --with-filename --line-number --column --smart-case",
search = vim.fn.expand('<cword>')
})
end, opts)
-- Fix duplicate key mapping by changing to <leader>fw (word under cursor)
map('n', '<leader>fw', function()
fzf.live_grep({
rg_opts = common_filter ..
" --no-heading --with-filename --line-number --column --smart-case",
search = vim.fn.expand('<cword>')
})
end, opts)
-- Additional fzf-lua mappings
map('n', '<leader>fr', function() fzf.grep_project() end, opts)
map('n', '<leader>fb', function() fzf.buffers() end, opts)
map('n', '<leader>fh', function() fzf.help_tags() end, opts)
map('n', '<leader>fs', function() fzf.grep_cword() end, opts)
map('n', '<leader>fS',
function() fzf.grep_cword({fzf_opts = {["--exact"] = ""}}) end, opts)
map('n', '<leader>fc', function() fzf.lgrep_curbuf() end, opts)
map('n', '<leader>fC',
function() fzf.lgrep_curbuf({search = vim.fn.expand('<cword>')}) end,
opts)
map('n', '<leader>ft', function() fzf.treesitter() end, opts)
map('n', '<leader>fT', function()
local current_word = vim.fn.expand('<cword>')
-- Pass the word as the initial query and call with_nth to ensure proper matching
fzf.treesitter({fzf_opts = {["--query"] = current_word}})
end, opts)
map('n', '<leader>di', function() fzf.diagnostics_document() end, opts)
-- LSP related
map('n', '<leader>ld', function() fzf.lsp_document_symbols() end, opts)
map('n', '<leader>lD', function()
local current_word = vim.fn.expand('<cword>')
fzf.lsp_document_symbols({fzf_opts = {["--query"] = current_word}})
end, opts)
map('n', '<leader>lw', function() fzf.lsp_workspace_symbols() end, opts)
map('n', '<leader>lW', function()
local current_word = vim.fn.expand('<cword>')
fzf.lsp_workspace_symbols({fzf_opts = {["--query"] = current_word}})
end, opts)
map('n', '<leader>lr', function() fzf.lsp_references() end, opts)
-- Visual mode grep with selected text
map('v', '<leader>fG', function()
-- Get current visual selection by yanking to unnamed register
local saved_reg = vim.fn.getreg('"')
local saved_regtype = vim.fn.getregtype('"')
-- Yank current visual selection
vim.cmd('normal! y')
-- Get the yanked text
local selected_text = vim.fn.getreg('"')
-- Restore the original register
vim.fn.setreg('"', saved_reg, saved_regtype)
-- Use the text as-is without escaping to avoid double escaping issues
fzf.live_grep({
rg_opts = common_filter ..
" --no-heading --with-filename --line-number --column --smart-case",
search = selected_text
})
end, opts)
-- Resume
map('n', '<leader>tr', function() fzf.resume() end, opts)
end