|
| 1 | +# Gist.vim |
| 2 | + |
| 3 | +This is a vimscript for creating gists (http://gist.github.com). |
| 4 | + |
| 5 | +For the latest version please see https://github.com/mattn/gist-vim. |
| 6 | + |
| 7 | +## Usage: |
| 8 | + |
| 9 | +- Post current buffer to gist, using default privacy option. |
| 10 | + |
| 11 | + :Gist |
| 12 | + |
| 13 | +- Post selected text to gist, using default privacy option. |
| 14 | + This applies to all permutations listed below (except multi). |
| 15 | + |
| 16 | + :'<,'>Gist |
| 17 | + |
| 18 | +- Create a private gist. |
| 19 | + |
| 20 | + :Gist -p |
| 21 | + |
| 22 | +- Create a public gist. |
| 23 | + (Only relevant if you've set gists to be private by default.) |
| 24 | + |
| 25 | + :Gist -P |
| 26 | + |
| 27 | +> This is only relevant if you've set gists to be private by default; |
| 28 | +> if you get an empty gist list, try ":Gist --abandon". |
| 29 | +
|
| 30 | +- Create a gist anonymously. |
| 31 | + |
| 32 | + :Gist -a |
| 33 | + |
| 34 | +- Create a gist with all open buffers. |
| 35 | + |
| 36 | + :Gist -m |
| 37 | + |
| 38 | +- Edit the gist (you need to have opened the gist buffer first). |
| 39 | + You can update the gist with the ":w" command within the gist buffer. |
| 40 | + |
| 41 | + :Gist -e |
| 42 | + |
| 43 | +- Edit the gist with name 'foo.js' (you need to have opened the gist buffer |
| 44 | + first). |
| 45 | + |
| 46 | + :Gist -e foo.js |
| 47 | + |
| 48 | +- Post/Edit with the description " (you need to have opened the gist buffer |
| 49 | + first). > |
| 50 | + |
| 51 | + :Gist -s something |
| 52 | + :Gist -e -s something |
| 53 | + |
| 54 | +- Delete the gist (you need to have opened the gist buffer first). |
| 55 | + Password authentication is needed. |
| 56 | + |
| 57 | + :Gist -d |
| 58 | + |
| 59 | +- Fork the gist (you need to have opened the gist buffer first). |
| 60 | + Password authentication is needed. |
| 61 | + |
| 62 | + :Gist -f |
| 63 | + |
| 64 | +- Star the gist (you need to have opened the gist buffer first). |
| 65 | + Password authentication is needed. |
| 66 | + |
| 67 | + :Gist +1 |
| 68 | + |
| 69 | +- Unstar the gist (you need to have opened the gist buffer first). |
| 70 | + Password authentication is needed. |
| 71 | + |
| 72 | + :Gist -1 |
| 73 | + |
| 74 | +- Get gist XXXXX. |
| 75 | + |
| 76 | + :Gist XXXXX |
| 77 | + |
| 78 | +- Get gist XXXXX and add to clipboard. |
| 79 | + |
| 80 | + :Gist -c XXXXX |
| 81 | + |
| 82 | +- List your public gists. |
| 83 | + |
| 84 | + :Gist -l |
| 85 | + |
| 86 | +- List gists from user "mattn". |
| 87 | + |
| 88 | + :Gist -l mattn |
| 89 | + |
| 90 | +- List everyone's gists. |
| 91 | + |
| 92 | + :Gist -la |
| 93 | + |
| 94 | +- List gists from your starred gists. |
| 95 | + |
| 96 | + :Gist -ls |
| 97 | + |
| 98 | +- Open the gist on browser after you post or update it. |
| 99 | + |
| 100 | + :Gist -b |
| 101 | + |
| 102 | +## List Feature |
| 103 | + |
| 104 | +- Useful mappings on the gist-listing buffer: |
| 105 | + - Both `o` or `Enter` open the gist file in a new buffer, and close the |
| 106 | + gist-vim listing one. |
| 107 | + - `b` opens the gist file in a browser; this is necessary because |
| 108 | + `Shift-Enter` (as was originally) only works for GUI vim. |
| 109 | + - `y` copies the contents of the selected gist to the clipboard, and |
| 110 | + closes the gist-vim buffer. |
| 111 | + - `p` pastes the contents of the selected gist to the buffer from where |
| 112 | + gist-vim was called, and closes the gist-vim buffer. |
| 113 | + - Hitting `Escape` or `Tab` at the gist-vim buffer closes it. |
| 114 | + |
| 115 | +- Gist listing has fixed-length columns now, more amenable to eye inspection. |
| 116 | + Every line on the gist-listing buffer contains the gist id, name and |
| 117 | + description, in that order. Columns are now padded and truncated to offer a |
| 118 | + faster browsing, in the following way: |
| 119 | + - The gist id string is fixed at 32 characters. |
| 120 | + - The length (in characters) of the name of the gist is fixed and |
| 121 | + can be set by the user using, for example: |
| 122 | + |
| 123 | + `let g:gistvim_namelength = 20` |
| 124 | + |
| 125 | + The default value for `gistvim_namelength` is 30. If the gist (file)name |
| 126 | + exceeds that length, it is truncated to the specified length. |
| 127 | + - Finally, the gist description is truncated in length to fit the remaining |
| 128 | + of the line, avoiding wrapped lines that mess up the table layout. |
| 129 | + - Note that the gist listing buffer now does not show the field 'code' |
| 130 | + (not sure what that did in the first place). |
| 131 | + |
| 132 | +## Tips: |
| 133 | + |
| 134 | +If you set g:gist_clip_command, gist.vim will copy the gist code with option |
| 135 | +'-c'. |
| 136 | + |
| 137 | +- Mac: |
| 138 | + |
| 139 | + let g:gist_clip_command = 'pbcopy' |
| 140 | + |
| 141 | +- Linux: |
| 142 | + |
| 143 | + let g:gist_clip_command = 'xclip -selection clipboard' |
| 144 | + |
| 145 | +- Others (cygwin?): |
| 146 | + |
| 147 | + let g:gist_clip_command = 'putclip' |
| 148 | + |
| 149 | +If you want to detect filetype from the filename: |
| 150 | + |
| 151 | + let g:gist_detect_filetype = 1 |
| 152 | + |
| 153 | +If you want to open browser after the post: |
| 154 | + |
| 155 | + let g:gist_open_browser_after_post = 1 |
| 156 | + |
| 157 | +If you want to change the browser: |
| 158 | + |
| 159 | + let g:gist_browser_command = 'w3m %URL%' |
| 160 | + |
| 161 | +or: |
| 162 | + |
| 163 | + let g:gist_browser_command = 'opera %URL% &' |
| 164 | + |
| 165 | +On windows, this should work with your user settings. |
| 166 | + |
| 167 | +If you want to show your private gists with ":Gist -l": |
| 168 | + |
| 169 | + let g:gist_show_privates = 1 |
| 170 | + |
| 171 | +If you want your gist to be private by default: |
| 172 | + |
| 173 | + let g:gist_post_private = 1 |
| 174 | + |
| 175 | +If you want your gist to be anonymous by default: |
| 176 | + |
| 177 | + let g:gist_post_anonymous = 1 |
| 178 | + |
| 179 | +If you want to manipulate multiple files in a gist: |
| 180 | + |
| 181 | + let g:gist_get_multiplefile = 1 |
| 182 | + |
| 183 | +If you want to use on GitHub Enterprise: |
| 184 | + |
| 185 | + let g:gist_api_url = 'http://your-github-enterprise-domain/api/v3' |
| 186 | + |
| 187 | +You need to either set global git config: |
| 188 | + |
| 189 | + $ git config --global github.user Username |
| 190 | + |
| 191 | +## License: |
| 192 | + |
| 193 | + Copyright 2010 by Yasuhiro Matsumoto |
| 194 | + modification, are permitted provided that the following conditions are met: |
| 195 | + |
| 196 | + 1. Redistributions of source code must retain the above copyright notice, |
| 197 | + this list of conditions and the following disclaimer. |
| 198 | + 2. Redistributions in binary form must reproduce the above copyright notice, |
| 199 | + this list of conditions and the following disclaimer in the documentation |
| 200 | + and/or other materials provided with the distribution. |
| 201 | + |
| 202 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 203 | + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 204 | + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 205 | + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 206 | + REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 207 | + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 208 | + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 209 | + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 210 | + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 211 | + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 212 | + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 213 | + OF THE POSSIBILITY OF SUCH DAMAGE. |
| 214 | + |
| 215 | + |
| 216 | +## Install: |
| 217 | + |
| 218 | +Copy it to your plugin directory. |
| 219 | +gist.vim will create a curl cookie-jar file in your runtimepath. |
| 220 | + |
| 221 | +- rtp: |
| 222 | + - autoload/gist.vim |
| 223 | + - plugin/gist.vim |
| 224 | + |
| 225 | +If you want to uninstall gist.vim, remember to also remove `~/.gist-vim`. |
| 226 | + |
| 227 | +You need to install webapi-vim also: |
| 228 | + |
| 229 | + http://www.vim.org/scripts/script.php?script_id=4019 |
| 230 | + |
| 231 | +If you want to use latest one: |
| 232 | + |
| 233 | + https://github.com/mattn/webapi-vim |
| 234 | + |
| 235 | +### Install with [Vundle](https://github.com/gmarik/vundle) |
| 236 | + |
| 237 | +Add the following lines to your `.vimrc`. |
| 238 | + |
| 239 | + Bundle 'mattn/webapi-vim' |
| 240 | + Bundle 'mattn/gist-vim' |
| 241 | + |
| 242 | +Now restart Vim and run `:BundleInstall`. |
| 243 | + |
| 244 | +### Install with [NeoBundle](https://github.com/Shougo/neobundle.vim) |
| 245 | + |
| 246 | +Add the following line to your `.vimrc`. |
| 247 | + |
| 248 | + NeoBundle 'mattn/gist-vim', {'depends': 'mattn/webapi-vim'} |
| 249 | + |
| 250 | +## Requirements: |
| 251 | + |
| 252 | +- curl command (http://curl.haxx.se/) |
| 253 | +- webapi-vim (https://github.com/mattn/webapi-vim) |
| 254 | +- and if you want to use your git profile, the git command-line client. |
| 255 | + |
| 256 | +## Setup: |
| 257 | + |
| 258 | +This plugin supports both basic and two-factor authentication using GitHub |
| 259 | +API v3. The plugin stores its credentials in `~/.gist-vim`. |
| 260 | + |
| 261 | +First, you need to set your GitHub username in git's global configuration: |
| 262 | + |
| 263 | + $ git config --global github.user <username> |
| 264 | + |
| 265 | +Then gist-vim will ask for your password in order to create an access |
| 266 | +token. If you have two-factor authentication enabled, gist-vim will also |
| 267 | +prompt you to enter the two-factor key you receive. |
| 268 | + |
| 269 | +Whichever type of authentication you use, your GitHub password will not be |
| 270 | +stored, only a OAuth access token produced specifically for gist-vim. The |
| 271 | +token is stored in `~/.gist-vim`. If you stop using the plugin, you can |
| 272 | +easily remove this file. To revoke the associated GitHub token, go to the |
| 273 | +list of ["Authorized applications" on GitHub's "Account Settings" |
| 274 | +page][uas]. |
| 275 | + |
| 276 | +[uas]: https://github.com/settings/applications |
| 277 | + |
| 278 | +**Note:** the username is optional if you only send anonymous gists. |
0 commit comments