diff --git a/README.md b/README.md index a43ecd8..77d60f6 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ Gaze deeply into unknown regions using the power of the moon. ## What is Telescope? -Telescope is a highly extendable fuzzy finder over lists. Items are shown in a popup with a prompt to search over. +Telescope is a highly extendable fuzzy finder over lists. Items are shown in a popup with a prompt to search over. Support for: * LSP (references, document symbols, workspace symbols) -* Treesitter -* Grep -* Files (git, fd) +* Treesitter +* Grep +* Files (git, fd) * Vim (command history, quickfix, loclist) [What is Telescope?](https://www.twitch.tv/teej_dv/clip/RichDistinctPlumberPastaThat) @@ -23,9 +23,9 @@ Support for: ## Requirements -Neovim Nightly (0.5) +Neovim Nightly (0.5) -Best experience on Neovim Nightly with LSP configured. +Best experience on Neovim Nightly with LSP configured. ## Installation @@ -72,7 +72,7 @@ Options can be passed directly to the above functions, or set as defaults. -- Optional way to setup default values require('telescope').setup{ default = { - -- Example: + -- Example: shorten_path = true -- currently the default value is true } } @@ -90,7 +90,7 @@ Searches over files in a git folder. Note: This does not work outside a git repo nnoremap p lua require'telescope.builtin'.find_files{} ``` -Search over files in your `cwd` current working directory. +Search over files in your `cwd` current working directory. ```vim nnoremap gr lua require'telescope.builtin'.lsp_references{} @@ -120,12 +120,12 @@ nnoremap :lua require'telescope.builtin'.find_files{} nnoremap gr lua require'telescope.builtin'.lsp_references{ shorten_path = true } ``` -What this does: +What this does: * Make the paths full size by default. On LSP references we are shortening paths. -* Bind `` for a common mapping to find files. +* Bind `` for a common mapping to find files. - Using `telescope.builtin.git_files` is better in git directories. You can make a toggle to detect if it's a git directory. -* Bind `gr` to find references in LSP. +* Bind `gr` to find references in LSP. - `telescope.builtin.lsp_workspace_symbols` and `telescope.builtin.lsp_document_symbols` are also good to bind for LSP. ## Mappings @@ -136,7 +136,7 @@ Mappings are fully customizable. Many familiar mapping patterns are setup as def next | previous next | previous j k next | previous (in normal mode) - go to file selection + go to file selection go to file selection as a split go to file selection as a vertical split @@ -184,27 +184,27 @@ Note: Requires the `cwd` to be a git directory. ```lua require'telescope.builtin'.find_files{ - -- Optional - -- cwd = "/home/tj/" + -- Optional + -- cwd = "/home/tj/" } ``` Searches files in your working directory. ```lua require'telescope.builtin'.grep_string{ - -- Optional + -- Optional -- search = false -- Search term or } ``` -Searches your string with a grep. +Searches your string with a grep. Note: Requires `rg`. ```lua require'telescope.builtin'.live_grep{} ``` -Searches all your files (respecting .gitignore) using grep. +Searches all your files (respecting .gitignore) using grep. Note: Requires `rg` #### Vim @@ -233,6 +233,15 @@ require'telescope.builtin'.command_history{} Search the vim command history. +```lua +require'telescope.builtin'.buffers{ + -- Optional + -- show_all_buffers = true -- Show unloaded buffers aswell +} +``` + +Search on vim buffers list. + #### LSP ```lua @@ -258,7 +267,7 @@ Search on all workspace symbols. ```lua require'telescope.builtin'.treesitter{ -- Optional - -- bufnr = Buffer number + -- bufnr = Buffer number } ``` @@ -267,7 +276,7 @@ Search on function names, variables, from Treesitter! Note: Requires nvim-treesitter #### Telescope -```lua +```lua require'telescope.builtin'.planets{} ``` @@ -318,9 +327,9 @@ Defaults: -- lua/telescope/pickers.lua Picker:new{ prompt = "", -- REQUIRED - finder = FUNCTION, -- see lua/telescope/finder.lua + finder = FUNCTION, -- see lua/telescope/finder.lua sorter = FUNCTION, -- see lua/telescope/sorter.lua - previewer = FUNCTION, -- see lua/telescope/previewer.lua + previewer = FUNCTION, -- see lua/telescope/previewer.lua selection_strategy = "reset", -- follow, reset, line border = {}, borderchars = {"─", "│", "─", "│", "┌", "┐", "┘", "└"}, diff --git a/lua/telescope/actions.lua b/lua/telescope/actions.lua index f4a29e5..0f890de 100644 --- a/lua/telescope/actions.lua +++ b/lua/telescope/actions.lua @@ -83,6 +83,7 @@ local function goto_file_selection(prompt_bufnr, command) -- TODO: Sometimes we open something with missing line numbers and stuff... if entry_bufnr then a.nvim_win_set_buf(original_win_id, entry_bufnr) + vim.api.nvim_command("doautocmd filetypedetect BufRead " .. vim.fn.fnameescape(filename)) else vim.cmd(string.format(":%s %s", command, filename)) diff --git a/lua/telescope/builtin.lua b/lua/telescope/builtin.lua index 1c3c629..a14c08a 100644 --- a/lua/telescope/builtin.lua +++ b/lua/telescope/builtin.lua @@ -404,13 +404,19 @@ builtin.fd = builtin.find_files builtin.buffers = function(opts) opts = opts or {} - local buffers = filter(function(b) + local buffers = filter(function(b) return - vim.api.nvim_buf_is_loaded(b) + (opts.show_all_buffers + or vim.api.nvim_buf_is_loaded(b)) and 1 == vim.fn.buflisted(b) end, vim.api.nvim_list_bufs()) + if not opts.bufnr_width then + local max_bufnr = math.max(unpack(buffers)) + opts.bufnr_width = #tostring(max_bufnr) + end + pickers.new(opts, { prompt = 'Buffers', finder = finders.new_table { diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 3ae4de5..90562bd 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -180,6 +180,8 @@ function make_entry.gen_from_quickfix(opts) end function make_entry.gen_from_buffer(opts) + opts = opts or {} + local get_position = function(entry) local tabpage_wins = vim.api.nvim_tabpage_list_wins(0) for k, v in ipairs(tabpage_wins) do @@ -191,6 +193,18 @@ function make_entry.gen_from_buffer(opts) return {} end + local make_display = function(entry) + local display_bufname + if opts.shorten_path then + display_bufname = utils.path_shorten(entry.filename) + else + display_bufname = entry.filename + end + + return string.format("%" .. opts.bufnr_width .. "d : %s", + entry.bufnr, display_bufname) + end + return function(entry) local bufnr_str = tostring(entry) local bufname = vim.api.nvim_buf_get_name(entry) @@ -206,7 +220,7 @@ function make_entry.gen_from_buffer(opts) value = bufname, ordinal = bufnr_str .. " : " .. bufname, - display = bufnr_str .. " : " .. bufname, + display = make_display, bufnr = entry, filename = bufname,