From 447d4e50b5c9333d5211efca957d9a8c3cfdfc95 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Sun, 6 Feb 2022 17:47:31 +0530 Subject: [PATCH] nvim: plugins: Switch to fzf-lua --- nvim/.config/nvim/after/plugin/fzf-lua.lua | 323 ++++++++++++++++++ .../.config/nvim/after/plugin/fzf-preview.lua | 12 - nvim/.config/nvim/after/plugin/fzf.vim | 58 ---- nvim/.config/nvim/lua/plugins.lua | 7 +- 4 files changed, 324 insertions(+), 76 deletions(-) create mode 100644 nvim/.config/nvim/after/plugin/fzf-lua.lua delete mode 100644 nvim/.config/nvim/after/plugin/fzf-preview.lua delete mode 100644 nvim/.config/nvim/after/plugin/fzf.vim diff --git a/nvim/.config/nvim/after/plugin/fzf-lua.lua b/nvim/.config/nvim/after/plugin/fzf-lua.lua new file mode 100644 index 0000000..71412cb --- /dev/null +++ b/nvim/.config/nvim/after/plugin/fzf-lua.lua @@ -0,0 +1,323 @@ +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, + }, + }, + bcommits = { + prompt = 'BCommits❯ ', + cmd = "git log --decorate --pretty=oneline --abbrev-commit --color", + preview = "git show --color=always {1}", + actions = { + ["default"] = actions.git_buf_edit, + ["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', 'b' , ':FzfLua buffers' , opts) +remap('n', 'B' , ':FzfLua oldfiles' , opts) +remap('n', 'fF', ':FzfLua files' , opts) +remap('n', 'fl', ':FzfLua blines' , opts) +remap('n', 'fL', ':FzfLua lines' , opts) +remap('n', 'fq', ':cclose:FzfLua quickfix' , opts) +remap('n', 'fQ', ':lclose:FzfLua loclist' , opts) + +-- Git +remap('n', 'ff', ':FzfLua git_files' , opts) +remap('n', '/' , ':FzfLua git_status' , opts) +remap('n', 'fb', ':FzfLua git_branches' , opts) +remap('n', 'fc', ':FzfLua git_bcommits' , opts) +remap('n', 'fC', ':FzfLua git_commits' , opts) + +-- Grep +remap('n', 'fg' , ':FzfLua grep' , opts) +remap('n', 'f/' , ':FzfLua live_grep' , opts) +remap('n', 'f\\', ':FzfLua live_grep_resume' , opts) +remap('n', 'fs' , ':FzfLua grep_cword' , opts) +remap('n', 'fS' , ':FzfLua grep_cWORD' , opts) +remap('x', 'fs' , ':FzfLua grep_visual' , opts) +remap('n', 'fr' , ':FzfLua grep_last' , opts) +remap('n', 'fR' , ':FzfLua live_grep_glob' , opts) + +-- Misc +remap('n', 'fh', ':FzfLua command_history' , opts) +remap('n', 'fH', ':FzfLua search_history' , opts) +remap('n', 'fm', ':FzfLua marks' , opts) +remap('n', 'fM', ':FzfLua man_pages' , opts) +remap('n', 'fo', ':FzfLua changes' , opts) +remap('n', 'fO', ':FzfLua jumps' , opts) +remap('n', 'fk', ':FzfLua keymaps' , opts) + +-- LSP +remap('n', 'lr', ':FzfLua lsp_references' , opts) +remap('n', 'ld', ':FzfLua lsp_definitions' , opts) +remap('n', 'lD', ':FzfLua lsp_declarations' , opts) +remap('n', 'lt', ':FzfLua lsp_typedefs' , opts) +remap('n', 'li', ':FzfLua lsp_implementations' , opts) +remap('n', 'ls', ':FzfLua lsp_document_symbols' , opts) +remap('n', 'lw', ':FzfLua lsp_workspace_symbols' , opts) +remap('n', 'lW', ':FzfLua lsp_live_workspace_symbols', opts) +remap('n', 'la', ':FzfLua lsp_code_actions' , opts) +remap('n', 'le', ':FzfLua lsp_document_diagnostics' , opts) +remap('n', 'lE', ':FzfLua lsp_workspace_diagnostics' , opts) diff --git a/nvim/.config/nvim/after/plugin/fzf-preview.lua b/nvim/.config/nvim/after/plugin/fzf-preview.lua deleted file mode 100644 index 7257483..0000000 --- a/nvim/.config/nvim/after/plugin/fzf-preview.lua +++ /dev/null @@ -1,12 +0,0 @@ -local remap = vim.api.nvim_set_keymap - -remap('n', 'fg', ':FZFGGrep', { noremap = true }) -remap('n', 'fG', ':FZFGrep', { noremap = true }) -remap('n', 'fl', ':FZFBLines', { noremap = true }) -remap('n', 'f\\', ':FZFRg', { noremap = true }) -remap('n', 'fT', ':FZFTags', { noremap = true }) -remap('n', 'fq', ':cclose:FZFQuickFix', { noremap = true }) -remap('n', 'fQ', ':lclose:FZFLocList', { noremap = true }) -remap('n', 'fS', ':FZFRg ', { noremap = true }) -remap('x', 'fS', '"zy:FZFRg z', { noremap = true }) -remap('n', 'ft', ':FZFTags ', { noremap = true }) diff --git a/nvim/.config/nvim/after/plugin/fzf.vim b/nvim/.config/nvim/after/plugin/fzf.vim deleted file mode 100644 index f2ff123..0000000 --- a/nvim/.config/nvim/after/plugin/fzf.vim +++ /dev/null @@ -1,58 +0,0 @@ -" See https://github.com/junegunn/fzf/blob/master/README-VIM.md -" An action can be a reference to a function that processes selected lines -function! s:build_quickfix_list(lines) - call setqflist([], ' ', { 'title': 'FZF Selected', 'items': map(copy(a:lines), '{ "filename": v:val }') }) - copen - cc -endfunction - -" https://github.com/junegunn/fzf.vim/pull/733 -function! s:list_buffers() - redir => list - silent ls - redir END - return split(list, "\n") -endfunction - -function! s:delete_buffers(lines) - execute 'bwipeout' join(map(a:lines, {_, line -> split(line)[0]})) -endfunction - -command! BD call fzf#run(fzf#wrap({ - \ 'source': s:list_buffers(), - \ 'sink*': { lines -> s:delete_buffers(lines) }, - \ 'options': '--multi --reverse --bind ctrl-a:select-all+accept' -\ })) - -let g:fzf_action = { -\ 'ctrl-q': function('s:build_quickfix_list'), -\ 'ctrl-t': 'tab split', -\ 'ctrl-x': 'split', -\ 'ctrl-v': 'vsplit', -\ } - -let $FZF_DEFAULT_OPTS = '--layout=reverse --bind "Ctrl-d:half-page-down,Ctrl-u:half-page-up,Ctrl-n:preview-down,Ctrl-p:preview-up,Ctrl-f:preview-page-down,Ctrl-b:preview-page-up,ctrl-a:select-all+accept"' -let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.8 }, } - -nnoremap b :Buffers -nnoremap B :History -nnoremap / :GFiles? -nnoremap ff :GFiles -nnoremap fF :Files -nnoremap fL :Lines -nnoremap fc :BCommits -nnoremap fC :Commits -nnoremap fh :History: -nnoremap fH :History/ -nnoremap fm :Marks -nnoremap fo :Locate -nnoremap fk :Maps -nnoremap f/ :Rg -nnoremap fs :Rg -xnoremap fs "zy:Rg z -nnoremap fw :BD - -imap (fzf-complete-word) -imap (fzf-complete-path) -imap (fzf-complete-file) -imap (fzf-complete-line) diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 8f6e82d..18c2a2c 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -7,11 +7,7 @@ local init = function () -- Vertical Motion use 'phaazon/hop.nvim' -- Search - use { - 'junegunn/fzf', - run = './install --bin' - } - use 'junegunn/fzf.vim' + use 'ibhagwan/fzf-lua' use 'bronson/vim-visual-star-search' -- Manage Project sessions use 'rmagatti/auto-session' @@ -31,7 +27,6 @@ local init = function () -- Boost vim command line mode use 'vim-utils/vim-husk' -- Quickfix - use 'chengzeyi/fzf-preview.vim' use { 'https://gitlab.com/yorickpeterse/nvim-pqf', config = function()