/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim/index.html
HTML | 299 lines | 178 code | 114 blank | 7 comment | 0 complexity | 5c214837f36dc76405df4306451fef7f MD5 | raw file
- <!DOCTYPE html>
- <!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
- <!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
- <!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
- <head>
- <meta charset="utf-8">
- <title>Copying and Pasting between OS X and Vim - Ben Woodall</title>
- <meta name="author" content="Ben Woodall">
-
- <meta name="description" content="Copying and pasting between the clipboard and vim has always been a nightmare for me. You find a big chunk of code you want to copy over to your …">
-
- <!-- http://t.co/dKP3o1e -->
- <meta name="HandheldFriendly" content="True">
- <meta name="MobileOptimized" content="320">
- <meta name="viewport" content="width=device-width, initial-scale=1">
-
- <link rel="canonical" href="http://benwoody.github.com/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim">
- <link href="/favicon.png" rel="icon">
- <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
- <link href="/atom.xml" rel="alternate" title="Ben Woodall" type="application/atom+xml">
- <script src="/javascripts/modernizr-2.0.js"></script>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
- <script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/lib/jquery.min.js"%3E%3C/script%3E'))</script>
- <script src="/javascripts/octopress.js" type="text/javascript"></script>
- <!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
- <link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
- <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,400italic' rel='stylesheet' type='text/css'>
-
- <script type="text/javascript">
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-38526676-1']);
- _gaq.push(['_trackPageview']);
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
- </script>
- </head>
- <body >
- <header role="banner"><hgroup>
- <h1><a href="/">Ben Woodall</a></h1>
- <h2>Last of the freelance hackers - Greatest sword fighter in the world</h2>
- </hgroup>
- </header>
- <nav role="navigation"><ul class="main-navigation">
- <li><a href="/">Home</a></li>
- <li><a href="/blog/archives">Archives</a></li>
- <!-- <li><a href="/resume">Resume</a></li> -->
- <li><a href="/key">Key</a></li>
- </ul>
- <div class="social">
- <a class="twitter" href="http://twitter.com/benwoodall" title="Twitter">Twitter</a>
- <a class="github" href="https://github.com/benwoody" title="GitHub">GitHub</a>
- <!-- <a class="coderwall" href="https://coderwall.com/benwoody" title="Coderwall">Coderwall</a> -->
- <a class="rss" href="/atom.xml" title="RSS">RSS</a>
- </div>
- </nav>
- <div id="main">
- <div id="content">
- <div>
- <article class="hentry" role="article">
-
- <header>
-
- <h1 class="entry-title">Copying and Pasting Between OS X and Vim</h1>
-
- </header>
- <span class="categories">
-
- <a class='category' href='/blog/categories/vim/'>vim</a>
-
- </span>
- <div data-showcase-id="6acec641-1364-44db-9149-36b5c4da8061" id="companycam-showcase-root"></div>
- <div class="entry-content"><p>Copying and pasting between the clipboard and vim has always been a nightmare for me. You find a big chunk of code you want to copy over to your project, tab over to vim, get into insert mode, and hit Command + v. What do you get? A big wall of text that has every line tabbed over. Definitely not the format you were trying to copy over.</p>
- <figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
- <span class='line-number'>2</span>
- <span class='line-number'>3</span>
- <span class='line-number'>4</span>
- <span class='line-number'>5</span>
- </pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nb">window</span><span class="p">.</span><span class="nx">setTimeout</span><span class="p">((</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
- </span><span class='line'> <span class="nx">$</span><span class="p">(</span><span class="s2">".alert"</span><span class="p">).</span><span class="nx">slideUp</span><span class="p">(</span><span class="mi">500</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
- </span><span class='line'> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">remove</span><span class="p">();</span>
- </span><span class='line'> <span class="p">});</span>
- </span><span class='line'> <span class="p">}),</span> <span class="mi">4000</span><span class="p">);</span>
- </span></code></pre></td></tr></table></div></figure>
- <!-- more -->
- <p>The easiest fix for this is to set the paste mode before you head into insert the code:</p>
- <figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
- </pre></td><td class='code'><pre><code class=''><span class='line'>:set paste</span></code></pre></td></tr></table></div></figure>
- <p>You’ll notice the statusline shows you in <code>PASTE</code> mode and the tooltip shows <code>-- INSERT (paste) --</code>. Paste in your code and things should be good. When you’re done, revert back with:</p>
- <figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
- </pre></td><td class='code'><pre><code class=''><span class='line'>:set nopaste</span></code></pre></td></tr></table></div></figure>
- <p>Another option is to set your pastetoggle key.</p>
- <figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
- </pre></td><td class='code'><pre><code class=''><span class='line'>:set pastetoggle=<F2></span></code></pre></td></tr></table></div></figure>
- <p>The above code will set the F2 key to toggle between paste and nopaste.</p>
- <p>What I <em>REALLY</em> want is a way to yy and pp from my system clipboard and have it work in vim. One large problem with this is that the methods that OS X uses to go to and from the clipboard (pbcopy and pbpaste) break when you work in tmux sessions.</p>
- <p>To fix this, we need to install <code>reattach-to-user-namespace</code> from <a href="https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard">ChrisJohnsen/tmux-MacOSX-pasteboard</a>. We can install this threw brew:</p>
- <figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
- </pre></td><td class='code'><pre><code class=''><span class='line'>brew install reattach-to-user-namespace</span></code></pre></td></tr></table></div></figure>
- <p>and in our .vimrc, add the following line:</p>
- <figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
- </pre></td><td class='code'><pre><code class=''><span class='line'>set clipboard=unnamed</span></code></pre></td></tr></table></div></figure>
- <p>Now, anything you yank from vim is available in the clipboard, and anything in the clipboard is available to paste in vim!</p>
- </div>
- <footer>
- <p class="meta">
-
-
- <span class="byline author vcard">Posted by <span class="fn">Ben Woodall</span></span>
-
-
- <time datetime="2015-03-24T13:28:00-07:00" pubdate data-updated="true">Mar 24<span>th</span>, 2015</time>
- </p>
-
- <div class="sharing">
-
- <a href="http://twitter.com/share" class="twitter-share-button" data-url="http://benwoody.github.com/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim/" data-via="benwoodall" data-counturl="http://benwoody.github.com/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim/" >Tweet</a>
-
-
- <div class="g-plusone" data-size="medium"></div>
-
-
- </div>
-
- <p class="meta">
-
- <a class="basic-alignment left" href="/blog/2013/10/20/validating-rest-queries-with-rails/" title="Previous Post: Validating REST queries with Rails">« Validating REST queries with Rails</a>
-
-
- </p>
- </footer>
- </article>
- <section>
- <h1>Comments</h1>
- <div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
- </div>
- </section>
- </div>
- <aside class="sidebar">
-
- <section>
- <h1>Recent Posts</h1>
- <ul id="recent_posts">
-
- <li class="post">
- <a href="/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim/">Copying and Pasting between OS X and Vim</a>
- </li>
-
- <li class="post">
- <a href="/blog/2013/10/20/validating-rest-queries-with-rails/">Validating REST queries with Rails</a>
- </li>
-
- <li class="post">
- <a href="/blog/2013/06/18/go-learn/">Go Learn</a>
- </li>
-
- <li class="post">
- <a href="/blog/2013/05/24/setup-for-remote-pairing/">Setup for Remote Pairing</a>
- </li>
-
- <li class="post">
- <a href="/blog/2013/02/14/a-bit-more-git/">A Bit More Git</a>
- </li>
-
- </ul>
- </section>
- <section>
- <h1>Latest Tweets</h1>
- <a class="twitter-timeline" href="https://twitter.com/benwoodall" data-widget-id="337940470082703361">Tweets by @benwoodall</a>
- <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
- </section>
-
- </aside>
- </div>
- </div>
- <footer role="contentinfo"><p>
- Copyright © 2015 - Ben Woodall -
- <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
- </p>
- </footer>
-
- <script type="text/javascript">
- var disqus_shortname = 'benwoodall';
-
-
- // var disqus_developer = 1;
- var disqus_identifier = 'http://benwoody.github.com/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim/';
- var disqus_url = 'http://benwoody.github.com/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim/';
- var disqus_script = 'embed.js';
-
- (function () {
- var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
- dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
- }());
- </script>
- <script type="text/javascript">
- (function() {
- var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true;
- script.src = 'https://apis.google.com/js/plusone.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(script, s);
- })();
- </script>
- <script type="text/javascript">
- (function(){
- var twitterWidgets = document.createElement('script');
- twitterWidgets.type = 'text/javascript';
- twitterWidgets.async = true;
- twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
- document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
- })();
- </script>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
- <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
- <script src="/javascripts/aharris.js"></script>
- <script> (function () { var ccShowcaseRoot = document.getElementById("companycam-showcase-root"); if (!ccShowcaseRoot.attachShadow || !window.fetch) { return; } var ccShowcaseRootParent = document.getElementsByTagName("body")[0]; var ccShowcaseScript = document.createElement("script"); ccShowcaseScript.src = 'https://showcase.companycam.com/bundle.js'; ccShowcaseScript.type = "text/javascript"; ccShowcaseRootParent.appendChild(ccShowcaseScript); })();</script>
-
- </body>
- </html>