vim-shortcut

? Discoverable & searchable shortcuts for (Neo)Vim

Github星跟蹤圖

shortcut.vim

This plugin provides a discoverable shortcut system for Vim that is inspired
by Spacemacs and powered by fzf.vim. It displays a searchable menu of
shortcuts when you pause partway while typing a shortcut, say, because you
forgot the rest of it or because you just want to see the shortcut menu again
to discover what else is available. You can interactively filter the menu by
typing more shortcut keys or parts of shortcut descriptions shown in the menu.

asciicast

Requirements

Usage

  • Use the Shortcut! prefix (with a bang) to describe existing shortcuts.

  • Use the Shortcut prefix (without a bang) to define brand new shortcuts.

  • Use the :Shortcuts command to display a searchable menu of shortcuts.

  • Use the g:shortcuts variable to access shortcuts keys and descriptions.

  • Use the g:shortcuts_overwrite_warning variable to detect any conflicts.

Discovery & fallback shortcuts

I recommend that you define these two shortcuts for discovery and fallback
(feel free to change the <Leader> key to your own commonly used prefix):

Shortcut show shortcut menu and run chosen shortcut
      \ noremap <silent> <Leader><Leader> :Shortcuts<Return>

Shortcut fallback to shortcut menu on partial entry
      \ noremap <silent> <Leader> :Shortcuts<Return>

The fallback shortcut's keys should represent the common prefix used by most
of your shortcuts so that it can automatically launch the shortcut menu for
you when you pause partway while typing a shortcut, say, because you forgot
the rest of it or because you just want to see the shortcut menu again to
discover what else is available. However, this is not a strict requirement
because you might find it useful to map shortcuts with uncommon prefixes when
you know them by heart and you thereby feel that a fallback is unnecessary.
As a result, you can map any keys to any shortcut, regardless of the prefix!
Furthermore, you can set up multiple fallback shortcuts too, one per prefix.

Describing existing shortcuts

Use Shortcut! with a bang to describe shortcuts that are already defined:

Shortcut! keys description

For more examples, see my vimrc:

Shortcut! [f       go to previous file in current file's directory
Shortcut! ]f       go to next     file in current file's directory

Any extra whitespace is ignored.

Defining new shortcuts

Simply prefix any existing map command with Shortcut and a description.

For example, take this mapping:

map definition

Add Shortcut and description:

Shortcut description map definition

You can use multiple lines too:

Shortcut description
      \ map definition

For more examples, see my vimrc:

Shortcut duplicate before cursor and then comment-out
      \ map <Space>cP  <Plug>NERDCommenterYank`[P
Shortcut fzf files in directory and go to chosen file
      \ nnoremap <silent> <Space>ef :Files<Return>
Shortcut save file as...
      \ nnoremap <silent> <Space>yf :call feedkeys(":saveas %\t", "t")<Return>
for i in range(1,9)
  execute 'Shortcut go to tab number '. i .' '
        \ 'nnoremap <silent> <Space>'. i .'t :tabfirst<Bar>'. i .'tabnext<Return>'
endfor
Shortcut comment-out using FIGlet ASCII art decoration
      \ nnoremap <silent> <Space>c@ V:call CommentUsingFIGlet()<Return>
      \, vnoremap <silent> <Space>c@ :<C-U>call CommentUsingFIGlet()<Return>

function! CommentUsingFIGlet()
  " ...
endfunction

Any extra whitespace is ignored.

Documentation

Run :help shortcut or see the doc/shortcut.txt file.

Testing

Developers can run the vim-vspec tests:

gem install bundler         # first time
bundle install              # first time
bundle exec vim-flavor test # every time

License

Like my work? :+1: Please spare a life today as thanks!
:cow::pig::chicken::fish::speak_no_evil::v::revolving_hearts:

Copyright 2015 Suraj N. Kurapati https://github.com/sunaku

Distributed under the same terms as Vim itself.

主要指標

概覽
名稱與所有者sunaku/vim-shortcut
主編程語言Vim Script
編程語言Ruby (語言數: 2)
平台
許可證
所有者活动
創建於2015-09-20 18:56:43
推送於2022-03-26 15:54:17
最后一次提交2022-03-26 09:24:28
發布數8
最新版本名稱2.2.2 (發布於 )
第一版名稱1.0.0 (發布於 )
用户参与
星數189
關注者數2
派生數4
提交數39
已啟用問題?
問題數7
打開的問題數2
拉請求數0
打開的拉請求數1
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?