Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sudormrfbin/cheatsheet.nvim

A cheatsheet plugin for neovim with bundled cheatsheets for the editor, multiple vim plugins, nerd-fonts, regex, etc. with a Telescope fuzzy finder interface!
https://github.com/sudormrfbin/cheatsheet.nvim

cheatsheet fuzzy-search nvim nvim-plugin telescope vim

Last synced: 7 days ago
JSON representation

A cheatsheet plugin for neovim with bundled cheatsheets for the editor, multiple vim plugins, nerd-fonts, regex, etc. with a Telescope fuzzy finder interface!

Awesome Lists containing this project

README

        

# cheatsheet.nvim

A searchable cheatsheet for neovim from within the editor using
[Telescope](https://github.com/nvim-telescope/telescope.nvim) (fallback to
displaying in a floating window if Telescope is not installed) with command autofill,
bundled cheats for the editor, vim plugins, nerd-fonts, etc because hoomans suck at
remembering stuff:

![cheatsheet.nvim gif](https://user-images.githubusercontent.com/23398472/121174386-7a182c00-c877-11eb-979b-5d5e6f8267d8.gif)

Font: [mononoki](https://madmalik.github.io/mononoki/), Colorscheme: [onedark](https://github.com/joshdick/onedark.vim), [Dotfiles](https://github.com/sudormrfbin/dotfiles2)

## Table of Contents

* [Features](#features)
* [Quickstart](#quickstart)
* [Installation](#installation)
* [Usage](#usage)
* [Auto Fill Commands From Telescope](#auto-fill-commands-from-telescope)
* [Bundled Cheatsheets](#bundled-cheatsheets)
* [Configuration](#configuration)
* [`cheatsheet.txt` File Format](#cheatsheettxt-file-format)
* [For Plugin Authors](#for-plugin-authors)
* [Acknowledgements](#acknowledgements)

## Features

- Telescope interface to quickly find what you're looking for
- Simple and portable [cheatsheet format](#cheatsheettxt-file-format) -- simple text file, no lua or vimscript involved
- [Fill out command line automatically](#auto-fill-commands-from-telescope) (without execution) if selected item in Telescope is a `:command`
- [Bundled cheatsheets](#bundled-cheatsheets) for:
- nerd-fonts, box drawing characters, lua patterns, etc
- other plugins like gitsigns, sandwich, easy-align, etc
- Enable bundled plugin cheatsheets only for plugins you have installed locally
- Use a `cheatsheet.txt` file from other installed plugins [if found in their directories](#for-plugin-authors)
- Copy cheats directly from Telescope interface

## Quickstart

1. Forget how to do `X`
2. Hit `?` to invoke cheatsheet telescope
3. Type in `X` and find forgotten mapping/command
4. No more ???
5. Profit !!

## Installation

Installing Telescope is not required, but *highly* recommended for
using this plugin effectively. `popup.nvim` and `plenary.nvim`
are used by Telescope.

Using [vim-plug](https://github.com/junegunn/vim-plug)

```viml
Plug 'sudormrfbin/cheatsheet.nvim'

Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
```

Using [dein](https://github.com/Shougo/dein.vim)

```viml
call dein#add('sudormrfbin/cheatsheet.nvim')

call dein#add('nvim-lua/popup.nvim')
call dein#add('nvim-lua/plenary.nvim')
call dein#add('nvim-telescope/telescope.nvim')
```
Using [packer.nvim](https://github.com/wbthomason/packer.nvim)

```lua
use {
'sudormrfbin/cheatsheet.nvim',

requires = {
{'nvim-telescope/telescope.nvim'},
{'nvim-lua/popup.nvim'},
{'nvim-lua/plenary.nvim'},
}
}
```

Subscribe to the [Updates](https://github.com/sudormrfbin/cheatsheet.nvim/issues/1)
issue thread to be notified about new features.

## Usage

Use the `:Cheatsheet` command which automatically uses Telescope if installed
or falls back to showing all the cheatsheet files concatenated in a floating
window. A default mapping `?` is provided for `:Cheatsheet`
(not bound if already in use). By default the `` key is `\`.

Your cheatsheet file is a simple text file with the name `cheatsheet.txt` found in
`~/.config/nvim/` (`~/AppData/Local/nvim/` if you're on Windows) alongside your
`init.vim`. Use the `:CheatsheetEdit` command to open it in a buffer to edit.

| Telescope mappings | Description |
| --- | --- |
| `` | Edit user cheatsheet à la `:CheatsheetEdit` |
| `` | Yank the cheatcode |
| `Enter` | Fill in the command line; see below |

#### Auto Fill Commands From Telescope

On `Enter`, if the current selection is a command, it will be filled
in the command line as if you had typed it (it won't be executed yet).
Note that it will *stop* filling the command line when it encounters a `{`
or `[`. So if the cheat is `:set textwidth={n}`, your commandline will
have `:set textwidth=` typed into it and the cursor at end.

> Since `cheatsheet.nvim` provides it's own commands, it is not required to
> "load" `cheatsheet.nvim` with Telescope which is usually required for plugins
> using Telescope.

## Bundled Cheatsheets

These are the cheatsheets shipped with `cheatsheet.nvim` (PRs welcome!):

- [`default`](./cheatsheets/cheatsheet-default.txt) (vim builtin commands and mappings)
- [`nerd-fonts`](https://www.nerdfonts.com/) (useful for ricing paired with `` for copying the symbol)
- `unicode` (currently only has box drawing characters)
- `regex` (PCRE)
- `markdown` (not fully featured yet)

Plugin cheatsheets (click to expand)

Ideally plugin authors would [supply their own](#for-plugin-authors)
`cheatsheet.txt`, but since that is not possible for every plugin, they are
collected in [cheatsheets/plugins](./cheatsheets/plugins).

- `auto-session`
- `gitsigns.nvim`
- `telescope.nvim`
- `vim-easy-align`
- `vim-sandwich`
- `goto-preview`
- `octo.nvim`

## Configuration

This is the default configuration:

```lua
require("cheatsheet").setup({
-- Whether to show bundled cheatsheets

-- For generic cheatsheets like default, unicode, nerd-fonts, etc
-- bundled_cheatsheets = {
-- enabled = {},
-- disabled = {},
-- },
bundled_cheatsheets = true,

-- For plugin specific cheatsheets
-- bundled_plugin_cheatsheets = {
-- enabled = {},
-- disabled = {},
-- }
bundled_plugin_cheatsheets = true,

-- For bundled plugin cheatsheets, do not show a sheet if you
-- don't have the plugin installed (searches runtimepath for
-- same directory name)
include_only_installed_plugins = true,

-- Key mappings bound inside the telescope window
telescope_mappings = {
[''] = require('cheatsheet.telescope.actions').select_or_fill_commandline,
[''] = require('cheatsheet.telescope.actions').select_or_execute,
[''] = require('cheatsheet.telescope.actions').copy_cheat_value,
[''] = require('cheatsheet.telescope.actions').edit_user_cheatsheet,
}
})
```

For example if you want to bind `Enter` to directly execute commands without
[autofilling](#auto-fill-commands-from-telescope) them
and instead want `Alt-Enter` to autofill, put this in your config:

```lua
require('cheatsheet').setup({
telescope_mappings = {
[''] = require('cheatsheet.telescope.actions').select_or_execute,
[''] = require('cheatsheet.telescope.actions').select_or_fill_commandline,
}
})
```

`bundled_cheatsheets` and `bundled_plugin_cheatsheets` can also be tables to
have more fine grained control for selective usage:

```lua
require("cheatsheet").setup({
bundled_cheatsheets = {
-- only show the default cheatsheet
enabled = { "default" },
},
bundled_plugin_cheatsheets = {
-- show cheatsheets for all plugins except gitsigns
disabled = { "gitsigns.nvim" },
}
})
```

## `cheatsheet.txt` File Format

- `#` starts a normal comment, blank lines are ignored.
- `##` starts a metadata comment for specifying sections and tags.

`## section-name @tag1 @tag2`: here `section-name` is the name of a plugin
or a simple name to group some cheats together. `tag1` and `tag2` are alternative
names that you might later remember the section name with. For example the section
name can be [`sandwich`](https://github.com/machakann/vim-sandwich) and the tag
can be `@surround`.

- A cheat consists of a description and the key/command/anything separated by `|`

```
Open cheatsheet | ?
Open cheatsheet in floating window | :CheatSheet!

View mappings | :map [mapping]
Set text width to {n} | :set tw={n}
```

Like help files, anything in square brackets is `[optional]` and anything
in curly brackets is `{required}` arguments. Some commands require a
register or mark or number before them, and they are marked with `{r}`,
`{m}`, `{n}`, etc. These are not hard and fast rules, simply conventions in
the default cheatsheet -- you can of course ignore them when writing your
own cheats (though if you want commands to be presented in the command line
properly on pressing `Enter`, see the note about it in the Usage section.)

See this project's [cheatsheet](./cheatsheet.txt) and the
[default](./cheatsheets/cheatsheet-default.txt) included one for more examples.

## For Plugin Authors

You can put a `cheatsheet.txt` file in the root of your repo
([like](./cheatsheet.txt) in this repo) and it will be picked up automatically
and displayed on `:Cheatsheet`. You don't have to add the file to your repo
*solely* to support searching it using `cheatsheet.nvim` -- the format is
simple enough to be opened and read normally and can serve as a great
quickstart for users.

## Acknowledgements

This plugin was inspired by (and borrowed some code and the default cheatsheat)
from [cheat40](https://github.com/lifepillar/vim-cheat40).