From 5414dcf954678b99ea397c688705dcfcb0eb70b8 Mon Sep 17 00:00:00 2001 From: Maxim Likhachev Date: Wed, 5 Feb 2020 16:02:15 +0300 Subject: [PATCH] vim: plugins: ++cheat40 --- etc/soft/vim/vim/+plugins/vim-cheat40/Readme.md | 56 ++++++++++++++++++++++ .../vim/+plugins/vim-cheat40/autoload/cheat40.vim | 45 +++++++++++++++++ .../vim/+plugins/vim-cheat40/plugin/cheat40.vim | 17 +++++++ .../vim/+plugins/vim-cheat40/syntax/cheat40.vim | 45 +++++++++++++++++ etc/soft/vim/vim/cheat40.txt | 33 +++++++++++++ etc/soft/vim/vimrc | 9 ++-- 6 files changed, 202 insertions(+), 3 deletions(-) create mode 100644 etc/soft/vim/vim/+plugins/vim-cheat40/Readme.md create mode 100644 etc/soft/vim/vim/+plugins/vim-cheat40/autoload/cheat40.vim create mode 100644 etc/soft/vim/vim/+plugins/vim-cheat40/plugin/cheat40.vim create mode 100644 etc/soft/vim/vim/+plugins/vim-cheat40/syntax/cheat40.vim create mode 100644 etc/soft/vim/vim/cheat40.txt diff --git a/etc/soft/vim/vim/+plugins/vim-cheat40/Readme.md b/etc/soft/vim/vim/+plugins/vim-cheat40/Readme.md new file mode 100644 index 0000000..dce7b8b --- /dev/null +++ b/etc/soft/vim/vim/+plugins/vim-cheat40/Readme.md @@ -0,0 +1,56 @@ +# Cheat40: a cheat sheet for Vim + +Cheat40 is a foldable extensible 40-column cheat sheet that you may open in Vim +by pressing `?` (the mapping is customizable, of course). Mappings and +commands are organized like the menus of a GUI app: there is a File section, an +Edit section, a View section, and so on. For each item the description comes +first, because one typically wants to find how to execute a task, not what the +meaning of a key sequence is (there is Vim's help for that). Syntax coloring and +the use of `conceal` keep the cheat sheet clutter-free and easy to read. + + +## Installation + +If your Vim supports packages (`echo has('packages')` prints `1`), I strongly +recommend that you use them. Just clone this repo inside `pack/*/start`, e.g., + + cd ~/.vim + git clone https://github.com/lifepillar/vim-cheat40.git pack/bundle/start/cheat40 + +Otherwise, use your preferred installation method. + + +## Extending the cheat sheet + +You may extend the cheat sheet by putting one or more files called `cheat40.txt` +anywhere in your `runtimepath` (e.g., in `~/.vim`). Cheat40 searches +`runtimepath` for such files and concatenates their content. This allows plugin +developers to provide a cheat sheet for their plugins by putting a `cheat40.txt` +file in the top folder of their plugins. + +If you do not want to use the default cheat sheet that comes with this plugin, +set the following variable in your `.vimrc`: + + let g:cheat40_use_default = 0 + +In this case, I recommend that you copy `cheat40.txt` into your `.vim` folder +and modify it to suit your needs. + +The syntax of a cheat sheet is very simple: + +- foldable sections use Vim's default markers (`{{{` and `}}}`) (see `:h + fold-marker`); +- sections of the form `About … {{{ … }}}` are interpreted as block comments; +- lines starting with a `#` are interpreted as line comments; +- each line, except for comments and section markers, should be 40 columns wide + (comments and section markers may be shorter than that); +- each item consists of a description, a key sequence, and a label; +- the description must fit in columns 1–25 (long descriptions may be split into + several lines); +- the key sequence and the label must fit in columns 26–40 (long key sequences + should be split into several lines); +- the label is a right-justified sequence of one or more characters (e.g., `N` + for Normal mode, `I` for Insert mode, and so on). + +See the cheat sheet inside the plugin for the details. + diff --git a/etc/soft/vim/vim/+plugins/vim-cheat40/autoload/cheat40.vim b/etc/soft/vim/vim/+plugins/vim-cheat40/autoload/cheat40.vim new file mode 100644 index 0000000..e44c37c --- /dev/null +++ b/etc/soft/vim/vim/+plugins/vim-cheat40/autoload/cheat40.vim @@ -0,0 +1,45 @@ +" Author: Lifepillar +" Maintainer: Lifepillar +" License: Distributed under the same terms as Vim itself. See :help license. + +let s:cheat40_dir = fnamemodify(resolve(expand(':p')), ':h:h') + +" Courtesy of Pathogen +function! s:slash() abort + return !exists("+shellslash") || &shellslash ? '/' : '\' +endfunction + + +" Split a path into a list. Code from Pathogen. +function! s:split(path) abort + if type(a:path) == type([]) | return a:path | endif + if empty(a:path) | return [] | endif + let split = split(a:path,'\\\@ + nnoremap q @=winnr("#")c +endf diff --git a/etc/soft/vim/vim/+plugins/vim-cheat40/plugin/cheat40.vim b/etc/soft/vim/vim/+plugins/vim-cheat40/plugin/cheat40.vim new file mode 100644 index 0000000..e7cc592 --- /dev/null +++ b/etc/soft/vim/vim/+plugins/vim-cheat40/plugin/cheat40.vim @@ -0,0 +1,17 @@ +" Author: Lifepillar +" Maintainer: Lifepillar +" License: Distributed under the same terms as Vim itself. See :help license. + +if exists("g:loaded_cheatsheet") || &cp || v:version < 700 + finish +endif +let g:loaded_cheatsheet = 1 + +command -bar -nargs=0 -bang Cheat40 call cheat40#open("" ==# '!') + +"if mapcheck("?", "n") == "" + "nmap ? :Cheat40 +"endif + +nmap ? :Cheat40 + diff --git a/etc/soft/vim/vim/+plugins/vim-cheat40/syntax/cheat40.vim b/etc/soft/vim/vim/+plugins/vim-cheat40/syntax/cheat40.vim new file mode 100644 index 0000000..8f9de42 --- /dev/null +++ b/etc/soft/vim/vim/+plugins/vim-cheat40/syntax/cheat40.vim @@ -0,0 +1,45 @@ +" Author: Lifepillar +" Maintainer: Lifepillar +" License: Distributed under the same terms as Vim itself. See :help license. + +if exists("b:current_syntax") + finish +endif + +syntax case ignore +syntax sync fromstart + +syn match Cheat40Descr /\%1v.*\%<26v./ +syn match Cheat40Command /\%26v.*\%<41v./ contains=Cheat40Mode,Cheat40Angle,Cheat40DblAngle +syn match Cheat40Header /^.*{{{\d*$/ contains=Cheat40BeginSection +syn region Cheat40About start=/^About.*{{{\d*$/ end=/^}}}$/ keepend contains=Cheat40BeginSection,Cheat40EndSection,Cheat40Tag,Cheat40Angle,Cheat40DblAngle +syn match Cheat40FirstLine /\%1l.*/ +syn match Cheat40BeginSection /{{{\d*/ contained conceal +syn match Cheat40EndSection /^}}}$/ conceal +syn match Cheat40Tag /`[^` \t]\+`/hs=s+1,he=e-1 contained contains=Cheat40Backtick,Cheat40Runtime +syn match Cheat40Backtick /`/ contained conceal +syn match Cheat40Mode /[NICVTOM*]\+\%>40v/ +syn match Cheat40Angle /‹[^› \t]\+›/ contained +syn match Cheat40DblAngle /«[^» \t]\+»/ contained +syn match Cheat40Comment /^#.*$/ contains=Cheat40Hash +syn match Cheat40Hash /^#\s*/ contained conceal +syn match Cheat40Runtime /\$VIMRUNTIME\/doc\// contained conceal + +hi def link Cheat40Descr Normal +hi def link Cheat40Command Constant +hi def link Cheat40Header Title +hi def link Cheat40About Comment +hi def link Cheat40FirstLine Statement +hi def link Cheat40BeginSection Ignore +hi def link Cheat40EndSection Ignore +hi def link Cheat40Tag Tag +hi def link Cheat40Backtick Ignore +hi def link Cheat40Mode Type +hi def link Cheat40Angle Identifier +hi def link Cheat40DblAngle Label +hi def link Cheat40Comment Comment +hi def link Cheat40Hash Ignore +hi def link Cheat40Runtime Ignore + +let b:current_syntax = "cheat40" + diff --git a/etc/soft/vim/vim/cheat40.txt b/etc/soft/vim/vim/cheat40.txt new file mode 100644 index 0000000..c32907d --- /dev/null +++ b/etc/soft/vim/vim/cheat40.txt @@ -0,0 +1,33 @@ +Press q to dismiss, to lose focus + +Перемещение {{{1 + + В начало экрана H N + В центр экрана M N + В конец экрана L N + + Вперёд на один экран ^F N + Назад на один экран ^B N + Вперёд на полэкрана ^D N + Назад на полэкрана ^U N + + Строку наверх экрана z N + Строку в центр экрана z. N + Строку вниз экрана z- N + +ex {{{1 + + Замена в найденных стр. :g/../s/a/b/g C + Замена с подтверждением :s/a/b/gc C + Повтор последней замены :%&g C + +Регистры {{{1 + + Содержимое регистров :registers N + Копировать строку в `a` "ayy N + Добавить строку в `a` "Ayy N + +Разное {{{1 + + Открыть ссылку gx N + diff --git a/etc/soft/vim/vimrc b/etc/soft/vim/vimrc index e450e24..168e507 100644 --- a/etc/soft/vim/vimrc +++ b/etc/soft/vim/vimrc @@ -896,6 +896,12 @@ autocmd User Startified setlocal buflisted " }}} +" cheat40 {{{ + +let g:cheat40_use_default = 0 + +" }}} + " floaterm {{{ let g:floaterm_keymap_toggle = ',s' @@ -906,8 +912,5 @@ let g:floaterm_borderchars = ['─', '│', '─', '│', '┌', '┐', '┘', ' " }}} - -" }}} - " }}}###########################################################################