Skip to content

octarect/telescope-menu.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

telescope-menu.nvim

CI Tag

telescope-menu.nvim is an extension for telescope.nvim which provides custom menus.

Demo

Getting Started

Dependencies

Installation

Using dein.vim

call dein#add('nvim-telescope/telescope.nvim')
call dein#add('octarect/telescope-menu.nvim')

If using TOML,

[[plugins]]
repo = 'nvim-telescope/telescope.nvim'

[[plugins]]
repo = 'octarect/telescope-menu.nvim'

Usage

Example Configuration

require("telescope").setup {
  extensions = {
    menu = {
      default = {
        items = {
          -- You can add an item of menu in the form of { "<display>", "<command>" }
          { "Checkhealth", "checkhealth" },
          { "Show LSP Info", "LspInfo" },
          { "Files", "Telescope find_files" },

          -- The above examples are syntax-sugars of the following;
          { display = "Change colorscheme", value = "Telescope colorscheme" },
        },
      },
    },
  },
}

require("telescope").load_extension "menu"

Run

Run Telescope menu to open the menu default.

Default Mappings

Mappings Action
<CR> Confirm selection

Pickers

Vim Command Lua Description
:Telescope menu :lua require"telescope".extensions.menu.menu{} Open default menu
:Telescope menu filetype lua require"telescope".extensions.menu.filetype{} Open filetype-specific menu
:Telescope menu <menu_name> :lua require"telescope".extensions.menu.<menu_name>{} Open <menu_name>

Configuration

Multiple menus

Defining multiple menus is supported. Menus except for default is opened by Telescope menu <menu_name>.

For example, you can have another menu named editor by the following config;

{
  extensions = {
    menu = {
      default = {
        items = {
          -- Jump to another menu
          { "Editor", "Telescope menu editor" },
        },
      },
      -- `editor` is an example, and you can name it as you like.
      editor = {
        items = {
          { "Split window vertically", "vsplit" },
          { "Split window horizontally", "split" },
          { "Write", "w" },
        },
      },
    },
  },
}

Then, you can open the menu by

  • ExCommand: Telescope menu editor
  • Lua: require("telescope").extensions.menu.editor()

Filetype-specific menu

You can define menu for a particular filetype, and open them by Telescope menu filetype.

Example:

{
  extensions = {
    menu = {
      filetype = {
        lua = {
          items = {
            { "Format", "!stylua %" },
            { "Open Luadev menu", "Luadev" },
            { "Execute a current buffer", "LuaRun" },
          },
        },
        -- Format
        -- <filetype> = {
        --   items = {
        --     -- your favorite commands
        --   }
        -- }
      }
    },
  },
}

Executing lua function

You can specify lua function as command instead of string.

{
  extensions = {
    menu = {
      default = {
        items = {
          { "Example", function()
            print("This is example."\n")
          end},
        },
      }
    },
  },
}

Executing a mapping

local keymap = require("telescope-menu.actions").keymap

require("telescope").setup {
  extensions = {
    menu = {
      default = {
        items = {
          { "Jump to the previous hunk", "<Plug>(GitGutterPrevHunk)", keymap },
          { "Jump to the next hunk", "<Plug>(GitGutterNextHunk)", keymap },
        },
      },
    },
  },
}

Contributing

Any pull requests are welcome. We consider you have granted non-exclusive right to your contributed code under MIT License. Use http://github.com/octarect/telescope-menu.nvim/issues for discussion.


CHANGELOG

v0.1.0

  • Basic features (Open a custom menu by Telescope menu)
  • CI for automated test

v0.2.0

New features

  • Filetype-specific menu (Telescope menu filetype)
  • Multiple menus
  • Supported list format for item (syntax-sugar)

Breaking changes

  • Changed name of default menu: global -> default

Other

  • Improved CI
    • Matrix test
    • Added lint and stylecheck