dotfiles/nvim/.config/nvim/after/plugin/fzf-lua.lua

324 lines
10 KiB
Lua
Raw Normal View History

2022-02-06 13:17:31 +01:00
local actions = require "fzf-lua.actions"
local remap = vim.api.nvim_set_keymap
local opts = { noremap=true, unique=true, silent=true }
require'fzf-lua'.setup {
global_resume = true,
global_resume_query = true,
winopts = {
height = 0.90,
width = 0.90,
row = 0.35,
col = 0.50,
border = { '', '', '', '', '', '', '', '' },
fullscreen = false,
hl = {
normal = 'Normal',
border = 'Normal',
cursor = 'Cursor',
cursorline = 'CursorLine',
search = 'Search',
title = 'Normal',
scrollbar_f = 'PmenuThumb',
scrollbar_e = 'PmenuSbar',
},
preview = {
default = 'bat',
border = 'border',
wrap = 'nowrap',
hidden = 'nohidden',
vertical = 'down:45%',
horizontal = 'right:60%',
layout = 'flex',
flip_columns = 120,
title = false,
scrollbar = false,
scrolloff = '-2',
scrollchars = {'', '' },
delay = 100,
winopts = {
number = true,
relativenumber = false,
cursorline = true,
cursorlineopt = 'both',
cursorcolumn = false,
signcolumn = 'no',
list = false,
foldenable = false,
foldmethod = 'manual',
},
},
},
keymap = {
fzf = {
["Ctrl-d"] = "half-page-down" ,
["Ctrl-u"] = "half-page-up" ,
["Ctrl-a"] = "beginning-of-line",
["Ctrl-e"] = "end-of-line" ,
["Ctrl-n"] = "preview-down" ,
["Ctrl-p"] = "preview-up" ,
["Ctrl-f"] = "preview-page-down",
["Ctrl-b"] = "preview-page-up" ,
["Ctrl-z"] = "abort" ,
["Ctrl-t"] = "toggle-all" ,
},
},
actions = {
files = {
["default"] = actions.file_edit_or_qf,
["ctrl-s"] = actions.file_split ,
["ctrl-v"] = actions.file_vsplit ,
["ctrl-t"] = actions.file_tabedit ,
["ctrl-q"] = actions.file_sel_to_qf ,
},
buffers = {
["default"] = actions.buf_edit ,
["ctrl-s"] = actions.buf_split ,
["ctrl-v"] = actions.buf_vsplit ,
["ctrl-t"] = actions.buf_tabedit,
}
},
fzf_opts = {
['--ansi'] = '',
['--prompt'] = '> ',
['--info'] = 'inline',
['--height'] = '100%',
['--layout'] = 'reverse',
},
previewers = {
cat = {
cmd = "cat",
args = "--number",
},
bat = {
cmd = "bat",
args = "--style=numbers,changes --color always",
theme = 'Monokai Extended Bright',
config = nil,
},
head = {
cmd = "head",
args = nil,
},
git_diff = {
cmd_deleted = "git diff --color HEAD --",
cmd_modified = "git diff --color HEAD",
cmd_untracked = "git diff --color --no-index /dev/null",
},
man = {
cmd = "man -c %s | col -bx",
},
builtin = {
syntax = true,
syntax_limit_l = 0,
syntax_limit_b = 1024*1024,
},
},
files = {
previewer = "bat",
prompt = 'Files ',
multiprocess = true,
git_icons = false,
file_icons = false,
color_icons = false,
find_opts = [[-type f -not -path '*/\.git/*' -printf '%P\n']],
rg_opts = "--color=never --files --hidden --follow -g '!.git'",
fd_opts = "--color=never --type f --hidden --follow --exclude .git",
actions = {
["default"] = actions.file_edit,
}
},
git = {
files = {
prompt = 'GitFiles ',
cmd = 'git ls-files --exclude-standard',
multiprocess = true,
git_icons = false,
file_icons = false,
color_icons = false,
},
status = {
prompt = 'GitStatus ',
cmd = "git status -s",
previewer = "git_diff",
file_icons = false,
git_icons = false,
color_icons = false,
actions = {
["right"] = { actions.git_unstage, actions.resume },
["left"] = { actions.git_stage, actions.resume },
},
},
commits = {
prompt = 'Commits ',
cmd = "git log --decorate --pretty=oneline --abbrev-commit --color",
preview = "git show --color=always {1}",
actions = {
["default"] = actions.git_checkout,
2022-02-06 13:17:31 +01:00
},
},
bcommits = {
prompt = 'BCommits ',
cmd = "git log --decorate --pretty=oneline --abbrev-commit --color",
preview = "git show --color=always {1}",
actions = {
["default"] = actions.git_buf_edit,
2022-02-06 13:17:31 +01:00
["ctrl-s"] = actions.git_buf_split,
["ctrl-v"] = actions.git_buf_vsplit,
["ctrl-t"] = actions.git_buf_tabedit,
},
},
branches = {
prompt = 'Branches ',
cmd = "git branch --all --color",
preview = "git log --decorate --graph --pretty=oneline --abbrev-commit --color {1}",
actions = {
["default"] = actions.git_switch,
},
},
icons = {
["M"] = { icon = "M", color = "yellow" },
["D"] = { icon = "D", color = "red" },
["A"] = { icon = "A", color = "green" },
["R"] = { icon = "R", color = "yellow" },
["C"] = { icon = "C", color = "yellow" },
["?"] = { icon = "?", color = "magenta" },
},
},
grep = {
prompt = 'Rg ',
input_prompt = 'Grep For ',
multiprocess = true,
git_icons = false,
file_icons = false,
color_icons = false,
rg_opts = "--column --line-number --no-heading --color=always --smart-case --max-columns=512",
grep_opts = "--binary-files=without-match --line-number --recursive --color=auto --perl-regexp",
glob_flag = "--iglob",
glob_separator = "%s%-%-"
},
args = {
prompt = 'Args ',
files_only = true,
actions = { ["ctrl-x"] = actions.arg_del }
},
oldfiles = {
prompt = 'History ',
cwd_only = false,
},
buffers = {
prompt = 'Buffers ',
file_icons = false,
color_icons = false,
sort_lastused = true,
actions = {
["ctrl-x"] = { actions.buf_del, actions.resume },
}
},
tabs = {
prompt = 'Tabs ',
tab_title = "Tab",
tab_marker = "<<",
file_icons = false,
color_icons = false,
actions = {
["default"] = actions.buf_switch,
["ctrl-x"] = { actions.buf_del, actions.resume },
},
},
lines = {
previewer = "builtin",
prompt = 'Lines ',
show_unlisted = false,
no_term_buffers = true,
fzf_opts = {
['--delimiter'] = vim.fn.shellescape(']'),
["--nth"] = '2..',
["--tiebreak"] = 'index',
},
},
blines = {
previewer = "builtin",
prompt = 'BLines ',
show_unlisted = true,
no_term_buffers = true,
fzf_opts = {
['--delimiter'] = vim.fn.shellescape('[:]'),
["--with-nth"] = '2..',
["--tiebreak"] = 'index',
},
},
quickfix = {
file_icons = false,
git_icons = false,
},
lsp = {
prompt_postfix = 'Lsp ',
cwd_only = false,
async_or_timeout = 5000,
file_icons = false,
git_icons = false,
lsp_icons = true,
severity = "hint",
icons = {
["Error"] = { icon = "E:", color = "red" },
["Warning"] = { icon = "W:", color = "yellow" },
["Information"] = { icon = "I:", color = "blue" },
["Hint"] = { icon = "H:", color = "magenta" },
},
},
file_icon_padding = '',
file_icon_colors = {
["lua"] = "blue",
},
manpages = { previewer = { _ctor = require'fzf-lua.previewer'.fzf.man_pages } },
}
-- Buffers and Files
remap('n', '<Leader>b' , ':FzfLua buffers<CR>' , opts)
remap('n', '<Leader>B' , ':FzfLua oldfiles<CR>' , opts)
remap('n', '<Leader>fF', ':FzfLua files<CR>' , opts)
remap('n', '<Leader>fl', ':FzfLua blines<CR>' , opts)
remap('n', '<Leader>fL', ':FzfLua lines<CR>' , opts)
remap('n', '<Leader>fq', ':cclose<CR>:FzfLua quickfix<CR>' , opts)
remap('n', '<Leader>fQ', ':lclose<CR>:FzfLua loclist<CR>' , opts)
-- Git
remap('n', '<Leader>ff', ':FzfLua git_files<CR>' , opts)
remap('n', '<Leader>/' , ':FzfLua git_status<CR>' , opts)
remap('n', '<Leader>fb', ':FzfLua git_branches<CR>' , opts)
remap('n', '<Leader>fc', ':FzfLua git_bcommits<CR>' , opts)
remap('n', '<Leader>fC', ':FzfLua git_commits<CR>' , opts)
-- Grep
remap('n', '<Leader>fg' , ':FzfLua grep<CR>' , opts)
remap('n', '<Leader>f/' , ':FzfLua live_grep<CR>' , opts)
remap('n', '<Leader>f\\', ':FzfLua live_grep_resume<CR>' , opts)
remap('n', '<Leader>fs' , ':FzfLua grep_cword<CR>' , opts)
remap('n', '<Leader>fS' , ':FzfLua grep_cWORD<CR>' , opts)
remap('x', '<Leader>fs' , ':<C-u>FzfLua grep_visual<CR>' , opts)
remap('n', '<Leader>fr' , ':FzfLua grep_last<CR>' , opts)
remap('n', '<Leader>fR' , ':FzfLua live_grep_glob<CR>' , opts)
-- Misc
remap('n', '<Leader>fh', ':FzfLua command_history<CR>' , opts)
remap('n', '<Leader>fH', ':FzfLua search_history<CR>' , opts)
remap('n', '<Leader>fm', ':FzfLua marks<CR>' , opts)
remap('n', '<Leader>fM', ':FzfLua man_pages<CR>' , opts)
remap('n', '<Leader>fo', ':FzfLua changes<CR>' , opts)
remap('n', '<Leader>fO', ':FzfLua jumps<CR>' , opts)
remap('n', '<Leader>fk', ':FzfLua keymaps<CR>' , opts)
-- LSP
remap('n', '<Leader>lr', ':FzfLua lsp_references<CR>' , opts)
remap('n', '<Leader>ld', ':FzfLua lsp_definitions<CR>' , opts)
remap('n', '<Leader>lD', ':FzfLua lsp_declarations<CR>' , opts)
remap('n', '<Leader>lt', ':FzfLua lsp_typedefs<CR>' , opts)
remap('n', '<Leader>li', ':FzfLua lsp_implementations<CR>' , opts)
remap('n', '<Leader>ls', ':FzfLua lsp_document_symbols<CR>' , opts)
remap('n', '<Leader>lw', ':FzfLua lsp_workspace_symbols<CR>' , opts)
remap('n', '<Leader>lW', ':FzfLua lsp_live_workspace_symbols<CR>', opts)
remap('n', '<Leader>la', ':FzfLua lsp_code_actions<CR>' , opts)
remap('n', '<Leader>le', ':FzfLua lsp_document_diagnostics<CR>' , opts)
remap('n', '<Leader>lE', ':FzfLua lsp_workspace_diagnostics<CR>' , opts)