https://github.com/sunaku/vim-shortcut
💇 Discoverable & searchable shortcuts for (Neo)Vim
https://github.com/sunaku/vim-shortcut
fallback-shortcuts shortcut-menu vim-plugins
Last synced: about 2 months ago
JSON representation
💇 Discoverable & searchable shortcuts for (Neo)Vim
- Host: GitHub
- URL: https://github.com/sunaku/vim-shortcut
- Owner: sunaku
- Created: 2015-09-20T18:56:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T15:54:17.000Z (about 3 years ago)
- Last Synced: 2025-03-27T21:15:00.461Z (3 months ago)
- Topics: fallback-shortcuts, shortcut-menu, vim-plugins
- Language: Vim script
- Homepage:
- Size: 522 KB
- Stars: 189
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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.[](https://asciinema.org/a/104572?autoplay=1)
## Requirements
* [fzf.vim] plugin.
## Installation
1. Clone this Git repository as follows, or [download and extract its
contents]( https://github.com/sunaku/vim-shortcut/archive/master.zip ).git clone https://github.com/sunaku/vim-shortcut.git ~/vim-shortcut
2. Run the following commands in Vim to start using this plugin immediately,
or add them to your *vimrc* file to automate this whenever you start Vim.:set runtimepath+=~/vim-shortcut
:runtime plugin/shortcut.vim3. Run the following command inside Vim to learn more about using this plugin.
:help shortcut.vim
## 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 `` key to your own commonly used prefix):```vim
Shortcut show shortcut menu and run chosen shortcut
\ noremap :ShortcutsShortcut fallback to shortcut menu on partial entry
\ noremap :Shortcuts
```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:
```vim
Shortcut! keys description
```For more examples, [see my vimrc](
https://github.com/sunaku/.vim/blob/qwerty/bundle/motion/unimpaired.vim
):```vim
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:
```vim
map definition
```Add `Shortcut` and description:
```vim
Shortcut description map definition
```You can use multiple lines too:
```vim
Shortcut description
\ map definition
```For more examples, [see my vimrc](
https://github.com/sunaku/.vim/blob/qwerty/plugin/format.vim
):```vim
Shortcut duplicate before cursor and then comment-out
\ map cP NERDCommenterYank`[P
``````vim
Shortcut fzf files in directory and go to chosen file
\ nnoremap ef :Files
``````vim
Shortcut save file as...
\ nnoremap yf :call feedkeys(":saveas %\t", "t")
``````vim
for i in range(1,9)
execute 'Shortcut go to tab number '. i .' '
\ 'nnoremap '. i .'t :tabfirst'. i .'tabnext'
endfor
``````vim
Shortcut comment-out using FIGlet ASCII art decoration
\ nnoremap c@ V:call CommentUsingFIGlet()
\|vnoremap c@ :call CommentUsingFIGlet()function! CommentUsingFIGlet()
" ...
endfunction
```Any extra whitespace is ignored.
## Documentation
Run `:help shortcut.vim` or see the `doc/shortcut.txt` file.
## Testing
Developers can run the [vim-vspec]( https://github.com/kana/vim-vspec ) tests:
```sh
gem install bundler # first time
bundle install # first time
bundle exec vim-flavor test # every time
```## License
[Spare A Life]: https://sunaku.github.io/vegan-for-life.html
> Like my work? 👍 Please [spare a life] today as thanks! 🐄🐖🐑🐔🐣🐟✨🙊✌
> Why? For 💕 ethics, the 🌎 environment, and 💪 health; see link above. 🙇Copyright 2015 Suraj N. Kurapati
Distributed under [the same terms as Vim itself][LICENSE].
[LICENSE]: http://vimdoc.sourceforge.net/htmldoc/uganda.html#license
[Spacemacs]: http://spacemacs.org
[fzf.vim]: https://github.com/junegunn/fzf.vim