All Projects → skywind3000 → Vim Tvision

skywind3000 / Vim Tvision

Licence: mit
Beautiful popup menus for Vim

Preface

Well designed and carefully colored Borland/Turbo C++ flavor popup menus for vim.

Installation

Plug 'skywind3000/vim-tvision'

Available Widgets

Popup Menu

Display a popup menu defined by itemlist, wait for user to make a selection and returns the result.

tvision#popup_menu({itemlist}, {options})

itemlist must be a list of strings. Each string in the list specifies a menu item:

  • A dash(-) represents a separator which is unselectable.
  • Shortcut keys can be defined after an & sign.
  • Script inside %{...} form will be evaluated before display.

options is a dictionary with optional keys:

  • line: y position of the screen coordinate (starts from 1).
  • col: x position of the screen coordinate (starts from 1).
  • cursor: default selection index, -1 for unselected by default.

Example:

" Each item is represented by one string, shortcut keys is defined by a `&` sign.
let lines = [
			\ "&New File\tCtrl+n",
			\ "&Open File\tCtrl+o", 
			\ "&Close",
			\ "--",
			\ "&Save\tCtrl+s",
			\ "Save &As",
			\ "Save All",
			\ "--",
			\ "&User Menu\tF9",
			\ "&Dos Shell",
			\ "~&Time %{&undolevels? '+':'-'}",
			\ "--",
			\ "E&xit\tAlt+x",
			\ ]
let index = tvision#popup_menu(lines, {'line':'cursor-1', 'col':'cursor'})
echo "Your selection is: " . index

Then you will get:

And use the default keymaps to interact with the popup menu:

Key Action
<esc> cancel
<cr> make the selection
<space> same as <cr>
<up> move the cursor up by one line
<down> move the cursor down by one line
j same as <down>
k same as <up>
<c-j> / <c-n> same as <down>
<c-k> / <c-p> same as <up>
g move the cursor to the first selectable item
G move the cursor to the last selectable item
J same as g
K same as k
q same as <esc>

Keymaps can be overrided by shortcuts defined in {itemlist}.

The function tvision#popup_menu will return if you make a selection or cancel by <ESC>.

Options

Border style

let g:tvision#border_style = 1

change the border style (1 by default), changed it to:

  • 0: disable
  • 1: ascii borders
  • 2: single unicode borders
  • 3: double unicode borders

Highlighting

The default highlighting groups are defined as:

hi! link TVisionBG Pmenu       " popup background
hi! link TVisionKey Keyword    " item shortcuts
hi! link TVisionOff Comment    " disabled items
hi! link TVisionSel PmenuSel   " current selected
hi! link TVisionHelp Title     " help text in command line

Customize as your preferences.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].