From b04ec331c48a1668b0df21f24e9870acccec5e64 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Thu, 3 Sep 2020 11:18:08 -0400 Subject: [PATCH] feat: Add cool mapping for in command mode --- lua/telescope/finders.lua | 4 +--- lua/telescope/pickers.lua | 7 ++++++- plugin/telescope.vim | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lua/telescope/finders.lua b/lua/telescope/finders.lua index b1a3819..b44dd71 100644 --- a/lua/telescope/finders.lua +++ b/lua/telescope/finders.lua @@ -11,9 +11,7 @@ local finders = {} -- JobFinder(my_job_args) ---@class Finder -local Finder = { - hello = "world" -} +local Finder = {} Finder.__index = Finder Finder.__call = function(t, ... ) return t:_find(...) end diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index db46e20..b072f90 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -64,6 +64,7 @@ function Picker:new(opts) return setmetatable({ prompt = opts.prompt, + default_text = opts.default_text, finder = opts.finder, sorter = opts.sorter, @@ -384,7 +385,11 @@ function Picker:find() mappings.apply_keymap(prompt_bufnr, self.attach_mappings, default_mappings) - vim.cmd [[startinsert]] + if self.default_text then + vim.api.nvim_buf_set_lines(prompt_bufnr, 0, 1, false, {self.default_text}) + end + + vim.cmd [[startinsert!]] end function Picker:hide_preview() diff --git a/plugin/telescope.vim b/plugin/telescope.vim index 837187a..347f887 100644 --- a/plugin/telescope.vim +++ b/plugin/telescope.vim @@ -6,6 +6,13 @@ highlight default link TelescopeSelection Visual highlight default link TelescopeNormal Normal +" This is like "" in your terminal. +" To use it, do `cmap (TelescopeFuzzyCommandSearch) +cnoremap (TelescopeFuzzyCommandSearch) e + \ "lua require('telescope.builtin').command_history { + \ default_text = [=[" . escape(getcmdline(), '"') . "]=] + \ }" + " let s:term_command = "rg preview_quit_map -l | fzf --preview 'bat --color=always --style=grid {-1}' --print0" " let s:term_command = "rg preview_quit_map -l | fzf --preview 'bat --color=always --style=grid {-1}' > file.txt" " let s:term_command = "(rg preview_quit_map -l | fzf --preview 'bat --color=always --style=grid {-1}')"