Skip to content

Instantly share code, notes, and snippets.

@Nexmean
Last active December 6, 2022 10:54
Show Gist options
  • Save Nexmean/03df73a3ed9675c0d91bf08bcb78a9c5 to your computer and use it in GitHub Desktop.
Save Nexmean/03df73a3ed9675c0d91bf08bcb78a9c5 to your computer and use it in GitHub Desktop.
Window picker for telescope.nvim

Install plugin: https://github.com/s1n7ax/nvim-window-picker

Create command:

vim.api.nvim_create_user_command("Pick", function (e)
  local success, picked = pcall(function ()
    return require('window-picker').pick_window({
      autoselect_one = true,
      include_current_win = true,
      current_win_hl_color = '#89b4fa',
      other_win_hl_color = '#89b4fa'
    })
  end)
  if not success then
    return
  end

  vim.api.nvim_set_current_win(picked)
  if e.fargs[1] ~= nil then
    vim.cmd('e ' .. e.fargs[1])
  end
end, { nargs = '?', complete = 'file' })

Add mappings to telescope:

local action_set = require('telescope.actions.set')

require('telescope').setup {
  defaults = {
    mappings = {
      i = {
        ["<S-CR>"] = function (prompt_bufnr)
          action_set.edit(prompt_bufnr, "Pick")
        end
      },
      n = {
        ["<S-CR>"] = function (prompt_bufnr)
          action_set.edit(prompt_bufnr, "Pick")
        end
      },
    },
  },
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment