diff options
| author | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2022-02-13 12:32:19 +0100 |
|---|---|---|
| committer | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2022-02-13 12:32:19 +0100 |
| commit | d43a4f3b7455599968b9e61c64944ef2759458d6 (patch) | |
| tree | 051652cd7bb8d272f40d70146cdd38b1b089ff98 /lua/alpha | |
| parent | 535b2236a134a4e36979ae27159c3f46e808ca6c (diff) | |
| download | nvim-conf-d43a4f3b7455599968b9e61c64944ef2759458d6.tar.gz nvim-conf-d43a4f3b7455599968b9e61c64944ef2759458d6.zip | |
More refactor move telescope to it's own repo and restructure
Diffstat (limited to 'lua/alpha')
| -rw-r--r-- | lua/alpha/plugins.lua | 37 | ||||
| -rw-r--r-- | lua/alpha/snippets/php.lua | 2 | ||||
| -rw-r--r-- | lua/alpha/telescope.lua | 70 | ||||
| -rw-r--r-- | lua/alpha/telescope/init.lua | 63 | ||||
| -rw-r--r-- | lua/alpha/telescope/mappings.lua | 47 | ||||
| -rw-r--r-- | lua/alpha/telescope/setup.lua | 172 |
6 files changed, 319 insertions, 72 deletions
diff --git a/lua/alpha/plugins.lua b/lua/alpha/plugins.lua index f85a513..5591695 100644 --- a/lua/alpha/plugins.lua +++ b/lua/alpha/plugins.lua @@ -2,6 +2,28 @@ vim.cmd [[packadd packer.nvim]] vim.cmd([[autocmd BufWritePost plugins.lua source <afile> | PackerCompile]]) return require('packer').startup(function(use) + + local local_use = function(first, second, opts) + opts = opts or {} + + local plug_path, home + if second == nil then + plug_path = first + home = "adalessa" + else + plug_path = second + home = first + end + + if vim.fn.isdirectory(vim.fn.expand("~/plugins/" .. plug_path)) == 1 then + opts[1] = "~/plugins/" .. plug_path + else + opts[1] = string.format("%s/%s", home, plug_path) + end + + use(opts) + end + use 'wbthomason/packer.nvim' use "lewis6991/impatient.nvim" @@ -70,6 +92,18 @@ return require('packer').startup(function(use) } use { + "ThePrimeagen/git-worktree.nvim", + config = function() + require("git-worktree").setup {} + end, + } + + use "nvim-telescope/telescope-dap.nvim" + use "rcarriga/nvim-notify" + use { "nvim-telescope/telescope-ui-select.nvim" } + use { "nvim-telescope/telescope-fzf-native.nvim", run = "make" } + + use { 'nvim-lualine/lualine.nvim', requires = {'kyazdani42/nvim-web-devicons', opt = true} } @@ -132,5 +166,6 @@ return require('packer').startup(function(use) use { 'vimwiki/vimwiki', opt = true, cmd = {'VimwikiIndex'}} -- Local plugins can be included - use '~/code/neovim/telescope-projectionist.nvim' + local_use 'telescope-projectionist.nvim' + local_use 'telescope-laravel.nvim' end) diff --git a/lua/alpha/snippets/php.lua b/lua/alpha/snippets/php.lua index 19088c4..9fd4e58 100644 --- a/lua/alpha/snippets/php.lua +++ b/lua/alpha/snippets/php.lua @@ -7,7 +7,7 @@ local c = ls.choice_node local d = ls.dynamic_node -- local f = ls.function_node -- local l = require("luasnip.extras").lambda -local conds = require("luasnip.extras.expand_conditions") +-- local conds = require("luasnip.extras.expand_conditions") -- visibility allows to reuse it pasing the first option to show for the -- snippet diff --git a/lua/alpha/telescope.lua b/lua/alpha/telescope.lua deleted file mode 100644 index 28f06b2..0000000 --- a/lua/alpha/telescope.lua +++ /dev/null @@ -1,70 +0,0 @@ -local telescope = require('telescope') -local actions = require('telescope.actions') -local previewers = require('telescope.previewers') - -telescope.setup { - defaults = { - file_sorter = require('telescope.sorters').get_fzy_sorter, - prompt_prefix = ' >', - use_less = false, - set_env = { ['COLORTERM'] = 'truecolor' }, - - file_previewer = previewers.vim_buffer_cat.new, - grep_previewer = previewers.vim_buffer_vimgrep.new, - qflist_previewer = previewers.vim_buffer_qflist.new, - - mappings = { - i = { - ["<C-x>"] = false, - ["<C-q>"] = actions.send_to_qflist, - }, - } - }, - extensions = { - fzy_native = { - override_generic_sorter = false, - override_file_sorter = true, - } - } -} - -telescope.load_extension('fzy_native') -telescope.load_extension("projectionist") -telescope.load_extension("file_browser") - -local M = {} - -M.search_config = function() - require("telescope.builtin").git_files({ - prompt_title = "< dotfiles >", - cwd = "$HOME/.dotfiles", - }) -end - -M.project_files = function() - 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 - -M.branches = function() - require'telescope.builtin'.git_branches({ attach_mappings = function(_, map) - map('i', '<c-j>', actions.git_create_branch) - map('n', '<c-j>', actions.git_create_branch) - return true - end}) -end - -M.laravel_artisan = require('alpha.telescope_laravel').artisan - -M.grep_string = function () - vim.ui.input("Grep for > ", function (input) - if input == nil then - return - end - require('telescope.builtin').grep_string({ search = input}) - end) -end - - -return M diff --git a/lua/alpha/telescope/init.lua b/lua/alpha/telescope/init.lua new file mode 100644 index 0000000..7b0ffd2 --- /dev/null +++ b/lua/alpha/telescope/init.lua @@ -0,0 +1,63 @@ +local actions = require('telescope.actions') + +local M = {} + +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.branches() + require'telescope.builtin'.git_branches({ attach_mappings = function(_, map) + map('i', '<c-j>', actions.git_create_branch) + map('n', '<c-j>', actions.git_create_branch) + return true + end}) +end + +function M.search_config() + require("telescope.builtin").git_files({ + prompt_title = "< dotfiles >", + cwd = "$HOME/.dotfiles", + }) +end + +function M.grep_string() + vim.ui.input("Grep for > ", function (input) + if input == nil then + return + end + require('telescope.builtin').grep_string({ search = input}) + end) +end + +function M.grep_word() + require('telescope.builtin').grep_string({ search = vim.fn.expand("<cword>")}) +end + +function M.find_symbol () + vim.ui.input("Symbol for > ", function (input) + if input == nil then + return + end + require('telescope.builtin').lsp_workspace_symbols({ search = input}) + end) +end + +function M.my_plugins() + require("telescope.builtin").find_files { + cwd = "~/plugins/", + } +end + +return setmetatable({}, { + __index = function(_, k) + + if M[k] then + return M[k] + else + return require("telescope.builtin")[k] + end + end, +}) diff --git a/lua/alpha/telescope/mappings.lua b/lua/alpha/telescope/mappings.lua new file mode 100644 index 0000000..411fc0c --- /dev/null +++ b/lua/alpha/telescope/mappings.lua @@ -0,0 +1,47 @@ +TelescopeMapArgs = TelescopeMapArgs or {} + +local map_tele = function(key, f, options, buffer) + local map_key = vim.api.nvim_replace_termcodes(key .. f, true, true, true) + + TelescopeMapArgs[map_key] = options or {} + + local mode = "n" + local rhs = string.format("<cmd>lua R('alpha.telescope')['%s'](TelescopeMapArgs['%s'])<CR>", f, map_key) + + local map_options = { + noremap = true, + silent = true, + } + + if not buffer then + vim.api.nvim_set_keymap(mode, key, rhs, map_options) + else + vim.api.nvim_buf_set_keymap(0, mode, key, rhs, map_options) + end +end + +-- not shure what this line does +vim.api.nvim_set_keymap("c", "<c-r><c-r>", "<Plug>(TelescopeFuzzyCommandSearch)", { noremap = false, nowait = true }) + + +map_tele("<leader>pp", "project_files") +map_tele("<leader>gc", "branches") +map_tele("<leader>pw", "grep_word") +map_tele("<leader>ps", "grep_string") +map_tele("<leader>pf", "projectionist") +map_tele("<leader>rc", "search_config") +map_tele("<leader>ph", "help_tags") +map_tele("<leader>pe", "buffers") +map_tele("<leader>pr", "treesitter") +map_tele("<leader>bb", "file_browser") +map_tele("<leader>vrr", "lsp_references") +map_tele("<leader>gs", "git_status") +map_tele("<leader>pv", "find_symbol") +map_tele("<leader>ve", "lsp_document_diagnostics") +map_tele("<leader>fp", "my_plugins") + +map_tele("<leader>pa", "laravel") + + + +return map_tele diff --git a/lua/alpha/telescope/setup.lua b/lua/alpha/telescope/setup.lua new file mode 100644 index 0000000..75ddfa9 --- /dev/null +++ b/lua/alpha/telescope/setup.lua @@ -0,0 +1,172 @@ +local actions = require "telescope.actions" +local action_state = require "telescope.actions.state" +local action_layout = require "telescope.actions.layout" + +local set_prompt_to_entry_value = function(prompt_bufnr) + local entry = action_state.get_selected_entry() + if not entry or not type(entry) == "table" then + return + end + + action_state.get_current_picker(prompt_bufnr):reset_prompt(entry.ordinal) +end + +require("telescope").setup { + defaults = { + prompt_prefix = "❯ ", + selection_caret = "❯ ", + + winblend = 0, + + layout_strategy = "horizontal", + layout_config = { + width = 0.95, + height = 0.85, + -- preview_cutoff = 120, + prompt_position = "top", + + horizontal = { + preview_width = function(_, cols, _) + if cols > 200 then + return math.floor(cols * 0.4) + else + return math.floor(cols * 0.6) + end + end, + }, + + vertical = { + width = 0.9, + height = 0.95, + preview_height = 0.5, + }, + + flex = { + horizontal = { + preview_width = 0.9, + }, + }, + }, + + selection_strategy = "reset", + sorting_strategy = "descending", + scroll_strategy = "cycle", + color_devicons = true, + + mappings = { + i = { + ["<C-x>"] = false, + ["<C-s>"] = actions.select_horizontal, + ["<C-n>"] = "move_selection_next", + + ["<C-y>"] = set_prompt_to_entry_value, + + -- These are new :) + ["<M-p>"] = action_layout.toggle_preview, + ["<M-m>"] = action_layout.toggle_mirror, + -- ["<M-p>"] = action_layout.toggle_prompt_position, + + -- ["<M-m>"] = actions.master_stack, + + -- ["<C-q>"] = actions.send_to_qflist + actions.open_qflist, + -- ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist, + + -- This is nicer when used with smart-history plugin. + ["<C-k>"] = actions.cycle_history_next, + ["<C-j>"] = actions.cycle_history_prev, + + ["<c-space>"] = function(prompt_bufnr) + local opts = { + callback = actions.toggle_selection, + loop_callback = actions.send_selected_to_qflist, + } + require("telescope").extensions.hop._hop_loop(prompt_bufnr, opts) + end, + + ["<C-w>"] = function() + vim.api.nvim_input "<c-s-w>" + end, + }, + }, + + -- borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + -- file_ignore_patterns = nil, + + file_previewer = require("telescope.previewers").vim_buffer_cat.new, + grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, + + history = { + path = "~/.local/share/nvim/databases/telescope_history.sqlite3", + limit = 100, + }, + }, + + pickers = { + fd = { + mappings = { + n = { + ["kj"] = "close", + }, + }, + }, + + git_branches = { + mappings = { + i = { + ["<C-a>"] = false, + }, + }, + }, + }, + + extensions = { + fzy_native = { + override_generic_sorter = true, + override_file_sorter = true, + }, + + fzf_writer = { + use_highlighter = false, + minimum_grep_characters = 6, + }, + + hop = { + -- keys define your hop keys in order; defaults to roughly lower- and uppercased home row + keys = { "a", "s", "d", "f", "g", "h", "j", "k", "l", ";" }, -- ... and more + + -- Highlight groups to link to signs and lines; the below configuration refers to demo + -- sign_hl typically only defines foreground to possibly be combined with line_hl + sign_hl = { "WarningMsg", "Title" }, + + -- optional, typically a table of two highlight groups that are alternated between + line_hl = { "CursorLine", "Normal" }, + + -- options specific to `hop_loop` + -- true temporarily disables Telescope selection highlighting + clear_selection_hl = false, + -- highlight hopped to entry with telescope selection highlight + -- note: mutually exclusive with `clear_selection_hl` + trace_entry = true, + -- jump to entry where hoop loop was started from + reset_selection = true, + }, + + ["ui-select"] = { + require("telescope.themes").get_dropdown { + -- even more opts + }, + }, + }, +} +_ = require("telescope").load_extension "dap" +_ = require("telescope").load_extension "notify" +_ = require("telescope").load_extension "file_browser" +_ = require("telescope").load_extension "ui-select" +_ = require("telescope").load_extension "fzf" +_ = require("telescope").load_extension "git_worktree" +-- _ = require("telescope").load_extension "neoclip" +-- _ = require("telescope").load_extension "frecency" +-- _ = require("telescope").load_extension "smart_history" +_ = require("telescope").load_extension "projectionist" +_ = require("telescope").load_extension "laravel" |