1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-02 22:30:04 +08:00

chore(cheat): use bundle vim-cheat

This commit is contained in:
wsdjeg 2022-10-25 22:39:37 +08:00
parent ac74bffee5
commit 4446ad9663
7 changed files with 224 additions and 1 deletions

View File

@ -19,7 +19,7 @@ function! SpaceVim#layers#tools#plugins() abort
call add(plugins, ['lymslive/vnote', { 'merged' : 0}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/rainbow', { 'merged' : 0}])
call add(plugins, ['mbbill/fencview', { 'on_cmd' : 'FencAutoDetect'}])
call add(plugins, ['wsdjeg/vim-cheat', { 'on_cmd' : 'Cheat'}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-cheat', { 'on_cmd' : 'Cheat'}])
call add(plugins, ['wsdjeg/Mysql.vim', { 'on_cmd' : 'SQLGetConnection'}])
call add(plugins, ['wsdjeg/SourceCounter.vim', { 'on_cmd' : 'SourceCounter'}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/calendar.vim', { 'on_cmd' : 'Calendar'}])

36
bundle/vim-cheat/.travis.yml vendored Normal file
View File

@ -0,0 +1,36 @@
language: python
cache:
pip: true
env:
matrix:
- LINT=vimlint-errors
- LINT=vimlint
- LINT=vint-errors
- LINT=vint
matrix:
allow_failures:
- env: LINT=vimlint
- env: LINT=vint
install:
- |
if [ "${LINT#vimlint}" != "$LINT" ]; then
git clone --depth=1 https://github.com/syngan/vim-vimlint /tmp/vimlint
git clone --depth=1 https://github.com/ynkdir/vim-vimlparser /tmp/vimlparser
elif [ "${LINT#vint}" != "$LINT" ]; then
virtualenv /tmp/vint && source /tmp/vint/bin/activate && pip install vim-vint
fi
script:
- |
if [ "$LINT" = "vimlint" ]; then
sh /tmp/vimlint/bin/vimlint.sh -l /tmp/vimlint -p /tmp/vimlparser .
elif [ "$LINT" = "vimlint-errors" ]; then
sh /tmp/vimlint/bin/vimlint.sh -E -l /tmp/vimlint -p /tmp/vimlparser .
elif [ "$LINT" = "vint" ]; then
vint .
elif [ "$LINT" = "vint-errors" ]; then
vint --error .
fi

10
bundle/vim-cheat/.vintrc.yaml vendored Normal file
View File

@ -0,0 +1,10 @@
cmdargs:
# Checking more strictly
severity: style_problem
# Enable coloring
color: true
policies:
ProhibitImplicitScopeVariable:
enabled: false

21
bundle/vim-cheat/LICENSE.md vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Wang Shidong
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

14
bundle/vim-cheat/README.md vendored Normal file
View File

@ -0,0 +1,14 @@
### vim-cheat
[![Build Status](https://travis-ci.org/wsdjeg/vim-cheat.svg?branch=master)](https://travis-ci.org/wsdjeg/vim-cheat)
#### Usage:
```
:Cheat <Tab>
will autocomplete the available cheatsheets.
```
Default cheatsheets are available in [simplecheats](https://github.com/artur-shaik/simplecheats).
#### thanks:
1. [cheat.vim](https://github.com/vim-scripts/cheat.vim)
2. [simplecheats](https://github.com/artur-shaik/simplecheats)

30
bundle/vim-cheat/autoload/cheat.vim vendored Normal file
View File

@ -0,0 +1,30 @@
" vim-cheat
"
" Maintainer: Wang Shidong <wsdjeg@outlook.com>
" License: MIT
" Version: 0.1.0
function! s:_update_git() abort
echom "Update git"
let tips = eval(join(systemlist('curl -s https://raw.githubusercontent.com/git-tips/tips/master/tips.json')))
let t = ''
for tip in tips
let t = t . "###" . tip.title . "\n"
let t = t . "```\n" . tip.tip . "\n```\n\n"
endfor
call writefile(split(t,"\n"), g:cheats_dir . 'git.md')
endfunction
function! cheat#Update(cheatName) abort
if exists("*s:_update_" . a:cheatName)
exec "call s:_update_" . a:cheatName ."()"
else
echohl WarningMsg | echom "Has no upstream for " . a:cheatName | echohl None
endif
endfunction
function! cheat#List_sheets() abort
return map(split(globpath(g:cheats_dir, '*'),'\n'), "fnamemodify(v:val, ':t')")
endfunction

112
bundle/vim-cheat/plugin/cheat.vim vendored Normal file
View File

@ -0,0 +1,112 @@
" vim-cheat
"
" Maintainer: Wang Shidong <wsdjeg@outlook.com>
" License: MIT
" Version: 0.1.0
if exists('g:loaded_cheat')
finish
endif
" Set the path to the cheat sheets cache file, can be overriden from
" .vimrc with:
" let g:cheats_dir = '/path/to/your/cache/file'
let g:cheats_dir = get(g:, 'cheats_dir', $HOME . '/.cheat/')
" Set the split direction for the output buffer.
" It can be overriden from .vimrc as well, by setting g:cheats_split to hor | ver
let s:cheats_split = get(g:, 'cheats_split', 'hor')
" Constants
let s:splitCmdMap = { 'ver' : 'vsp' , 'hor' : 'sp' }
let s:cheat_options = {"-add" : "add new cheatsheet" , "-update" : "update current cheatsheet"}
" Func Defs
func! FindOrCreateOutWin(bufName)
let l:outWinNr = bufwinnr(a:bufName)
let l:outBufNr = bufnr(a:bufName)
" Find or create a window for the bufName
if l:outWinNr == -1
" Create a new window
exec s:splitCmdMap[s:cheats_split]
let l:outWinNr = bufwinnr('%')
if l:outBufNr != -1
" The buffer already exists. Open it here.
exec 'b'.l:outBufNr
endif
" Jump back to the previous window the user was editing in.
exec 'wincmd p'
endif
" Find the buffer number or create one for bufName
if l:outBufNr == -1
" Jump to the output window
exec l:outWinNr.' wincmd w'
" Open a new output buffer
exec 'e '.a:bufName
setlocal noswapfile
setlocal buftype=nofile
setlocal wrap
let l:outBufNr = bufnr('%')
" Jump back to the previous window the user was editing in.
exec 'wincmd p'
endif
return l:outBufNr
endf
func! RunAndRedirectOut(cheatName, bufName)
" Change to the output buffer window
let l:outWinNr = bufwinnr(a:bufName)
exec l:outWinNr.' wincmd w'
call append(0, readfile(fnameescape(g:cheats_dir . a:cheatName)))
normal! gg
endf
func! CheatCompletion(ArgLead, CmdLine, CursorPos)
echom "arglead:[".a:ArgLead ."] cmdline:[" .a:CmdLine ."] cursorpos:[" .a:CursorPos ."]"
if a:ArgLead =~ '^-\w*'
return join(keys(s:cheat_options),"\n")
endif
return join(cheat#List_sheets(),"\n")
endf
func! Cheat(...)
let l:c = a:0 != 0 ? a:000 : split(input('Cheat Sheet: ', '', 'custom,CheatCompletion'),' ')
if len(l:c) == 1 && l:c[0] !~ '^-\w*'
let l:outBuf = FindOrCreateOutWin('-cheat_output-')
call RunAndRedirectOut(l:c[0], l:outBuf)
elseif len(l:c) == 2 && l:c[0] ==# '-add' && l:c[1] !~ '^-\w*'
if index(cheat#List_sheets(), l:c[1]) == -1
exe "split ". g:cheats_dir . fnameescape(l:c[1])
else
echohl WarningMsg | echom "cheets " . l:c[1] . " already exists" | echohl None
endif
elseif len(l:c) == 2 && l:c[0] ==# '-update' && l:c[1] !~ '^-\w*'
call cheat#Update(l:c[1])
endif
endf
func! CheatCurrent()
call Cheat(expand('<cword>'))
endf
" Commands Mappings
comm! -nargs=* -complete=custom,CheatCompletion Cheat :call Cheat(<f-args>)
comm! CheatCurrent :call CheatCurrent()
" Disable default mappings
" let g:Cheat_EnableDefaultMappings = 0
if get(g:, 'Cheat_EnableDefaultMappings', 1)
if empty(maparg('<Leader>C', 'n'))
nnoremap <Leader>C :call Cheat()<CR>
endif
" Ask for cheatsheet for the word under cursor
if empty(maparg('<Leader>ch', 'n'))
nmap <leader>ch :call CheatCurrent()<CR>
endif
endif
let g:loaded_cheat = 1