From cee10964f04916939121e9b6fc07d814cab1a0e3 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 2 Mar 2023 13:25:23 +0100 Subject: [PATCH] Replace neovim telescope with fzf I've added fzf to zsh and don't want to have multiple different solutions for same problem. I therefore use fzf-lua within neovim which replaces telescope. --- home/programs/neovim.nix | 21 ++---------- .../lua/telescope/_extensions/custom_runs.lua | 32 ------------------- .../neovim/configuration/plugin/functions.vim | 4 +-- .../neovim/configuration/plugin/mappings.vim | 11 +++---- home/programs/neovim/plugins/fzf-lua.lua | 16 ++++++++++ .../plugins/telescope-ctags-outline.lua | 18 ----------- home/programs/neovim/plugins/telescope.lua | 31 ------------------ 7 files changed, 25 insertions(+), 108 deletions(-) delete mode 100644 home/programs/neovim/configuration/lua/telescope/_extensions/custom_runs.lua create mode 100644 home/programs/neovim/plugins/fzf-lua.lua delete mode 100644 home/programs/neovim/plugins/telescope-ctags-outline.lua delete mode 100644 home/programs/neovim/plugins/telescope.lua diff --git a/home/programs/neovim.nix b/home/programs/neovim.nix index 421f162..eef9034 100644 --- a/home/programs/neovim.nix +++ b/home/programs/neovim.nix @@ -162,17 +162,6 @@ let ]; }; - telescope-ctags-outline = pkgs.vimUtils.buildVimPluginFrom2Nix rec { - pname = "telescope-ctags-outline"; - version = "35b2df9545f72352502703ba06b7ab711fa25e51"; - src = pkgs.fetchFromGitHub { - owner = "fcying"; - repo = "${pname}.nvim"; - rev = version; - sha256 = "e8QcD7H2unmoaLaN1JUxtOGQYBJGAXtfSnj8sW66ff4="; - }; - }; - in { enable = true; @@ -225,15 +214,9 @@ in { } { - plugin = telescope-nvim; + plugin = fzf-lua; type = "lua"; - config = builtins.readFile(./neovim/plugins/telescope.lua); - } - - { - plugin = telescope-ctags-outline; - type = "lua"; - config = builtins.readFile(./neovim/plugins/telescope-ctags-outline.lua); + config = builtins.readFile(./neovim/plugins/fzf-lua.lua); } dressing-nvim diff --git a/home/programs/neovim/configuration/lua/telescope/_extensions/custom_runs.lua b/home/programs/neovim/configuration/lua/telescope/_extensions/custom_runs.lua deleted file mode 100644 index 64ba0da..0000000 --- a/home/programs/neovim/configuration/lua/telescope/_extensions/custom_runs.lua +++ /dev/null @@ -1,32 +0,0 @@ -local telescope = require('telescope') -local pickers = require('telescope.pickers') -local finders = require('telescope.finders') -local actions = require('telescope.actions') -local action_state = require('telescope.actions.state') -local conf = require('telescope.config').values - -local custom_runs = function(opts) - opts = opts or {} - - local results = { 'CopyFileName', 'CopyRelativeFilePath', 'CopyFullFilePath' } - - pickers.new(opts, { - prompt_title = 'Custom Runs', - finder = finders.new_table { - results = results - }, - sorter = conf.generic_sorter(opts), - attach_mappings = function(prompt_bufnr, map) - actions.select_default:replace(function() - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - vim.api.nvim_call_function(selection[1], {}) - end) - return true - end, - }):find() -end - -return telescope.register_extension({ - exports = { custom_runs = custom_runs }, -}) diff --git a/home/programs/neovim/configuration/plugin/functions.vim b/home/programs/neovim/configuration/plugin/functions.vim index 40ace12..36b35dd 100644 --- a/home/programs/neovim/configuration/plugin/functions.vim +++ b/home/programs/neovim/configuration/plugin/functions.vim @@ -113,7 +113,7 @@ function! StartProfiling() execute(':profile file *') endfunc -function! TelescopeCurrentComposerPackage() +function! FilesInCurrentComposerPackage() let l:filePath = split(expand('%:p:h'), '/') while !filereadable('/' . join(l:filePath + ['composer.json'], '/')) && len(l:filePath) @@ -121,7 +121,7 @@ function! TelescopeCurrentComposerPackage() endwhile if len(l:filePath) - execute(':Telescope find_files cwd=/' . join(l:filePath, '/')) + execute("lua require ('fzf-lua').files({cwd='/" . join(l:filePath, '/') . "'})") else echom 'No composer package detected.' endif diff --git a/home/programs/neovim/configuration/plugin/mappings.vim b/home/programs/neovim/configuration/plugin/mappings.vim index 0bdd96b..eaf8c7f 100644 --- a/home/programs/neovim/configuration/plugin/mappings.vim +++ b/home/programs/neovim/configuration/plugin/mappings.vim @@ -10,12 +10,11 @@ nnoremap v :set paste! nnoremap nh :nohlsearch " Configure navigation, e.g. go to buffer, file, ... -nnoremap pp :lua require('telescope.builtin').builtin({ include_extensions = true }) -nnoremap pf :Telescope git_files -nnoremap pb :Telescope buffers -nnoremap pt :Telescope ctags_outline outline -nnoremap pr :Telescope custom_runs -nnoremap pc :call TelescopeCurrentComposerPackage() +nnoremap pp :lua require('fzf-lua').builtin() +nnoremap pf :lua require('fzf-lua').git_files() +nnoremap pb :lua require('fzf-lua').buffers() +nnoremap pt :lua require('fzf-lua').btags() +nnoremap pc :call FilesInCurrentComposerPackage() " lca = lsp code action nnoremap lca :lua vim.lsp.buf.code_action() diff --git a/home/programs/neovim/plugins/fzf-lua.lua b/home/programs/neovim/plugins/fzf-lua.lua new file mode 100644 index 0000000..528621a --- /dev/null +++ b/home/programs/neovim/plugins/fzf-lua.lua @@ -0,0 +1,16 @@ +require("fzf-lua").setup({ + fzf_bin = "fzf-tmux", + fzf_tmux_opts = { + ["-p"] = "", + ["-y"] = "1", + ["-w"] = "95%", + ["-h"] = "75%", + }, + winopts = { + preview = { + hidden = "hidden", -- I don't like a preview, keep space for selection + }, + }, +}) + +require("fzf-lua").register_ui_select() diff --git a/home/programs/neovim/plugins/telescope-ctags-outline.lua b/home/programs/neovim/plugins/telescope-ctags-outline.lua deleted file mode 100644 index a47b1d6..0000000 --- a/home/programs/neovim/plugins/telescope-ctags-outline.lua +++ /dev/null @@ -1,18 +0,0 @@ -require('telescope').setup({ - extensions = { - ctags_outline = { - ctags = { 'ctags' }, - ft_opt = { - css = '--css-types=vcit', - fluid = '--xml-types=si', - markdown = '--Markdown-types=csStT', - rst = '--reStructuredText-types=csSt', - sql = '--SQL-types=tE', - xml = '--xml-types=ci', - yaml = '--Yaml-types=t', - }, - }, - }, -}) - -require('telescope').load_extension('ctags_outline') diff --git a/home/programs/neovim/plugins/telescope.lua b/home/programs/neovim/plugins/telescope.lua deleted file mode 100644 index 3c83066..0000000 --- a/home/programs/neovim/plugins/telescope.lua +++ /dev/null @@ -1,31 +0,0 @@ -local telescope = require('telescope') -local actions = require('telescope.actions') -local actionsLayout = require('telescope.actions.layout') - -telescope.setup({ - defaults = { - layout_strategy = 'center', - layout_config = { - width = 0.6, - }, - sorting_strategy = 'ascending', - default_mappings = { - i = { - [""] = actions.move_selection_next, - [""] = actions.move_selection_previous, - [""] = actions.close, - - [""] = actions.select_default, - [""] = actions.which_key, - [""] = actions.select_vertical, - - [""] = actionsLayout.toggle_preview, - }, - }, - - preview = { - hide_on_startup = true, - }, - }, -}) -telescope.load_extension('custom_runs')