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?
已存档?
是复刻?
已锁定?
是镜像?
是私有?