6 changed files with 202 additions and 3 deletions
			
			
		| @ -0,0 +1,56 @@@@ -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 `<leader>?` (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. | ||||
| 
 | ||||
| @ -0,0 +1,45 @@@@ -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('<sfile>: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,'\\\@<!\%(\\\\\)*\zs,') | ||||
|   return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")') | ||||
| endfunction | ||||
| 
 | ||||
| fun! cheat40#open(newtab) | ||||
|   if a:newtab | ||||
|     tabnew +setlocal\ buftype=nofile\ bufhidden=hide\ nobuflisted\ noswapfile\ winfixwidth | ||||
|   else | ||||
|     botright 40vnew +setlocal\ buftype=nofile\ bufhidden=hide\ nobuflisted\ noswapfile\ winfixwidth | ||||
|   endif | ||||
|   if get(g:, 'cheat40_use_default', 1) | ||||
|     execute '$read' s:cheat40_dir.s:slash().'cheat40.txt' | ||||
|   endif | ||||
|   for glob in reverse(s:split(&runtimepath)) | ||||
|     for cs in filter(map(filter(split(glob(glob), "\n"), 'v:val !~ "cheat40"'), 'v:val.s:slash()."cheat40.txt"'), 'filereadable(v:val)') | ||||
|       execute "$read" cs | ||||
|     endfor | ||||
|   endfor | ||||
|   norm ggd_ | ||||
|   setlocal foldmethod=marker foldtext=substitute(getline(v:foldstart),'\\s\\+{{{.*$','','') | ||||
|   execute 'setlocal foldlevel='.get(g:, 'cheat40_foldlevel', 1) | ||||
|   setlocal concealcursor=nc conceallevel=3 | ||||
|   setlocal expandtab nonumber norelativenumber nospell nowrap textwidth=40 | ||||
|   setlocal fileencoding=utf-8 filetype=cheat40 nomodifiable | ||||
|   setlocal iskeyword=@,48-57,-,/,.,192-255 | ||||
|   execute "setlocal" "tags=".s:cheat40_dir.s:slash()."tags" | ||||
|   nnoremap <silent> <buffer> <tab> <c-w><c-p> | ||||
|   nnoremap <silent> <buffer> q <c-w><c-p>@=winnr("#")<cr><c-w>c | ||||
| endf | ||||
| @ -0,0 +1,17 @@@@ -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("<bang>" ==# '!') | ||||
| 
 | ||||
| "if mapcheck("<leader>?", "n") == "" | ||||
|   "nmap <unique> <leader>? :<c-u>Cheat40<cr> | ||||
| "endif | ||||
| 
 | ||||
| nmap <leader>? :<c-u>Cheat40<cr> | ||||
| 
 | ||||
| @ -0,0 +1,45 @@@@ -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" | ||||
| 
 | ||||
| @ -0,0 +1,33 @@@@ -0,0 +1,33 @@ | ||||
| Press q to dismiss, <Tab> to lose focus | ||||
| 
 | ||||
| Перемещение {{{1 | ||||
| 
 | ||||
|  В начало экрана          H             N | ||||
|  В центр  экрана          M             N | ||||
|  В конец  экрана          L             N | ||||
| 
 | ||||
|  Вперёд на один экран     ^F            N | ||||
|  Назад  на один экран     ^B            N | ||||
|  Вперёд на полэкрана      ^D            N | ||||
|  Назад  на полэкрана      ^U            N | ||||
| 
 | ||||
|  Строку наверх  экрана    z<ENTER>      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 | ||||
| 
 | ||||
					Loading…
					
					
				
		Reference in new issue