Giter Club home page Giter Club logo

quickmenu.vim's Introduction

Preface

There are many keymaps defined in my .vimrc. Getting tired to check my .vimrc again and again when I forget some, so I made this quickmenu plugin which can be fully customized:

  • Well formatted and carefully colored to ensure neat and handy.
  • Press <F12> to popup quickmenu on the right, use j and k to move up and down.
  • Press <Enter> or 1 to 9 to select an item.
  • Help details will display in the cmdline when you are moving the cursor around.
  • Items can be filtered by filetype, different items for different filetypes.
  • Scripts in the %{...} form from text and help will be evaluated and expanded.
  • No longer have to be afraid for forgetting keymaps.

Just see this GIF demonstration below:

Trying to share my configuration to my friends, I found that they did't have patience to remember all the keymaps in my vimrc, but a quickmenu is quite accaptable for them.

Note: Active development on this plugin has stopped. The only future changes will be bug fixes.

Please see vim-quickui.

Install

Copy autoload/quickmenu.vim and syntax/quickmenu.vim to your ~/.vim/autoload and ~/.vim/syntax. or use Vundle to install it from skywind3000/quickmenu.vim. Add these lines to your .vimrc:

" choose a favorite key to show/hide quickmenu
noremap <silent><F12> :call quickmenu#toggle(0)<cr>

" enable cursorline (L) and cmdline help (H)
let g:quickmenu_options = "HL"

Tutorial

Simply use the function below:

function quickmenu#append(text, action [, help = ''])
  • text will be show in the quickmenu, vimscript in %{...} will be evaluated and expanded.
  • action is a piece of vimscript to be executed when a item is selected.
  • help will display in the cmdline if g:quickmenu_options contains H.

A item will be treated as "static text" (unselectable) If action is empty. text starting with "#" represents a new section.

Example for .vimrc:

" enable cursorline (L) and cmdline help (H)
let g:quickmenu_options = "LH"

" clear all the items
call g:quickmenu#reset()

" bind to F12
noremap <silent><F12> :call quickmenu#toggle(0)<cr>


" section 1, text starting with "#" represents a section (see the screen capture below)
call g:quickmenu#append('# Develop', '')

call g:quickmenu#append('item 1.1', 'echo "1.1 is selected"', 'select item 1.1')
call g:quickmenu#append('item 1.2', 'echo "1.2 is selected"', 'select item 1.2')
call g:quickmenu#append('item 1.3', 'echo "1.3 is selected"', 'select item 1.3')

" section 2
call g:quickmenu#append('# Misc', '')

call g:quickmenu#append('item 2.1', 'echo "2.1 is selected"', 'select item 2.1')
call g:quickmenu#append('item 2.2', 'echo "2.2 is selected"', 'select item 2.2')
call g:quickmenu#append('item 2.3', 'echo "2.3 is selected"', 'select item 2.3')
call g:quickmenu#append('item 2.4', 'echo "2.4 is selected"', 'select item 2.4')

And then quickmenu is ready:

Vim is lack of basic ui components, that's ok for experienced users, but hard for the others. A quickmenu is quite easier for them. Now we have this cute menu and show/hide it with F12. and no longer have to worry about forgetting keymaps.

Documentation

Add new items into menu

function quickmenu#append(text, action [, help = '' [, ft = '']])
  • text will be show in the quickmenu, vimscript in %{...} will be evaluated and expanded.
  • action is a piece of vimscript to be executed when a item is selected.
  • help will display in the cmdline if g:quickmenu_options contains H.
  • ft filter to decide if item is enabled for specific filetypes.

A item will be treated as "static text" (unselectable) If action is empty. text starting with "#" represents a new section.

Note that, script evaluation of %{...} is happened before quickmenu open, you can get information from current document and display them in the menu, like current filename or word under cursor.

And action will be executed after quickmenu closed. All the action will affect current document (not the quickmenu window).

If you want your item enabled for C/C++ set the parameter of ft to "c,cpp,objc,objcpp", otherwise just leave it empty.

Clear items

function quickmenu#reset()

This will reset the quickmenu

Set header

function quickmenu#header(text)

Replace the origin title of QuickMenu X.X.X

Show / hide quickmenu

function quickmenu#toggle(menuid)

You have unlimited menus to use, not only one. The menuid is used to indicate which menu to be displayed. 0 can be used by default.

Set current menuid

function quickmenu#current(menuid)

If current menu changed (which is 0 by default), quickmenu#append() will insert new items into the new menu and quickmenu#reset() will clear items in it either.

Popup quickmenu on the bottom (cmdline)

function quickmenu#bottom(menuid)

Use cmdline to show quickmenu.

Options

g:quickmenu_padding_left (integer)

Left padding size of the quickmenu window

default = 3

Set it to 2 or 1 if you are running vim in a small window, so quickmenu will not occupy much space.

g:quickmenu_padding_right (integer)

Right padding size of the quickmenu window

default = 3

Set it to 2 or 1 if you are running vim in a small window, so quickmenu will not occupy much space.

quickmenu_max_width (integer)

Max quickmenu window size

default = 40

Window width of quickmenu is adaptive to the content of items. This control the max value of the window size.

g:quickmenu_disable_nofile (integer)

Quickmenu will not popup if buftype is "nofile" when set it to 1

default = 1

Prevent quickmenu accidently popup in some non-file window like: quickfix, location list or tagbar, etc. whose buftype has been set to "nofile".

g:quickmenu_ft_blacklist (list)

Quickmenu will not popup if current filetype matchs the blacklist.

default = ['netrw', 'nerdtree', 'startify']

It is not enough to use g:quickmenu_disable_nofile to detect non-file buffers, some plugins like netrw forgot to set their buftype to "nofile".

g:quickmenu_options (string)

Quickmenu gui options, each character represents a feature.

default = ''

The available options are "H" (show help in the cmdline), "L" (show cursorline) and "T" (open on the left).

Example

The configuration for the first GIF screencapture:

" clear all the items
call quickmenu#reset()

" enable cursorline (L) and cmdline help (H)
let g:quickmenu_options = "HL"

" use your favorite key to show / hide quickmenu
noremap <silent><F12> :call quickmenu#toggle(0)


" new section: empty action with text starts with "#" represent a new section
call quickmenu#append("# Debug", '')

" script between %{ and } will be evaluated before menu open
call quickmenu#append("Run %{expand('%:t')}", '!./%', "Run current file")


" new section
call quickmenu#append("# Git", '')

" use fugitive to show diff
call quickmenu#append("git diff", 'Gvdiff', "use fugitive's Gvdiff on current document")

call quickmenu#append("git status", 'Gstatus', "use fugitive's Gstatus on current document")


" new section
call quickmenu#append("# Misc", '')

call quickmenu#append("Turn paste %{&paste? 'off':'on'}", "set paste!", "enable/disable paste mode (:set paste!)")

call quickmenu#append("Turn spell %{&spell? 'off':'on'}", "set spell!", "enable/disable spell check (:set spell!)")

call quickmenu#append("Function List", "TagbarToggle", "Switch Tagbar on/off")

For more advanced usage, you may be interested in my own config:

https://github.com/skywind3000/vim/blob/master/asc/menu.vim

More

UltiSnips is great, but remembering all the snipet's names is really painful. There are more nearly 130+ snippets for C++ in UltiSnips's database, but I can remember only three of them.

Using quickmenu to select snippets is much easier for me than using UltiSnips directly, I am going to write a wiki page about it.

History

  • 1.2.4 (2017-08-08): supports funcref now.
  • 1.2.3 (2017-07-27): add <nowait> befor noremap to avoid delay when you press 'c'
  • 1.2.2 (2017-07-17): clear help text after pressing '0', remember cursor pos after closed.
  • 1.2.1 (2017-07-16): use redraw to clear help text in the cmdline after quickmenu closed.
  • 1.2.0 (2017-07-16): new feature quickmenu#bottom to popup on the bottom.
  • 1.1.16 (2017-07-15): improve unicode character support
  • 1.1.15 (2017-07-15): fixed: quickmenu will always popup on the right, no matter splitright is set or unset.
  • 1.1.14 (2017-07-14): fixed: incompatible with vim before 7.4.2202
  • 1.1.13 (2017-07-14): New option to set default left/right padding size, useful when running vim in a small window.
  • 1.1.12 (2017-07-13): Initial commit.

Credits

Thanks to vim-startify, quickmenu uses its syntax and some idea.

It is a great honor if you like it and star this repository or vote it in: script #5589.

If you are interested in this plugin you may also like AsyncRun.

quickmenu.vim's People

Contributors

skywind3000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quickmenu.vim's Issues

hide Close button

Since quick menu can be toggled by the same key, i would like to not display the close menu entries, please introduce a variable to not show these.

How to reload quickmenu?

First of all, I love your plugin!

I'm using quickmenu like that:

function! QuickMenuBranches()
  call quickmenu#header('Quick Git')
  call g:quickmenu#reset()
  let branches = systemlist("git branch --list | tr -d '* '")

  call g:quickmenu#append('# Change branch:', '')

  for branch in branches
    call g:quickmenu#append('' . branch, '%{silent !git checkout ' . branch . '}')
  endfor

  call g:quickmenu#append('# Delete branch:', '')

  for branch in branches
    call g:quickmenu#append('' . branch, '%{silent !git branch -D ' . branch . '}')
  endfor

  call g:quickmenu#append('# Branch miscellaneous:', '')

  call g:quickmenu#append('Pull and rebase with master', 'silent !git checkout master; git pull; git checkout -; git rebase master;')
  call g:quickmenu#append('Add and continue rebasing', 'silent !git add .; git rebase --continue;')
endfunction

call QuickMenuBranches()

How could I reload the branches everytime the popup is opened? Right now I have to reopen vim again. I read the section about enclosing an action inside %{}, but that's not quite what I need.

I do know that the problem is the way that I'm currently loading the branches:

let branches = systemlist("git branch --list | tr -d '* '")

But I don't know what could be done to reload them.

Any ideas?

Thanks!

Neovim automatic menus

Hello again :)

Neovim recently added a function menu_get. I'm not sure if you use Neovim or not, but I think this could be useful for quickmenu. I made an example of what could be done to auto generate "quickmenus" from built-in menus.

For example, with Vimwiki, you can generate a menu automatically that looks like this:

image

let s:debug = v:false

" Function to handle creating a menu entry for an actual mapping
function! s:handle_maps(menu, mode) abort
  if !has_key(a:menu, 'mappings')
    return
  endif

  if !has_key(a:menu.mappings, a:mode)
    return
  endif

  let rhs = a:menu.mappings[a:mode].rhs
  let rhs = substitute(rhs, "\r", '', 'g')
  let rhs = substitute(rhs, "\n", '', 'g')

  if s:debug
    echo 'MENU.RHS: ' string(rhs)
  endif

  call quickmenu#append(a:menu.name, rhs)
endfunction

" Recursive function to check for menus and handle menus
function! s:handle_menu(menu, mode) abort
  if has_key(a:menu, 'submenus')
    if s:debug
      echo 'MENU: ' . string(a:menu.name)
    endif

    call quickmenu#append('# ' . a:menu.name, '')
    call s:handle_maps(a:menu, a:mode)

    for submenu in a:menu.submenus
      call s:handle_menu(submenu, a:mode)
    endfor
  else
    call s:handle_maps(a:menu, a:mode)
  endif
endfunction

" Entry point for making menus
function! Menu2Quick(name, mode) abort
  let menu_list = menu_get(a:name, a:mode)

  call quickmenu#reset()
  call quickmenu#header(a:name)

  for menu in menu_list
    call s:handle_menu(menu, a:mode)
  endfor

  call quickmenu#toggle(0)
endfunction

Would you be interested in including this in your plugin? If not, that's fine. If so, I can make a pull request for it and clean things up.

Assign letters to command

Awesome plug-in!
I was wondering if you would consider adding something like

[ i ] init.vim

So when I press i, it opens it.

Use a funcref instead of a string in quickmenu#append()

Hi, awesome plugin 😄

I'm wondering if it would be possible to use a function reference or lambda for quickmenu#append().

For example:

function! ExampleFunc(arg) abort
  return arg + 1
endfunction

call quickmenu#append('call funcref', funcref('ExampleFunc', [10]))

Thanks

is there possible to toggle more than one window?

Hi,
thanks for your wonderful and newbie-friendly vim plugin.

[the background]: I'm trying to use this plugin for making a "symbol list window"(just like source-insight) to show all symbols of the editing file. my conf

[the question]: now I'm wondering if there's possible to show more window(a window for symbol-in-current-file listing , another window for symbol-in-the-whole-project searching)
thanks again!

Does not seem to recognise filetype of "py"

When I set the "ft=" option to "py",the line still does not show up. My line is:
call quickmenu#append('.debug: Debug code', 'echo "Debug code"', "Debug code","py,sh")

When editing a .sh file the line appears but does not when I am editing a python file.

Thank.
khy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.