lines|blines|grep_curbuf|lgrep_curbuf: hide filename by default

fix help buffer syntax highlighting in blines|buffer preview
main
bhagwan 2 years ago
parent 253b9413eb
commit 1d6ea8d381

@ -504,11 +504,36 @@ require'fzf-lua'.setup {
["ctrl-x"] = actions.buf_del,
}
},
lines = {
previewer = "builtin", -- set to 'false' to disable
prompt = 'Lines ',
show_unlisted = false, -- exclude 'help' buffers
no_term_buffers = true, -- exclude 'term' buffers
fzf_opts = {
-- do not include bufnr in fuzzy matching
-- tiebreak by line no.
['--delimiter'] = vim.fn.shellescape(']'),
["--nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = {
["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split,
["ctrl-v"] = actions.buf_vsplit,
["ctrl-t"] = actions.buf_tabedit,
}
},
blines = {
previewer = "builtin", -- set to 'false' to disable
prompt = 'BLines ',
show_unlisted = true, -- include 'help' buffers
no_term_buffers = false, -- include 'term' buffers
fzf_opts = {
-- hide filename, tiebreak by line no.
['--delimiter'] = vim.fn.shellescape('[:]'),
["--with-nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = {
["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split,

@ -538,11 +538,36 @@ Consult the list below for available settings:
["ctrl-x"] = actions.buf_del,
}
},
lines = {
previewer = "builtin", -- set to 'false' to disable
prompt = 'Lines ',
show_unlisted = false, -- exclude 'help' buffers
no_term_buffers = true, -- exclude 'term' buffers
fzf_opts = {
-- do not include bufnr in fuzzy matching
-- tiebreak by line no.
['--delimiter'] = vim.fn.shellescape(']'),
["--nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = {
["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split,
["ctrl-v"] = actions.buf_vsplit,
["ctrl-t"] = actions.buf_tabedit,
}
},
blines = {
previewer = "builtin", -- set to 'false' to disable
prompt = 'BLines ',
show_unlisted = true, -- include 'help' buffers
no_term_buffers = false, -- include 'term' buffers
fzf_opts = {
-- hide filename, tiebreak by line no.
['--delimiter'] = vim.fn.shellescape('[:]'),
["--with-nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = {
["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split,

@ -324,6 +324,13 @@ M.globals.lines = {
prompt = 'Lines> ',
file_icons = true and M._has_devicons,
color_icons = true,
show_unlisted = false,
no_term_buffers = true,
fzf_opts = {
['--delimiter'] = vim.fn.shellescape(']'),
["--nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = {
["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split,
@ -338,6 +345,11 @@ M.globals.blines = {
color_icons = true,
show_unlisted = true,
no_term_buffers = false,
fzf_opts = {
['--delimiter'] = vim.fn.shellescape('[:]'),
["--with-nth"] = '2..',
["--tiebreak"] = 'index',
},
actions = {
["default"] = actions.buf_edit,
["ctrl-s"] = actions.buf_split,

@ -170,7 +170,7 @@ function M.entry_to_file(entry, cwd)
if bufnr then
terminal = utils.is_term_buffer(bufnr)
if terminal then
file, line = stripped:match("(.*):(%d+)$")
file, line = stripped:match("([^:]+):(%d+)")
end
end
return {

@ -252,6 +252,7 @@ function Previewer.buffer_or_file:populate_preview_buf(entry_str)
else --]]
-- mark the buffer for unloading the next call
self.preview_bufloaded = true
entry.filetype = vim.api.nvim_buf_get_option(entry.bufnr, 'filetype')
local lines = vim.api.nvim_buf_get_lines(entry.bufnr, 0, -1, false)
vim.api.nvim_buf_set_lines(self.preview_bufnr, 0, -1, false, lines)
-- end
@ -335,11 +336,19 @@ function Previewer.buffer_or_file:do_syntax(entry)
))
end
if syntax_limit_reached == 0 then
-- prepend the buffer number to the path and
-- set as buffer name, this makes sure 'filetype detect'
-- gets the right filetype which enables the syntax
local tempname = path.join({tostring(bufnr), entry.path})
pcall(api.nvim_buf_set_name, bufnr, tempname)
if entry.filetype and #entry.filetype>0 then
-- filetype was saved from a loaded buffer
-- this helps avoid losing highlights for help buffers
-- which are '.txt' files with 'ft=help'
-- api.nvim_buf_set_option(bufnr, 'filetype', entry.filetype)
pcall(api.nvim_buf_set_option, bufnr, 'filetype', entry.filetype)
else
-- prepend the buffer number to the path and
-- set as buffer name, this makes sure 'filetype detect'
-- gets the right filetype which enables the syntax
local tempname = path.join({tostring(bufnr), entry.path})
pcall(api.nvim_buf_set_name, bufnr, tempname)
end
-- nvim_buf_call has less side-effects than window switch
api.nvim_buf_call(bufnr, function()
vim.cmd('filetype detect')

@ -205,9 +205,6 @@ end
M.buffer_lines = function(opts)
if not opts then return end
if opts.no_term_buffers == nil then
opts.no_term_buffers = true
end
local buffers = filter_buffers(opts,
opts.current_buffer_only and { vim.api.nvim_get_current_buf() } or
vim.api.nvim_list_bufs())
@ -249,9 +246,6 @@ M.buffer_lines = function(opts)
-- disable multi-select
opts.fzf_opts["--no-multi"] = ''
opts.fzf_opts["--preview-window"] = 'hidden:right:0'
opts.fzf_opts["--delimiter"] = vim.fn.shellescape(']')
opts.fzf_opts["--nth"] = '2,-1'
opts.fzf_opts["--tiebreak"] = 'index'
if opts.search and #opts.search>0 then
opts.fzf_opts['--query'] = vim.fn.shellescape(opts.search)

@ -349,8 +349,10 @@ M.grep_curbuf = function(opts)
if opts.exec_empty_query == nil then
opts.exec_empty_query = true
end
opts.fzf_opts = vim.tbl_extend("keep",
opts.fzf_opts or {}, config.globals.blines.fzf_opts)
opts.filename = vim.api.nvim_buf_get_name(0)
if #opts.filename > 0 then
if #opts.filename > 0 and vim.loop.fs_stat(opts.filename) then
opts.filename = path.relative(opts.filename, vim.loop.cwd())
if opts.lgrep then
return M.live_grep(opts)
@ -359,7 +361,7 @@ M.grep_curbuf = function(opts)
return M.grep(opts)
end
else
utils.info("Rg current buffer requires actual file on disk")
utils.info("Rg current buffer requires file on disk")
return
end
end

Loading…
Cancel
Save