nvim-telescope / telescope-live-grep-args.nvim

Live grep with args
726 stars 40 forks source link

Can't configure keymap for shortcurs #58

Closed karambaq closed 1 year ago

karambaq commented 1 year ago

I've tried several options like this:

    {
      "gt",
      function() require("telescope").extensions.live_grep_args.shortcuts.grep_word_under_cursor() end,
      -- function() require("telescope-live-grep-args.live_grep_args_shortcuts").grep_word_under_cursor() end,
      desc = "Find for word under cursor",
    },

Error is:

5108: Error executing lua: ...m/lazy/telescope.nvim/lua/telescope/_extensions/init.lua:10: 'live_grep_args_shortcuts' extension doesn't exist or isn't installed: modu
le 'telescope._extensions.live_grep_args_shortcuts' not found:
        no field package.preload['telescope._extensions.live_grep_args_shortcuts']
cache_loader: module telescope._extensions.live_grep_args_shortcuts not found
cache_loader_lib: module telescope._extensions.live_grep_args_shortcuts not found
        no file './telescope/_extensions/live_grep_args_shortcuts.lua'
        no file '/usr/local/share/luajit-2.1.0-beta3/telescope/_extensions/live_grep_args_shortcuts.lua'
        no file '/usr/local/share/lua/5.1/telescope/_extensions/live_grep_args_shortcuts.lua'
        no file '/usr/local/share/lua/5.1/telescope/_extensions/live_grep_args_shortcuts/init.lua'
        no file './telescope/_extensions/live_grep_args_shortcuts.so'
        no file '/usr/local/lib/lua/5.1/telescope/_extensions/live_grep_args_shortcuts.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './telescope.so'
        no file '/usr/local/lib/lua/5.1/telescope.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'error'
        ...m/lazy/telescope.nvim/lua/telescope/_extensions/init.lua:10: in function 'load_extension'
        ...m/lazy/telescope.nvim/lua/telescope/_extensions/init.lua:17: in function '__index'

My whole config:

-- local Util = require "utils"
local fzf_opts = {
  fuzzy = true,                   -- false will only do exact matching
  override_generic_sorter = true, -- override the generic sorter
  override_file_sorter = true,    -- override the file sorter
  case_mode = "smart_case",       -- or "ignore_case" or "respect_case"
  -- the default case_mode is "smart_case"
}
local M = {
  "nvim-telescope/telescope.nvim",
  lazy = false,
  dependencies = {
    { "nvim-lua/popup.nvim" },
    { "nvim-lua/plenary.nvim" },
    { "cljoly/telescope-repo.nvim" },
    { "nvim-telescope/telescope-dap.nvim" },
    { "nvim-telescope/telescope-fzf-native.nvim",    build = "make" },
    { "nvim-telescope/telescope-file-browser.nvim" },
    -- { "nvim-telescope/telescope-fzy-native.nvim" },
    { "nvim-telescope/telescope-live-grep-args.nvim" },
  },
  keys = {
    -- disable the keymap to grep files
    -- { "<leader>/", false },
    --
    -- { "<leader><leader>", false },
    { "<leader><space>", "<cmd>Telescope live_grep_args<cr>", desc = "Find live_grep_args" },
    {
      "gt",
      function() require("telescope").extensions.live_grep_args.shortcuts.grep_word_under_cursor() end,
      -- function() require("telescope-live-grep-args.live_grep_args_shortcuts").grep_word_under_cursor() end,
      desc = "Find for word under cursor",
    },
    {
      "<leader>fw",
      function() require("telescope.builtin").grep_string() end,
      desc = "Find for word under cursor",
    },
    {
      "<leader>fc",
      function() require("telescope.builtin").treesitter() end,
      desc = "Find class/func inside current file",
    },
    {
      "<leader>gb",
      function() require("telescope.builtin").git_branches() end,
      desc = "Git checkout",
    },
    {
      "<leader>f<CR>",
      function() require("telescope.builtin").resume() end,
      desc = "Resume search",
    },
    {
      "<leader>fs",
      function()
        local aerial_avail, _ = pcall(require, "aerial")
        if aerial_avail then
          require("telescope").extensions.aerial.aerial()
        else
          require("telescope.builtin").lsp_document_symbols()
        end
      end,
      desc = "Find symbols",
    },
    { "<leader>fb",      "<cmd>Telescope buffers<cr>",        desc = "Buffers" },
    -- { "<leader>fF", Util.telescope "files", desc = "Find Files (root dir)" },
    -- { "<leader>ff", Util.telescope("files", { cwd = false }), desc = "Find Files (cwd)" },
    { "<leader>fR",      "<cmd>Telescope oldfiles<cr>",       desc = "Recent" },
    -- { "<leader>fr", Util.telescope("oldfiles", { cwd = vim.loop.cwd() }), desc = "Recent (cwd)" },
    { "<leader>fg",      "<cmd>Telescope git_status<cr>",     desc = "Find changed files" },
    {
      "<leader>fo",
      "<cmd>Telescope file_browser<cr>",
      { noremap = true },
      desc = "Open file browser",
    },
    -- {
    --   "<leader>sS",
    --   require("telescope.builtin").lsp_dynamic_workspace_symbols {
    --     symbols = {
    --       "Class",
    --       "Function",
    --       "Method",
    --     },
    --   },
    --   desc = "Goto Symbol",
    -- },
    {
      "<leader>sd",
      function()
        require("telescope.builtin").lsp_dynamic_workspace_symbols {
          symbols = {
            "Class",
            "Function",
            "Method",
            "Field",
          },
        }
      end,
      desc = "Goto Symbol",
    },

    -- require("telescope.builtin").find_files({ cwd = vim.fn.expand("%:p:h") })

    -- { "<leader>fm", require("browser-bookmarks").select, desc = "Fuzzy search browser bookmarks" },
    -- {
    --   "<leader>fr",
    --   {
    --     function()
    --       require("telescope.builtin").oldfiles()
    --     end,
    --     desc = "Find history",
    --   },
    -- },
    -- add a keymap to browse plugin files
  },
}

function M.config()
  local actions = require "telescope.actions"
  local trouble = require "trouble.providers.telescope"
  local telescope = require "telescope"
  local lga_actions = require "telescope-live-grep-args.actions"
  telescope.setup {
    defaults = {
      vimgrep_arguments = {
        "rg",
        "--color=never",
        "--no-heading",
        "--with-filename",
        "--line-number",
        "--column",
        "--smart-case",
      },
      layout_strategy = "horizontal",
      layout_config = {
        horizontal = {
          prompt_position = "bottom",
          preview_width = 0.55,
          results_width = 0.8,
        },
        -- vertical = {
        --   mirror = false,
        --   prompt_position = "bottom",
        --   preview_width = 0.55,
        --   results_width = 0.8,
        -- },
        width = 0.87,
        height = 0.80,
        preview_cutoff = 120,
      },
      prompt_prefix = "    ",
      -- prompt_prefix = "   ",
      selection_caret = "  ",
      winblend = 0,
      border = {},
      --   borderchars = {
      --     prompt = { "━", "┃", "━", "┃", "┏", "┓", "┛", "┗" },
      --     -- preview = {"━", "┃", "━", "┃", "┏", "┓", "┛", "┗"},
      --     -- results = {"━", "┃", "━", "┃", "┏", "┓", "┛", "┗"},
      --     -- prompt = {" ", " ", " ", " ", " ", " ", " ", " "},
      --     preview = { "─", "│", "─", "│", "┌", "┐", "┘", "└" },
      --     results = { "─", "│", "─", "│", "┌", "┐", "┘", "└" },
      --   },
      --   --[[ path_display = { "smart" }, ]]
      set_env = { ["COLORTERM"] = "truecolor" },
      mappings = {
        i = { ["<c-t>"] = trouble.open_with_trouble },
        --[[ n = { ["<c-t>"] = trouble.open_with_trouble }, ]]
      },
    },
    pickers = {
      -- Manually set sorter, for some reason not picked up automatically
      lsp_dynamic_workspace_symbols = {
        sorter = telescope.extensions.fzf.native_fzf_sorter(fzf_opts),
      },
    },
    extensions = {
      live_grep_args = {
        auto_quoting = true, -- enable/disable auto-quoting
        -- define mappings, e.g.
        mappings = {
          -- extend mappings
          i = {
            ["<C-k>"] = lga_actions.quote_prompt(),
            ["<C-i>"] = lga_actions.quote_prompt { postfix = " -F " },
          },
        },
        -- ... also accepts theme settings, for example:
        -- theme = "dropdown", -- use dropdown theme
        -- theme = { }, -- use own theme spec
        -- layout_config = { mirror=true }, -- mirror preview pane
      },
      -- fzy = {
      --   override_generic_sorter = false,
      --   override_file_sorter = true,
      --   case_mode = "smart_case",
      -- },

      fzf = {
        fuzzy = true,                   -- false will only do exact matching
        override_generic_sorter = true, -- override the generic sorter
        override_file_sorter = true,    -- override the file sorter
        case_mode = "smart_case",       -- or "ignore_case" or "respect_case"
      },
    },
  }

  -- Extensions

  telescope.load_extension "repo"
  -- telescope.load_extension "neoclip"
  telescope.load_extension "notify"
  telescope.load_extension "dap"
  telescope.load_extension "fzf"
  -- telescope.load_extension("fzy_native")
  telescope.load_extension "live_grep_args"
  telescope.load_extension "file_browser"
  -- telescope.load_extension("bookmarks")

  previewers = require "telescope.previewers"
  builtin = require "telescope.builtin"
  local conf = require "telescope.config"
  local delta = previewers.new_termopen_previewer {
    get_command = function(entry)
      -- this is for status
      -- You can get the AM things in entry.status. So we are displaying file if entry.status == '??' or 'A '
      -- just do an if and return a different command
      if entry.status == " D" then return end

      if entry.status == "??" then return { "bat", "--style=plain", "--pager", "less -R", entry.value } end

      return { "git", "-c", "core.pager=delta", "-c", "delta.side-by-side=false", "diff", entry.value }
    end,
  }
end

function M.my_git_commits(opts)
  opts = opts or {}
  opts.previewer = delta

  builtin.git_commits(opts)
end

function M.my_git_bcommits(opts)
  opts = opts or {}
  opts.previewer = delta

  builtin.git_bcommits(opts)
end

function M.my_git_status(opts)
  opts = opts or {}
  opts.git_icons = {
    added = "",
    changed = "",
    copied = "C",
    renamed = "",
    unmerged = "",
    untracked = "",
    deleted = "✖",
  }
  opts.previewer = delta

  builtin.git_status(opts)
end

function M.my_note(opts) builtin.live_grep { prompt_title = " Note ", cwd = "~/Notes" } end

function M.project_files()
  local opts = {} -- define here if you want to define something
  local ok = pcall(require("telescope.builtin").git_files, opts)
  if not ok then require("telescope.builtin").find_files(opts) end
end

function M.my_buffers(opts)
  builtin.buffers {
    layout_strategy = "vertical",
    ignore_current_buffer = true,
    sort_mru = true,
  }
end

return M
karambaq commented 1 year ago

It should be:

    {
      "gt",
      function() require("telescope-live-grep-args.shortcuts").grep_word_under_cursor() end,
      desc = "Find for word under cursor",
    },