mirror of
1
0
Fork 0

Update vim-gist.

This commit is contained in:
Kurtis Moxley 2022-05-19 22:00:33 +08:00
parent 7747765240
commit f219991e20
10 changed files with 303 additions and 547 deletions

View File

@ -1,11 +0,0 @@
all : gist-vim.zip
remove-zip:
-rm -f doc/tags
-rm -f gist-vim.zip
gist-vim.zip: remove-zip
zip -r gist-vim.zip autoload plugin doc README.mkd
release: gist-vim.zip
vimup update-script gist.vim

View File

@ -2,7 +2,7 @@
This is a vimscript for creating gists (http://gist.github.com).
For the latest version please see https://github.com/mattn/gist-vim.
For the latest version please see https://github.com/mattn/vim-gist.
## Usage:
@ -87,6 +87,10 @@ For the latest version please see https://github.com/mattn/gist-vim.
:Gist -l mattn
- Specify the number of gists listed:
:Gist -l -n 100
- List everyone's gists.
:Gist -la
@ -103,14 +107,14 @@ For the latest version please see https://github.com/mattn/gist-vim.
- Useful mappings on the gist-listing buffer:
- Both `o` or `Enter` open the gist file in a new buffer, and close the
gist-vim listing one.
vim-gist listing one.
- `b` opens the gist file in a browser; this is necessary because
`Shift-Enter` (as was originally) only works for GUI vim.
- `y` copies the contents of the selected gist to the clipboard, and
closes the gist-vim buffer.
closes the vim-gist buffer.
- `p` pastes the contents of the selected gist to the buffer from where
gist-vim was called, and closes the gist-vim buffer.
- Hitting `Escape` or `Tab` at the gist-vim buffer closes it.
vim-gist was called, and closes the vim-gist buffer.
- Hitting `Escape` or `Tab` at the vim-gist buffer closes it.
- Gist listing has fixed-length columns now, more amenable to eye inspection.
Every line on the gist-listing buffer contains the gist id, name and
@ -188,6 +192,10 @@ You need to either set global git config:
$ git config --global github.user Username
If you want to list more than 30 gists per page (maximum is 100):
let g:gist_per_page_limit = 100
## License:
Copyright 2010 by Yasuhiro Matsumoto
@ -237,7 +245,7 @@ If you want to use latest one:
Add the following lines to your `.vimrc`.
Bundle 'mattn/webapi-vim'
Bundle 'mattn/gist-vim'
Bundle 'mattn/vim-gist'
Now restart Vim and run `:BundleInstall`.
@ -245,7 +253,7 @@ Now restart Vim and run `:BundleInstall`.
Add the following line to your `.vimrc`.
NeoBundle 'mattn/gist-vim', {'depends': 'mattn/webapi-vim'}
NeoBundle 'mattn/vim-gist', {'depends': 'mattn/webapi-vim'}
## Requirements:
@ -262,15 +270,15 @@ First, you need to set your GitHub username in git's global configuration:
$ git config --global github.user <username>
Then gist-vim will ask for your password in order to create an access
token. If you have two-factor authentication enabled, gist-vim will also
Then vim-gist will ask for your password in order to create an access
token. If you have two-factor authentication enabled, vim-gist will also
prompt you to enter the two-factor key you receive.
NOTE:
If you want you can set it directly to `g:github_user` and `g:gist_token`.
Whichever type of authentication you use, your GitHub password will not be
stored, only a OAuth access token produced specifically for gist-vim. The
stored, only a OAuth access token produced specifically for vim-gist. The
token is stored in `~/.gist-vim`. If you stop using the plugin, you can
easily remove this file. To revoke the associated GitHub token, go to the
list of ["Authorized applications" on GitHub's "Account Settings"

View File

@ -3,7 +3,7 @@
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 10-Oct-2016.
" Version: 7.3
" WebPage: http://github.com/mattn/gist-vim
" WebPage: http://github.com/mattn/vim-gist
" License: BSD
let s:save_cpo = &cpoptions
@ -134,7 +134,7 @@ function! s:truncate(str, num)
let str = substitute(str, mx_first, '\2', '')
endwhile
while width + 1 <= a:num
let ret .= " "
let ret .= ' '
let width = width + 1
endwhile
return ret
@ -160,7 +160,7 @@ function! s:format_gist(gist) abort
let desc = substitute(desc, ' ', ' ', 'g')
" Display a nice formatted (and truncated if needed) table of gists on screen
" Calculate field lengths for gist-listing formatting on screen
redir =>a |exe "sil sign place buffer=".bufnr('')|redir end
redir =>a |exe 'sil sign place buffer='.bufnr('')|redir end
let signlist = split(a, '\n')
let width = winwidth(0) - ((&number||&relativenumber) ? &numberwidth : 0) - &foldcolumn - (len(signlist) > 2 ? 2 : 0)
let idlen = 33
@ -171,7 +171,7 @@ endfunction
" Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it.
let s:bufprefix = 'gist' . (has('unix') ? ':' : '_')
function! s:GistList(gistls, page) abort
function! s:GistList(gistls, page, pagelimit) abort
if a:gistls ==# '-all'
let url = g:gist_api_url.'gists/public'
elseif get(g:, 'gist_show_privates', 0) && a:gistls ==# 'starred'
@ -196,9 +196,11 @@ function! s:GistList(gistls, page) abort
exec 'silent noautocmd split' s:bufprefix.a:gistls
endif
endif
let url = url . '?per_page=' . a:pagelimit
if a:page > 1
let oldlines = getline(0, line('$'))
let url = url . '?page=' . a:page
let url = url . '&page=' . a:page
endif
setlocal modifiable
@ -214,7 +216,7 @@ function! s:GistList(gistls, page) abort
echohl ErrorMsg | echomsg v:errmsg | echohl None
return
endif
let res = webapi#http#get(url, '', { "Authorization": auth })
let res = webapi#http#get(url, '', { 'Authorization': auth })
if v:shell_error != 0
bw!
redraw
@ -330,7 +332,7 @@ function! gist#list(user, ...) abort
if len(auth) == 0
return []
endif
let res = webapi#http#get(url, '', { "Authorization": auth })
let res = webapi#http#get(url, '', { 'Authorization': auth })
return webapi#json#decode(res.content)
endfunction
@ -339,7 +341,7 @@ function! s:GistGetFileName(gistid) abort
if len(auth) == 0
return ''
endif
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": auth })
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { 'Authorization': auth })
let gist = webapi#json#decode(res.content)
if has_key(gist, 'files')
return sort(keys(gist.files))[0]
@ -352,7 +354,7 @@ function! s:GistDetectFiletype(gistid) abort
if len(auth) == 0
return ''
endif
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": auth })
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { 'Authorization': auth })
let gist = webapi#json#decode(res.content)
let filename = sort(keys(gist.files))[0]
let ext = fnamemodify(filename, ':e')
@ -380,7 +382,7 @@ endfunction
function! s:GistGet(gistid, clipboard) abort
redraw | echon 'Getting gist... '
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": s:GistGetAuthHeader() })
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { 'Authorization': s:GistGetAuthHeader() })
if res.status =~# '^2'
try
let gist = webapi#json#decode(res.content)
@ -459,10 +461,10 @@ function! s:GistGet(gistid, clipboard) abort
let content = gist.files[filename].content
call setline(1, split(content, "\n"))
let b:gist = {
\ "filename": filename,
\ "id": gist.id,
\ "description": gist.description,
\ "private": gist.public =~ 'true',
\ 'filename': filename,
\ 'id': gist.id,
\ 'description': gist.description,
\ 'private': gist.public =~# 'true',
\}
catch
let &undolevels = old_undolevels
@ -527,16 +529,16 @@ function! s:GistListAction(mode) abort
return
endif
if line =~# '^more\.\.\.$'
call s:GistList(b:gistls, b:page+1)
call s:GistList(b:gistls, b:page+1, g:gist_per_page_limit)
return
endif
endfunction
function! s:GistUpdate(content, gistid, gistnm, desc) abort
let gist = { "id": a:gistid, "files" : {}, "description": "","public": function('webapi#json#true') }
let gist = { 'id': a:gistid, 'files' : {}, 'description': '','public': function('webapi#json#true') }
if exists('b:gist')
if has_key(b:gist, 'filename') && len(a:gistnm) > 0
let gist.files[b:gist.filename] = { "content": '', "filename": b:gist.filename }
let gist.files[b:gist.filename] = { 'content': '', 'filename': b:gist.filename }
let b:gist.filename = a:gistnm
endif
if has_key(b:gist, 'private') && b:gist.private | let gist['public'] = function('webapi#json#false') | endif
@ -560,25 +562,25 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort
if a:desc !=# ' '
let gist['description'] = a:desc
else
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { "Authorization": auth })
let res = webapi#http#get(g:gist_api_url.'gists/'.a:gistid, '', { 'Authorization': auth })
if res.status =~# '^2'
let old_gist = webapi#json#decode(res.content)
let gist['description'] = old_gist.description
endif
endif
let gist.files[filename] = { "content": a:content, "filename": filename }
let gist.files[filename] = { 'content': a:content, 'filename': filename }
redraw | echon 'Updating gist... '
let res = webapi#http#post(g:gist_api_url.'gists/' . a:gistid,
\ webapi#json#encode(gist), {
\ "Authorization": auth,
\ "Content-Type": "application/json",
\ 'Authorization': auth,
\ 'Content-Type': 'application/json',
\})
if res.status =~# '^2'
let obj = webapi#json#decode(res.content)
let loc = obj['html_url']
let b:gist = {"id": a:gistid, "filename": filename}
let b:gist = {'id': a:gistid, 'filename': filename}
setlocal nomodified
redraw | echomsg 'Done: '.loc
else
@ -598,8 +600,8 @@ function! s:GistDelete(gistid) abort
redraw | echon 'Deleting gist... '
let res = webapi#http#post(g:gist_api_url.'gists/'.a:gistid, '', {
\ "Authorization": auth,
\ "Content-Type": "application/json",
\ 'Authorization': auth,
\ 'Content-Type': 'application/json',
\}, 'DELETE')
if res.status =~# '^2'
if exists('b:gist')
@ -651,13 +653,13 @@ endfunction
" GistID: 123123
"
function! s:GistPost(content, private, desc, anonymous) abort
let gist = { "files" : {}, "description": "","public": function('webapi#json#true') }
let gist = { 'files' : {}, 'description': '','public': function('webapi#json#true') }
if a:desc !=# ' ' | let gist['description'] = a:desc | endif
if a:private | let gist['public'] = function('webapi#json#false') | endif
let filename = s:get_current_filename(1)
let gist.files[filename] = { "content": a:content, "filename": filename }
let gist.files[filename] = { 'content': a:content, 'filename': filename }
let header = {"Content-Type": "application/json"}
let header = {'Content-Type': 'application/json'}
if !a:anonymous
let auth = s:GistGetAuthHeader()
if len(auth) == 0
@ -674,10 +676,10 @@ function! s:GistPost(content, private, desc, anonymous) abort
let obj = webapi#json#decode(res.content)
let loc = obj['html_url']
let b:gist = {
\ "filename": filename,
\ "id": matchstr(loc, '[^/]\+$'),
\ "description": gist['description'],
\ "private": a:private,
\ 'filename': filename,
\ 'id': matchstr(loc, '[^/]\+$'),
\ 'description': gist['description'],
\ 'private': a:private,
\}
if s:update_GistID(b:gist['id'])
Gist -e
@ -695,7 +697,7 @@ function! s:GistPostBuffers(private, desc, anonymous) abort
let bn = bufnr('%')
let query = []
let gist = { "files" : {}, "description": "","public": function('webapi#json#true') }
let gist = { 'files' : {}, 'description': '','public': function('webapi#json#true') }
if a:desc !=# ' ' | let gist['description'] = a:desc | endif
if a:private | let gist['public'] = function('webapi#json#false') | endif
@ -708,12 +710,12 @@ function! s:GistPostBuffers(private, desc, anonymous) abort
silent! exec 'buffer!' bufnr
let content = join(getline(1, line('$')), "\n")
let filename = s:get_current_filename(index)
let gist.files[filename] = { "content": content, "filename": filename }
let gist.files[filename] = { 'content': content, 'filename': filename }
let index = index + 1
endfor
silent! exec 'buffer!' bn
let header = {"Content-Type": "application/json"}
let header = {'Content-Type': 'application/json'}
if !a:anonymous
let auth = s:GistGetAuthHeader()
if len(auth) == 0
@ -730,10 +732,10 @@ function! s:GistPostBuffers(private, desc, anonymous) abort
let obj = webapi#json#decode(res.content)
let loc = obj['html_url']
let b:gist = {
\ "filename": filename,
\ "id": matchstr(loc, '[^/]\+$'),
\ "description": gist['description'],
\ "private": a:private,
\ 'filename': filename,
\ 'id': matchstr(loc, '[^/]\+$'),
\ 'description': gist['description'],
\ 'private': a:private,
\}
if s:update_GistID(b:gist['id'])
Gist -e
@ -761,10 +763,12 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
let editpost = 0
let anonymous = get(g:, 'gist_post_anonymous', 0)
let openbrowser = 0
let setpagelimit = 0
let pagelimit = g:gist_per_page_limit
let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$'
let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$'
if strlen(g:github_user) == 0 && anonymous == 0
echohl ErrorMsg | echomsg 'You have not configured a Github account. Read '':help gist-vim-setup''.' | echohl None
echohl ErrorMsg | echomsg 'You have not configured a Github account. Read '':help gist-setup''.' | echohl None
return
endif
if a:bang == '!'
@ -788,6 +792,14 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
elseif arg =~# '^\(-G\|--gitclone\)$\C' && gistidbuf !=# '' && g:gist_api_url ==# 'https://api.github.com/' && has_key(b:, 'gist') && has_key(b:gist, 'id')
exe '!' printf('git clone git@github.com:%s', b:gist['id'])
return
elseif setpagelimit == 1
let setpagelimit = 0
let pagelimit = str2nr(arg)
if pagelimit < 1 || pagelimit > 100
echohl ErrorMsg | echomsg 'Page limit should be between 1 and 100: '.arg | echohl None
unlet args
return 0
endif
elseif arg =~# '^\(-la\|--listall\)$\C'
let gistls = '-all'
elseif arg =~# '^\(-ls\|--liststar\)$\C'
@ -828,7 +840,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
echohl ErrorMsg | echomsg v:errmsg | echohl None
else
let gistid = gistidbuf
let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { "Authorization": auth }, 'PUT')
let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { 'Authorization': auth }, 'PUT')
if res.status =~# '^2'
echomsg 'Starred' gistid
else
@ -842,7 +854,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
echohl ErrorMsg | echomsg v:errmsg | echohl None
else
let gistid = gistidbuf
let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { "Authorization": auth }, 'DELETE')
let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/star', '', { 'Authorization': auth }, 'DELETE')
if res.status =~# '^2'
echomsg 'Unstarred' gistid
else
@ -857,7 +869,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
return
else
let gistid = gistidbuf
let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/fork', '', { "Authorization": auth })
let res = webapi#http#post(g:gist_api_url.'gists/'.gistid.'/fork', '', { 'Authorization': auth })
if res.status =~# '^2'
let obj = webapi#json#decode(res.content)
let gistid = obj['id']
@ -868,6 +880,14 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
endif
elseif arg =~# '^\(-b\|--browser\)$\C'
let openbrowser = 1
elseif arg =~# '^\(-n\|--per-page\)$\C'
if len(gistls) > 0
let setpagelimit = 1
else
echohl ErrorMsg | echomsg 'Page limit can be set only for list commands'.arg | echohl None
unlet args
return 0
endif
elseif arg !~# '^-' && len(gistnm) == 0
if gistdesc !=# ' '
let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$')
@ -904,7 +924,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
endif
if len(gistls) > 0
call s:GistList(gistls, 1)
call s:GistList(gistls, 1, pagelimit)
elseif len(gistid) > 0 && editpost == 0 && deletepost == 0
call s:GistGet(gistid, clipboard)
else
@ -986,12 +1006,12 @@ function! s:GistGetAuthHeader() abort
let note_url = 'http://www.vim.org/scripts/script.php?script_id=2423'
let insecureSecret = printf('basic %s', webapi#base64#b64encode(g:github_user.':'.password))
let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({
\ "scopes" : ["gist"],
\ "note" : note,
\ "note_url" : note_url,
\ 'scopes' : ['gist'],
\ 'note' : note,
\ 'note_url' : note_url,
\}), {
\ "Content-Type" : "application/json",
\ "Authorization" : insecureSecret,
\ 'Content-Type' : 'application/json',
\ 'Authorization' : insecureSecret,
\})
let h = filter(res.header, 'stridx(v:val, "X-GitHub-OTP:") == 0')
if len(h)
@ -1001,13 +1021,13 @@ function! s:GistGetAuthHeader() abort
return ''
endif
let res = webapi#http#post(g:gist_api_url.'authorizations', webapi#json#encode({
\ "scopes" : ["gist"],
\ "note" : note,
\ "note_url" : note_url,
\ 'scopes' : ['gist'],
\ 'note' : note,
\ 'note_url' : note_url,
\}), {
\ "Content-Type" : "application/json",
\ "Authorization" : insecureSecret,
\ "X-GitHub-OTP" : otp,
\ 'Content-Type' : 'application/json',
\ 'Authorization' : insecureSecret,
\ 'X-GitHub-OTP' : otp,
\})
endif
let authorization = webapi#json#decode(res.content)
@ -1025,138 +1045,138 @@ function! s:GistGetAuthHeader() abort
endfunction
let s:extmap = extend({
\".adb": "ada",
\".ahk": "ahk",
\".arc": "arc",
\".as": "actionscript",
\".asm": "asm",
\".asp": "asp",
\".aw": "php",
\".b": "b",
\".bat": "bat",
\".befunge": "befunge",
\".bmx": "bmx",
\".boo": "boo",
\".c-objdump": "c-objdump",
\".c": "c",
\".cfg": "cfg",
\".cfm": "cfm",
\".ck": "ck",
\".cl": "cl",
\".clj": "clj",
\".cmake": "cmake",
\".coffee": "coffee",
\".cpp": "cpp",
\".cppobjdump": "cppobjdump",
\".cs": "csharp",
\".css": "css",
\".cw": "cw",
\".d-objdump": "d-objdump",
\".d": "d",
\".darcspatch": "darcspatch",
\".diff": "diff",
\".duby": "duby",
\".dylan": "dylan",
\".e": "e",
\".ebuild": "ebuild",
\".eclass": "eclass",
\".el": "lisp",
\".erb": "erb",
\".erl": "erlang",
\".f90": "f90",
\".factor": "factor",
\".feature": "feature",
\".fs": "fs",
\".fy": "fy",
\".go": "go",
\".groovy": "groovy",
\".gs": "gs",
\".gsp": "gsp",
\".haml": "haml",
\".hs": "haskell",
\".html": "html",
\".hx": "hx",
\".ik": "ik",
\".ino": "ino",
\".io": "io",
\".j": "j",
\".java": "java",
\".js": "javascript",
\".json": "json",
\".jsp": "jsp",
\".kid": "kid",
\".lhs": "lhs",
\".lisp": "lisp",
\".ll": "ll",
\".lua": "lua",
\".ly": "ly",
\".m": "objc",
\".mak": "mak",
\".man": "man",
\".mao": "mao",
\".matlab": "matlab",
\".md": "markdown",
\".minid": "minid",
\".ml": "ml",
\".moo": "moo",
\".mu": "mu",
\".mustache": "mustache",
\".mxt": "mxt",
\".myt": "myt",
\".n": "n",
\".nim": "nim",
\".nu": "nu",
\".numpy": "numpy",
\".objdump": "objdump",
\".ooc": "ooc",
\".parrot": "parrot",
\".pas": "pas",
\".pasm": "pasm",
\".pd": "pd",
\".phtml": "phtml",
\".pir": "pir",
\".pl": "perl",
\".po": "po",
\".py": "python",
\".pytb": "pytb",
\".pyx": "pyx",
\".r": "r",
\".raw": "raw",
\".rb": "ruby",
\".rhtml": "rhtml",
\".rkt": "rkt",
\".rs": "rs",
\".rst": "rst",
\".s": "s",
\".sass": "sass",
\".sc": "sc",
\".scala": "scala",
\".scm": "scheme",
\".scpt": "scpt",
\".scss": "scss",
\".self": "self",
\".sh": "sh",
\".sml": "sml",
\".sql": "sql",
\".st": "smalltalk",
\".swift": "swift",
\".tcl": "tcl",
\".tcsh": "tcsh",
\".tex": "tex",
\".textile": "textile",
\".tpl": "smarty",
\".twig": "twig",
\".txt" : "text",
\".v": "verilog",
\".vala": "vala",
\".vb": "vbnet",
\".vhd": "vhdl",
\".vim": "vim",
\".weechatlog": "weechatlog",
\".xml": "xml",
\".xq": "xquery",
\".xs": "xs",
\".yml": "yaml",
\'.adb': 'ada',
\'.ahk': 'ahk',
\'.arc': 'arc',
\'.as': 'actionscript',
\'.asm': 'asm',
\'.asp': 'asp',
\'.aw': 'php',
\'.b': 'b',
\'.bat': 'bat',
\'.befunge': 'befunge',
\'.bmx': 'bmx',
\'.boo': 'boo',
\'.c-objdump': 'c-objdump',
\'.c': 'c',
\'.cfg': 'cfg',
\'.cfm': 'cfm',
\'.ck': 'ck',
\'.cl': 'cl',
\'.clj': 'clj',
\'.cmake': 'cmake',
\'.coffee': 'coffee',
\'.cpp': 'cpp',
\'.cppobjdump': 'cppobjdump',
\'.cs': 'csharp',
\'.css': 'css',
\'.cw': 'cw',
\'.d-objdump': 'd-objdump',
\'.d': 'd',
\'.darcspatch': 'darcspatch',
\'.diff': 'diff',
\'.duby': 'duby',
\'.dylan': 'dylan',
\'.e': 'e',
\'.ebuild': 'ebuild',
\'.eclass': 'eclass',
\'.el': 'lisp',
\'.erb': 'erb',
\'.erl': 'erlang',
\'.f90': 'f90',
\'.factor': 'factor',
\'.feature': 'feature',
\'.fs': 'fs',
\'.fy': 'fy',
\'.go': 'go',
\'.groovy': 'groovy',
\'.gs': 'gs',
\'.gsp': 'gsp',
\'.haml': 'haml',
\'.hs': 'haskell',
\'.html': 'html',
\'.hx': 'hx',
\'.ik': 'ik',
\'.ino': 'ino',
\'.io': 'io',
\'.j': 'j',
\'.java': 'java',
\'.js': 'javascript',
\'.json': 'json',
\'.jsp': 'jsp',
\'.kid': 'kid',
\'.lhs': 'lhs',
\'.lisp': 'lisp',
\'.ll': 'll',
\'.lua': 'lua',
\'.ly': 'ly',
\'.m': 'objc',
\'.mak': 'mak',
\'.man': 'man',
\'.mao': 'mao',
\'.matlab': 'matlab',
\'.md': 'markdown',
\'.minid': 'minid',
\'.ml': 'ml',
\'.moo': 'moo',
\'.mu': 'mu',
\'.mustache': 'mustache',
\'.mxt': 'mxt',
\'.myt': 'myt',
\'.n': 'n',
\'.nim': 'nim',
\'.nu': 'nu',
\'.numpy': 'numpy',
\'.objdump': 'objdump',
\'.ooc': 'ooc',
\'.parrot': 'parrot',
\'.pas': 'pas',
\'.pasm': 'pasm',
\'.pd': 'pd',
\'.phtml': 'phtml',
\'.pir': 'pir',
\'.pl': 'perl',
\'.po': 'po',
\'.py': 'python',
\'.pytb': 'pytb',
\'.pyx': 'pyx',
\'.r': 'r',
\'.raw': 'raw',
\'.rb': 'ruby',
\'.rhtml': 'rhtml',
\'.rkt': 'rkt',
\'.rs': 'rs',
\'.rst': 'rst',
\'.s': 's',
\'.sass': 'sass',
\'.sc': 'sc',
\'.scala': 'scala',
\'.scm': 'scheme',
\'.scpt': 'scpt',
\'.scss': 'scss',
\'.self': 'self',
\'.sh': 'sh',
\'.sml': 'sml',
\'.sql': 'sql',
\'.st': 'smalltalk',
\'.swift': 'swift',
\'.tcl': 'tcl',
\'.tcsh': 'tcsh',
\'.tex': 'tex',
\'.textile': 'textile',
\'.tpl': 'smarty',
\'.twig': 'twig',
\'.txt' : 'text',
\'.v': 'verilog',
\'.vala': 'vala',
\'.vb': 'vbnet',
\'.vhd': 'vhdl',
\'.vim': 'vim',
\'.weechatlog': 'weechatlog',
\'.xml': 'xml',
\'.xq': 'xquery',
\'.xs': 'xs',
\'.yml': 'yaml',
\}, get(g:, 'gist_extmap', {}))
let &cpo = s:save_cpo

View File

@ -1,19 +1,19 @@
*Gist.vim* Vimscript for creating gists (http://gist.github.com)
Usage |gist-vim-usage|
Tips |gist-vim-tips|
License |gist-vim-license|
Install |gist-vim-install|
Requirements |gist-vim-requirements|
Setup |gist-vim-setup|
FAQ |gist-vim-faq|
Usage |vim-gist-usage|
Tips |vim-gist-tips|
License |vim-gist-license|
Install |vim-gist-install|
Requirements |vim-gist-requirements|
Setup |vim-gist-setup|
FAQ |vim-gist-faq|
This is a vimscript for creating gists (http://gist.github.com)
For the latest version please see https://github.com/mattn/gist-vim.
For the latest version please see https://github.com/mattn/vim-gist.
==============================================================================
USAGE *:Gist* *gist-vim-usage*
USAGE *:Gist* *vim-gist-usage*
- Post current buffer to gist, using default privacy option. >
@ -102,6 +102,8 @@ USAGE *:Gist* *gist-vim-usage*
:Gist -l
:Gist --list
:Gist -l -n 100
:Gist --list --per-page 100
<
- List gists from user "mattn". >
@ -120,15 +122,15 @@ USAGE *:Gist* *gist-vim-usage*
- While the gist list is visible, the following mappings apply:
- 'o' or 'Enter' will open the selected gist file in a new buffer
and close the gist-vim listing split.
and close the vim-gist listing split.
- 'b' will open the selected gist file in a browser. If you are in
GUI vim you can also achieve this by pressing 'Shift-Enter'.
- 'y' will copy the contents of the selected gist to the clipboard,
and close the gist-vim listing split.
and close the vim-gist listing split.
- 'p' will (copy and) paste the contents of the selected gist to the
buffer from which gist-vim was called, and close the gist-vim
buffer from which vim-gist was called, and close the vim-gist
listing split.
- 'Esc' will close the gist-vim listing split without performing any
- 'Esc' will close the vim-gist listing split without performing any
further action.
- Open the gist on browser after you post or update it.
@ -141,7 +143,7 @@ USAGE *:Gist* *gist-vim-usage*
:Gist!
<
==============================================================================
TIPS *gist-vim-tips*
TIPS *vim-gist-tips*
If you set "g:gist_clip_command", gist.vim will copy the gist code with option
"-c".
@ -201,6 +203,10 @@ If you want to open gist list/buffer as vertical split: >
let g:gist_list_vsplit = 1
If you want to list more than 30 gists per page (maximum is 100):
let g:gist_per_page_limit = 100
If you want to modify filetype for the file on github, or add mapping of
filetype/file-extension: >
@ -216,13 +222,13 @@ in your local file, then call >
:Gist
The gist-vim listing split lists gists ids, names (filenames) as well as
The vim-gist listing split lists gists ids, names (filenames) as well as
their description. This is done following a table layout, with fixed space
for each column. For offering quick browsing, gist-vim will truncate all
for each column. For offering quick browsing, vim-gist will truncate all
output exceeding the available horizontal space, assuring that every gist
listed only takes one line on the table. Although the gist id field width is
fixed internally, the user can define the length of the (file)name field on
the gist-vim listing. This can be done by the following declaration:
the vim-gist listing. This can be done by the following declaration:
let g:gist_namelength = 20
@ -241,7 +247,7 @@ All other values are treated as 1.
This variable's value is 1 by default.
==============================================================================
LICENSE *gist-vim-license*
LICENSE *vim-gist-license*
Copyright 2010 by Yasuhiro Matsumoto
@ -267,7 +273,7 @@ LICENSE *gist-vim-license*
OF THE POSSIBILITY OF SUCH DAMAGE.
==============================================================================
INSTALL *gist-vim-install*
INSTALL *vim-gist-install*
Copy following files into your plugin directory.
@ -275,7 +281,7 @@ rtp:
- autoload/gist.vim
- plugin/gist.vim
If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`.
If you want to uninstall gist.vim, remember to also remove `~/.vim-gist`.
You need to install webapi-vim also:
@ -286,17 +292,17 @@ If you want to use latest one:
https://github.com/mattn/webapi-vim
==============================================================================
REQUIREMENTS *gist-vim-requirements*
REQUIREMENTS *vim-gist-requirements*
- curl command (http://curl.haxx.se/)
- webapi-vim (https://github.com/mattn/webapi-vim)
- and, if you want to use your git profile, the git command-line client.
==============================================================================
SETUP *gist-vim-setup*
SETUP *vim-gist-setup*
This plugin uses GitHub API v3. The authentication value is stored in `~/.gist-vim`.
gist-vim provides two ways to authenticate against the GitHub APIs.
This plugin uses GitHub API v3. The authentication value is stored in `~/.vim-gist`.
vim-gist provides two ways to authenticate against the GitHub APIs.
First, you need to set your GitHub username in global git config:
>
@ -312,7 +318,7 @@ If you have two-factor authentication enabled on GitHub, you'll see the message
"Must specify two-factor authentication OTP code." In this case, you need to
create a "Personal Access Token" on GitHub's "Account Settings" page
(https://github.com/settings/applications) and place it in a file
named ~/.gist-vim like this:
named ~/.vim-gist like this:
>
token xxxxx
<
@ -331,13 +337,13 @@ This is not secure at all, so strongly discouraged.
NOTE: the username is optional if you only send anonymous gists.
==============================================================================
FAQ *gist-vim-faq*
FAQ *vim-gist-faq*
Q. :Gist returns a Forbidden error
A. Try deleting ~/.gist-vim and authenticating again.
A. Try deleting ~/.vim-gist and authenticating again.
==============================================================================
THANKS *gist-vim-thanks*
THANKS *vim-gist-thanks*
AD7six
Bruno Bigras

View File

@ -1,303 +0,0 @@
script_name: Gist.vim
script_id: '2423'
script_type: utility
script_package: gist-vim.zip
script_version: '7.3'
required_vim_version: '7.0'
summary: vimscript for gist
detailed_description: |
This is vimscript for gist (http://gist.github.com)
Usage:
:Gist
post whole text to gist.
:'<,'>Gist
post selected text to gist.
:Gist -p
post whole text to gist with private.
if you got empty gist list, try :Gist --abandon
:Gist -a
post whole text to gist with anonymous.
:Gist -m
post multi buffer to gist.
:Gist -e
edit the gist. (should be work on gist buffer)
you can update the gist with :w command on gist buffer.
:Gist -e foo.js
edit the gist with name 'foo.js'. (should be work on gist buffer)
:Gist -d
delete the gist. (should be work on gist buffer)
authentication required.
:Gist -f
fork the gist. (should be work on gist buffer)
authentication required.
:Gist XXXXX
get gist XXXXX.
:Gist -c XXXXX.
get gist XXXXX and put to clipboard.
:Gist -l
list gists from mine.
:Gist -la
list gists from all.
Tips:
if set g:gist_clip_command, gist.vim will copy the gist code
with option '-c'.
# mac
let g:gist_clip_command = 'pbcopy'
# linux
let g:gist_clip_command = 'xclip -selection clipboard'
# others(cygwin?)
let g:gist_clip_command = 'putclip'
if you want to detect filetype from filename...
let g:gist_detect_filetype = 1
if you want to open browser after the post...
let g:gist_open_browser_after_post = 1
if you want to change the browser...
let g:gist_browser_command = 'w3m %URL%'
or
let g:gist_browser_command = 'opera %URL% &'
on windows, should work with original setting.
Require:
curl command (http://curl.haxx.se/)
and if you want to use profile of git, it require git command.
install_details: |
copy it to your plugin directory.
gist.vim leave cookie-jar file into runtimepath.
rtp:
plugin/gist.vim
cookies/github
See also: https://github.com/mattn/gist-vim/blob/master/README.mkd
versions:
- '7.3': |
This is an upgrade for Gist.vim: fixed many bugs. Added few list actions: yank, paste, open in browser.
- '7.2': |
This is an upgrade for Gist.vim: fixed many bugs.
- '7.1': |
This is an upgrade for Gist.vim: updated installation notes.
- '7.0': |
This is an upgrade for Gist.vim: fixed few bugs.
- '6.9': |
This is an upgrade for Gist.vim: fixed few bugs.
- '6.8': |
This is an upgrade for Gist.vim: changed authentication. removed password authentication. if you want to keep using password authentication, let gist_use_password_in_gitconfig to 1.
- '6.7': |
This is an upgrade for Gist.vim: fix behavior of g:gist_browser_command = ':OpenBrowser %URL%'.
- '6.6': |
This is an upgrade for Gist.vim: fixed detecting filetype.
- '6.5': |
This is an upgrade for Gist.vim: use webapi namespace. NOTE: please upgrade webapi-vim also.
- '6.4': |
This is an upgrade for Gist.vim: fixed updating with description.
- '6.3': |
This is an upgrade for Gist.vim: fixed typos.
- '6.2': |
This is an upgrade for Gist.vim: fixed some bugs.
- '6.1': |
This is an upgrade for Gist.vim: fixed opening browser.
- '6.0': |
This is an upgrade for Gist.vim: changed to use github APIs. Note to remove cookies directory if you used.
- '5.9': |
This is an upgrade for Gist.vim: add support anonymous post. fixed many bugs.
- '5.8': |
This is an upgrade for Gist.vim: add support for description. you can post description using -s option.
- '5.7': |
This is an upgrade for Gist.vim: post with filetype more cleverly.
- '5.6': |
This is an upgrade for Gist.vim: fix '--abandon'.
- '5.5': |
This is an upgrade for Gist.vim: fix: forgot to upload autoload/gist.vim.
- '5.4': |
This is an upgrade for Gist.vim: fix: does not work correctly with blockwize selection.
- '5.3': |
This is an upgrade for Gist.vim: upd: support autoload.
- '5.2': |
This is an upgrade for Gist.vim: add: support block-wise selection.
- '5.1': |
This is an upgrade for Gist.vim: fix: can't update privates.
- '5.0': |
This is an upgrade for Gist.vim: follow update of gist.github.com
- '4.9': |
fix: don't add new line after "Done: xxx".
fix: show WHY FAILED' when failed to post.
add: support for :OpenBrowser.
add: new option 'gist_curl_options'.
- '4.8': |
This is an upgrade for Gist.vim: fix: can't open private gist with ":Gist XXXXX".
- '4.7': |
This is an upgrade for Gist.vim: fix: filetype detection.
- '4.6': |
This is an upgrade for Gist.vim: fix: strange cookies folder.
- '4.5': |
This is an upgrade for Gist.vim: fix: use gist_clip_command for copying URL to clipboard. this fix strange behavior on Mac OSX.
- '4.4': |
This is an upgrade for Gist.vim: fix: gist is now only using https.
- '4.3': |
This is an upgrade for Gist.vim: add new option '-f' for fork.
- '4.2': |
This is an upgrade for Gist.vim: fixed code for login.
- '4.1': |
This is an upgrade for Gist.vim: fixed code cleanup.
- '4.0': |
This is an upgrade for Gist.vim: fixed deleting gist, listing privates.
- '3.9': |
This is an upgrade for Gist.vim: fixed :w handler in gist buffer.
- '3.8': |
This is an upgrade for Gist.vim: 'more...' on gist list.
- '3.7': |
This is an upgrade for Gist.vim: fix problem that break "gist list" window at twice.
- '3.6': |
This is an upgrade for Gist.vim: fix filetype detection for 'vimscript'.
- '3.5': |
This is an upgrade for Gist.vim: fix filetype detection.
- '3.4': |
This is an upgrade for Gist.vim: use '+' register on unix only if built with 'xterm_clipboard'. and some bug fixes.
- '3.3': |
This is an upgrade for Gist.vim: fix problem that append empty line when getting gist.
- '3.2': |
This is an upgrade for Gist.vim: added Gist header to recognize the gist. added script type header for Vimana.
- '3.1': |
This is an upgrade for Gist.vim: fix checking redirect url.
- '3.0': |
This is an upgrade for Gist.vim: fix for official changes(private button name was changed).
- '2.9': |
This is an upgrade for Gist.vim: fix for official changes(private button name was changed).
- '2.8': |
This is an upgrade for Gist.vim: be able to post multi buffer. currently updating or showing not supported. and ':Gist -d' delete the gist.
- '2.7': |
This is an upgrade for Gist.vim: be able to write the gist to local file with ':w foo.txt'.
- '2.6': |
This is an upgrade for Gist.vim: fixed problem that does not work 'Gist XXXX'.
- '2.5': |
This is an upgrade for Gist.vim: use existing buffer when open the list or gist.
- '2.4': |
This is an upgrade for Gist.vim: show error message when no any github settings.
- '2.3': |
This is an upgrade for Gist.vim: added :w BufWriteCmd for GistUpdate.
- '2.2': |
This is an upgrade for Gist.vim: fixed a bug for anonymous post. and new option '-a' for anonymous post.
- '2.1': |
This is an upgrade for Gist.vim: support changing gist filename.
- '2.0': |
This is an upgrade for Gist.vim: bugfix for listing gists in specified user.
- '1.9': |
This is an upgrade for Gist.vim: added support editing the gist. and bits bug fix.
- '1.8': |
This is an upgrade for Gist.vim: added new option g:gist_open_browser_after_post/g:gist_browser_command to open posted gist.
- '1.7': |
This is an upgrade for Gist.vim: now changed argument for putting clipboard as ':Gist -c XXXXX'.
- '1.6': |
This is an upgrade for Gist.vim: add gist's author in gist list.
- '1.5': |
This is an upgrade for Gist.vim: oops. bugfix for auto-detection.
- '1.4': |
This is an upgrade for Gist.vim: bugfix for auto-detection.
- '1.3': |
This is an upgrade for Gist.vim: more auto-detection for filetype.
- '1.2': |
This is an upgrade for Gist.vim: added new option for detect filetype from filename.
- '1.1': |
This is an upgrade for Gist.vim: calling StdinReadPost.
- '1.0': |
This is an upgrade for Gist.vim: treat literal "-" as part of username.
- '0.9': |
This is an upgrade for Gist.vim: added new option 'g:gist_clip_command' that copy the gist code.
# __END__
# vim: filetype=yaml

View File

@ -1,7 +1,7 @@
"=============================================================================
" File: gist.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" WebPage: http://github.com/mattn/gist-vim
" WebPage: http://github.com/mattn/vim-gist
" License: BSD
" GetLatestVimScripts: 2423 1 :AutoInstall: gist.vim
" script type: plugin
@ -12,12 +12,13 @@ endif
let g:loaded_gist_vim = 1
function! s:CompleteArgs(arg_lead,cmdline,cursor_pos)
return filter(copy(["-p", "-P", "-a", "-m", "-e", "-s", "-d", "+1", "-1", "-f", "-c", "-l", "-la", "-ls", "-b",
return filter(copy(["-p", "-P", "-a", "-m", "-e", "-s", "-d", "+1", "-1", "-f", "-c", "-l", "-la", "-ls", "-b", "-n",
\ "--listall", "--liststar", "--list", "--multibuffer", "--private", "--public", "--anonymous", "--description", "--clipboard",
\ "--rawurl", "--delete", "--edit", "--star", "--unstar", "--fork", "--browser"
\ "--rawurl", "--delete", "--edit", "--star", "--unstar", "--fork", "--browser", "--per-page"
\ ]), 'stridx(v:val, a:arg_lead)==0')
endfunction
let g:gist_per_page_limit = get(g:, 'gist_per_page_limit', 30)
command! -nargs=? -range=% -bang -complete=customlist,s:CompleteArgs Gist :call gist#Gist(<count>, "<bang>", <line1>, <line2>, <f-args>)
" vim:set et:

View File

@ -87,6 +87,10 @@ For the latest version please see https://github.com/mattn/vim-gist.
:Gist -l mattn
- Specify the number of gists listed:
:Gist -l -n 100
- List everyone's gists.
:Gist -la
@ -188,6 +192,10 @@ You need to either set global git config:
$ git config --global github.user Username
If you want to list more than 30 gists per page (maximum is 100):
let g:gist_per_page_limit = 100
## License:
Copyright 2010 by Yasuhiro Matsumoto

View File

@ -171,7 +171,7 @@ endfunction
" Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it.
let s:bufprefix = 'gist' . (has('unix') ? ':' : '_')
function! s:GistList(gistls, page) abort
function! s:GistList(gistls, page, pagelimit) abort
if a:gistls ==# '-all'
let url = g:gist_api_url.'gists/public'
elseif get(g:, 'gist_show_privates', 0) && a:gistls ==# 'starred'
@ -196,9 +196,11 @@ function! s:GistList(gistls, page) abort
exec 'silent noautocmd split' s:bufprefix.a:gistls
endif
endif
let url = url . '?per_page=' . a:pagelimit
if a:page > 1
let oldlines = getline(0, line('$'))
let url = url . '?page=' . a:page
let url = url . '&page=' . a:page
endif
setlocal modifiable
@ -527,7 +529,7 @@ function! s:GistListAction(mode) abort
return
endif
if line =~# '^more\.\.\.$'
call s:GistList(b:gistls, b:page+1)
call s:GistList(b:gistls, b:page+1, g:gist_per_page_limit)
return
endif
endfunction
@ -761,6 +763,8 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
let editpost = 0
let anonymous = get(g:, 'gist_post_anonymous', 0)
let openbrowser = 0
let setpagelimit = 0
let pagelimit = g:gist_per_page_limit
let listmx = '^\%(-l\|--list\)\s*\([^\s]\+\)\?$'
let bufnamemx = '^' . s:bufprefix .'\(\zs[0-9a-f]\+\ze\|\zs[0-9a-f]\+\ze[/\\].*\)$'
if strlen(g:github_user) == 0 && anonymous == 0
@ -788,6 +792,14 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
elseif arg =~# '^\(-G\|--gitclone\)$\C' && gistidbuf !=# '' && g:gist_api_url ==# 'https://api.github.com/' && has_key(b:, 'gist') && has_key(b:gist, 'id')
exe '!' printf('git clone git@github.com:%s', b:gist['id'])
return
elseif setpagelimit == 1
let setpagelimit = 0
let pagelimit = str2nr(arg)
if pagelimit < 1 || pagelimit > 100
echohl ErrorMsg | echomsg 'Page limit should be between 1 and 100: '.arg | echohl None
unlet args
return 0
endif
elseif arg =~# '^\(-la\|--listall\)$\C'
let gistls = '-all'
elseif arg =~# '^\(-ls\|--liststar\)$\C'
@ -868,6 +880,14 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
endif
elseif arg =~# '^\(-b\|--browser\)$\C'
let openbrowser = 1
elseif arg =~# '^\(-n\|--per-page\)$\C'
if len(gistls) > 0
let setpagelimit = 1
else
echohl ErrorMsg | echomsg 'Page limit can be set only for list commands'.arg | echohl None
unlet args
return 0
endif
elseif arg !~# '^-' && len(gistnm) == 0
if gistdesc !=# ' '
let gistdesc = matchstr(arg, '^\s*\zs.*\ze\s*$')
@ -904,7 +924,7 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
endif
if len(gistls) > 0
call s:GistList(gistls, 1)
call s:GistList(gistls, 1, pagelimit)
elseif len(gistid) > 0 && editpost == 0 && deletepost == 0
call s:GistGet(gistid, clipboard)
else

View File

@ -102,6 +102,8 @@ USAGE *:Gist* *vim-gist-usage*
:Gist -l
:Gist --list
:Gist -l -n 100
:Gist --list --per-page 100
<
- List gists from user "mattn". >
@ -201,6 +203,10 @@ If you want to open gist list/buffer as vertical split: >
let g:gist_list_vsplit = 1
If you want to list more than 30 gists per page (maximum is 100):
let g:gist_per_page_limit = 100
If you want to modify filetype for the file on github, or add mapping of
filetype/file-extension: >

View File

@ -12,12 +12,13 @@ endif
let g:loaded_gist_vim = 1
function! s:CompleteArgs(arg_lead,cmdline,cursor_pos)
return filter(copy(["-p", "-P", "-a", "-m", "-e", "-s", "-d", "+1", "-1", "-f", "-c", "-l", "-la", "-ls", "-b",
return filter(copy(["-p", "-P", "-a", "-m", "-e", "-s", "-d", "+1", "-1", "-f", "-c", "-l", "-la", "-ls", "-b", "-n",
\ "--listall", "--liststar", "--list", "--multibuffer", "--private", "--public", "--anonymous", "--description", "--clipboard",
\ "--rawurl", "--delete", "--edit", "--star", "--unstar", "--fork", "--browser"
\ "--rawurl", "--delete", "--edit", "--star", "--unstar", "--fork", "--browser", "--per-page"
\ ]), 'stridx(v:val, a:arg_lead)==0')
endfunction
let g:gist_per_page_limit = get(g:, 'gist_per_page_limit', 30)
command! -nargs=? -range=% -bang -complete=customlist,s:CompleteArgs Gist :call gist#Gist(<count>, "<bang>", <line1>, <line2>, <f-args>)
" vim:set et: