Skip to content

Latest commit

 

History

History
174 lines (120 loc) · 5.1 KB

README.md

File metadata and controls

174 lines (120 loc) · 5.1 KB

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

Installation

  1. Clone this Git repository as follows, or download and extract its contents.

     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.vim
    
  3. 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 <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.vim 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? 👍 Please spare a life today as thanks! 🐄🐖🐑🐔🐣🐟✨🙊✌
Why? For 💕 ethics, the 🌎 environment, and 💪 health; see link above. 🙇

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

Distributed under the same terms as Vim itself.