Giter VIP home page Giter VIP logo

vim-syncopate's Introduction

syncopate

(Syn)tax (cop)y-p(a)s(te).

What's it for?

To make sharing beautiful code as frictionless as possible.

Say you have a nicely syntax-highlighted buffer in vim. This plugin lets you open a browser tab with that buffer's contents, including the highlighting. If you copy-paste into a webmail window, a Google Doc, etc., the syntax highlighting stays intact.

Best of all, it cleans up after itself: it won't clutter your directories with .html files.

How do I install it?

Depends on your plugin manager.

Note that syncopate is a maktaba plugin, so you will need to install maktaba (if your plugin manager doesn't handle dependencies). If you want to configure the plugin, we strongly recommend installing glaive as well.

Here are instructions for Vundle, the most popular plugin manager. Add the following lines between your call vundle#begin() and call vundle#end() lines.

" Dependency; required for vim-syncopate.
Plugin google/vim-maktaba

" Strongly recommended: easy configuration of maktaba plugins.
Plugin google/vim-glaive

Plugin google/vim-syncopate

Syncopate is expected to work on any platform vim supports, but the default configuration may not work on your system and direct-to-clipboard support hasn't been implemented for some platforms. Contributions welcome!

xclip

Syncopate requires xclip to manipulate the clipboard. In most cases, installing it from your package manager should just work.

Arch Linux's official repository has an xclip (0.12.4) which is too old: it doesn't support --target. Arch users should install xclip-svn from AUR:

yaourt -S xclip-svn

How do I use it?

Use the clipboard directly

Use the :SyncopateExportToClipboard command. It populates the clipboard with the contents of your buffer (or just part of it, if you're in visual mode), including highlighting. You can then paste your beautiful code into a compose window (such as Gmail).

Of course, it's even better with a keymapping, which you can enable using Glaive:

" This line needs to go anywhere after 'call vundle#end()'.
call glaive#Install()

" Enable keymappings.
Glaive syncopate plugin[mappings]

By default, syncopate's mappings all start with the prefix <Leader><. You can change the prefix by giving plugin[mappings] a value, like so:

Glaive syncopate plugin[mappings]='qwer'

The following examples will assume you're using the default prefix, and that your <Leader> is ,.

  • ,< calls :SyncopateExportToClipboard on whatever motion you choose. (e.g., ,<ip will copy the current paragraph (ip) to the clipboard.)
  • ,<> calls :SyncopateExportToClipboard on the whole buffer (or your selection in visual mode).

Put it in a browser window

Alternatively, you can use the :SyncopateExportToBrowser command. It opens the HTML in a new browser tab, so you can select regions interactively. Syncopate automatically cleans up the HTML file after opening the tab.

If you use :SyncopateExportToBrowser, be sure to copy with Ctrl-C (as opposed to mouse selection/middle-click); otherwise, the highlighting will not be retained.

How do I configure it?

There are a variety of syncopate-specific options: whether to change the colorscheme, which browser to use, etc. See :help syncopate-config.

For everything else, use the built-in options for the :TOhtml command: :help 2html.vim. (Options are down below, starting at :help g:html_diff_one_file.)

For example, the following line will exclude line numbers from the output, even if you use them in vim:

let g:html_number_lines = 0

So how's this different from plain :TOhtml?

Mainly convenience. Under the hood, :SyncopateExportToClipboard will:

  1. Switch to the default colorscheme (it shows up better on white backgrounds).
  2. Create the HTML version of your vim buffer.
  3. Export it to the clipboard.
  4. Restore your colorscheme, and any other settings it needed to change.

Simply running :TOhtml only does the second step. In particular, the third step is difficult to remember how to do. Without it, :TOhtml usually involves tiresome saving-and-subsequently-deleting of HTML files, and fiddling with a browser.

vim-syncopate's People

Contributors

chiphogg avatar dbarnett avatar hellosputnik avatar htfy96 avatar malcolmr avatar xanderman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-syncopate's Issues

Register syncopate with vim-pi

We should register syncopate with vim-pi, the vim plugin index, so that VAM users can install it with

VAMActivate syncopate

instead of

VAMActivate github:google/vim-syncopate

xclip: -t: No such file or directory

ERROR(shell error): Error running: xclip -t text/html -selection clipboard
xclip: -t: No such file or directory

I'm using xclip 0.12-4 on Arch Linux, and man xclip doesn't give out any information about -t. I guess -t is no longer supported in this version.

Support OSX

When :SyncopateExportToClipboard is used on an OSX machine, it should invoke pbcopy instead of xclip. pbcopy doesn't seem to have HTML support (manpage), so for that to work, we'd need to send it RTF or PostScript.

:SyncopateExportToBrowser should also not default to sensible-browser on OSX, but that's not a big deal anyway since people can already configure the flag to whatever they want.

clipboard should be pasteable into non-rich editors

When I use :SyncopateExportToClipboard and then try to paste into a plain text input (such as a textarea in Chrome or gedit), nothing happens. It should paste a non-formatted version of the copied text, if possible.

Visual mode export mapping should support exporting partial lines

If you visually select part of a line and invoke the mapping for :SyncopateExportToClipboard, syncopate exports the entire line to the clipboard. It would be better to export just the characters in the selection.

The mapping for this wouldn't go through :SyncopateExportToClipboard but would probably be a standalone function.

Would like a way to explicitly omit the background color

In particular, I would like to be able to take snippets for inclusion in a slide deck using the background of the slide deck itself. This is particularly important as I can choose a colorscheme with a very close color to that of the slide deck to ensure things are legible, but the exact background color might be different and jarring in the slide.

Bump version to 0.2.0

I can just directly edit the addon-info.json file from GitHub, but I thought I should get some kind of review first.

Do we also want a CHANGELOG.md? If so, I'll put together a proper pull request.

Support sending output directly to clipboard instead of opening browser

For users with a recent version of xclip installed, it's possible to write the formatted output directly to the clipboard instead of opening a web browser for them to manually copy from (see http://stackoverflow.com/questions/3261379/getting-html-source-or-rich-text-from-the-x-clipboard for details).

To use this for output from :TOhtml, we would also need to process the HTML so we could inline the styles from the header into individual elements, but overall it would make the plugin much simpler and easier to use.

Syncopate fails on files in non-writable directories

I tried using SyncopateExportToBrowser on a file in /etc/ where I didn't have write access and got some errors:

"/etc/passwd.html"
Error detected while processing function syncopate#ExportToBrowser:
line   12:
"/etc/passwd.html" E212: Can't open file for writing
line   19:
E89: No write since last change for buffer 2 (add ! to override)

and my browser opened to a nonexistent file (since the file was never written).

I think rather than writing the buffer from :TOhtml, it would be better to get the contents with getline(1, '$') and write them to a temp file.

Syncopate resets background to light

I use "set bg=dark" in my vimrc. If I run "set bg?", vim prints "background=dark". After I type <> and close the browser window, the background property is reset to light. If I run "set bg?", vim prints "background=light".

Improve error handling for external tools

We should handle cases where external tools like the browser executable and eventually xclip are missing or don't behave as expected.

Currently, if sensible-browser is missing, it silently fails since we never check the exit status. (Hint: maktaba#syscall#Create(['sensible-browser']).Call() behaves a little better by default).

Selecting and exporting all lines in the buffer confusingly reports "exported the entire file"

I was troubleshooting how exporting visual ranges works and really confused to see "Syncopate exported the entire file" when I had specifically selected just part of a line (esp. since I was expecting exporting partial lines to work, #30). Would be saner to ensure it reports "entire file" only when the entire-file version was invoked.

Unfortunately, it's not possible to directly determine whether an explicit range was passed, so the current mapping/command setup with -range=% would need to be tweaked a bit. At the very least, #30 would make the visual mapping not report "entire file".

Document which platforms are supported

There's no a priori reason to expect syncopate wouldn't work on Windows or any other given platform, but it seems to have poor-to-nonexistent support for Windows and doesn't mention what platforms are supported anywhere.

We should document which platforms are completely unsupported in README/docs and/or handle corner cases better (e.g., don't default to sensible-browser on platforms that don't have it).

Let the user choose their browser

We use sensible-browser by default, which I think is Debian-only. Nobody's complained so far, presumably because most people use Ubuntu (which is based on Debian). Still, it would be nice to make this configurable: Glaive syncopate browser=firefox would be nice.

Add an operator function

Right now, if we want to copy-paste only a portion of the buffer, we have to select it visually.

It would be pretty slick if we could add an operator function (:help :map-operator). Then for a mapping like ,<, we could do ,<ip to export a syntax-highlighted paragraph to the clipboard.

Official Google product

DISCLAIMER: This is not an official Google product.

How is this not an official Google product if it's in the google organization and is featured here too?

Document and warn better for missing xclip

There's no documentation about needing to have xclip installed for :SyncopateExportToClipboard to work, and if you try it without xclip installed, it just silently fails to modify the clipboard without showing any error from vim (since it's run with :silent %!xclip). In fact, it falsely reports "Syncopate exported blah blah".

We should document the xclip requirement in the help and also give a reasonable error message if it's missing or fails.

:SyncopateExportToClipboard can't export a dark background to email client.

To reproduce:

  1. :Glaive syncopate !change_colorscheme
  2. :SyncopateExportToClipboard
  3. Ctrl-V to paste into email client. The text colours come out alright, but the background is transparent.

This is one area where :SyncopateExportToBrowser is superior.

The background colour is set in the <body> tag, which webmail clients ignore.

I don't know why it works when we copy-paste from the browser. However, note that the original use case also worked when copying from the browser, even though it "shouldn't have" without g:html_use_css = 0. Presumably, Ctrl-C'ing from the browser "magically" translates the HTML into a form that email clients can use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.