PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim/index.html

https://github.com/benwoody/benwoody.github.com
HTML | 299 lines | 178 code | 114 blank | 7 comment | 0 complexity | 5c214837f36dc76405df4306451fef7f MD5 | raw file
  1. <!DOCTYPE html>
  2. <!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
  3. <!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
  4. <!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
  5. <head>
  6. <meta charset="utf-8">
  7. <title>Copying and Pasting between OS X and Vim - Ben Woodall</title>
  8. <meta name="author" content="Ben Woodall">
  9. <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 &hellip;">
  10. <!-- http://t.co/dKP3o1e -->
  11. <meta name="HandheldFriendly" content="True">
  12. <meta name="MobileOptimized" content="320">
  13. <meta name="viewport" content="width=device-width, initial-scale=1">
  14. <link rel="canonical" href="http://benwoody.github.com/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim">
  15. <link href="/favicon.png" rel="icon">
  16. <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
  17. <link href="/atom.xml" rel="alternate" title="Ben Woodall" type="application/atom+xml">
  18. <script src="/javascripts/modernizr-2.0.js"></script>
  19. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  20. <script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/lib/jquery.min.js"%3E%3C/script%3E'))</script>
  21. <script src="/javascripts/octopress.js" type="text/javascript"></script>
  22. <!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
  23. <link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
  24. <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,400italic' rel='stylesheet' type='text/css'>
  25. <script type="text/javascript">
  26. var _gaq = _gaq || [];
  27. _gaq.push(['_setAccount', 'UA-38526676-1']);
  28. _gaq.push(['_trackPageview']);
  29. (function() {
  30. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  31. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  32. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  33. })();
  34. </script>
  35. </head>
  36. <body >
  37. <header role="banner"><hgroup>
  38. <h1><a href="/">Ben Woodall</a></h1>
  39. <h2>Last of the freelance hackers - Greatest sword fighter in the world</h2>
  40. </hgroup>
  41. </header>
  42. <nav role="navigation"><ul class="main-navigation">
  43. <li><a href="/">Home</a></li>
  44. <li><a href="/blog/archives">Archives</a></li>
  45. <!-- <li><a href="/resume">Resume</a></li> -->
  46. <li><a href="/key">Key</a></li>
  47. </ul>
  48. <div class="social">
  49. <a class="twitter" href="http://twitter.com/benwoodall" title="Twitter">Twitter</a>
  50. <a class="github" href="https://github.com/benwoody" title="GitHub">GitHub</a>
  51. <!-- <a class="coderwall" href="https://coderwall.com/benwoody" title="Coderwall">Coderwall</a> -->
  52. <a class="rss" href="/atom.xml" title="RSS">RSS</a>
  53. </div>
  54. </nav>
  55. <div id="main">
  56. <div id="content">
  57. <div>
  58. <article class="hentry" role="article">
  59. <header>
  60. <h1 class="entry-title">Copying and Pasting Between OS X and Vim</h1>
  61. </header>
  62. <span class="categories">
  63. <a class='category' href='/blog/categories/vim/'>vim</a>
  64. </span>
  65. <div data-showcase-id="6acec641-1364-44db-9149-36b5c4da8061" id="companycam-showcase-root"></div>
  66. <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>
  67. <figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
  68. <span class='line-number'>2</span>
  69. <span class='line-number'>3</span>
  70. <span class='line-number'>4</span>
  71. <span class='line-number'>5</span>
  72. </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>
  73. </span><span class='line'> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.alert&quot;</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>
  74. </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>
  75. </span><span class='line'> <span class="p">});</span>
  76. </span><span class='line'> <span class="p">}),</span> <span class="mi">4000</span><span class="p">);</span>
  77. </span></code></pre></td></tr></table></div></figure>
  78. <!-- more -->
  79. <p>The easiest fix for this is to set the paste mode before you head into insert the code:</p>
  80. <figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
  81. </pre></td><td class='code'><pre><code class=''><span class='line'>:set paste</span></code></pre></td></tr></table></div></figure>
  82. <p>You&rsquo;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&rsquo;re done, revert back with:</p>
  83. <figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
  84. </pre></td><td class='code'><pre><code class=''><span class='line'>:set nopaste</span></code></pre></td></tr></table></div></figure>
  85. <p>Another option is to set your pastetoggle key.</p>
  86. <figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
  87. </pre></td><td class='code'><pre><code class=''><span class='line'>:set pastetoggle=&lt;F2></span></code></pre></td></tr></table></div></figure>
  88. <p>The above code will set the F2 key to toggle between paste and nopaste.</p>
  89. <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>
  90. <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>
  91. <figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
  92. </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>
  93. <p>and in our .vimrc, add the following line:</p>
  94. <figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
  95. </pre></td><td class='code'><pre><code class=''><span class='line'>set clipboard=unnamed</span></code></pre></td></tr></table></div></figure>
  96. <p>Now, anything you yank from vim is available in the clipboard, and anything in the clipboard is available to paste in vim!</p>
  97. </div>
  98. <footer>
  99. <p class="meta">
  100. <span class="byline author vcard">Posted by <span class="fn">Ben Woodall</span></span>
  101. <time datetime="2015-03-24T13:28:00-07:00" pubdate data-updated="true">Mar 24<span>th</span>, 2015</time>
  102. </p>
  103. <div class="sharing">
  104. <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>
  105. <div class="g-plusone" data-size="medium"></div>
  106. </div>
  107. <p class="meta">
  108. <a class="basic-alignment left" href="/blog/2013/10/20/validating-rest-queries-with-rails/" title="Previous Post: Validating REST queries with Rails">&laquo; Validating REST queries with Rails</a>
  109. </p>
  110. </footer>
  111. </article>
  112. <section>
  113. <h1>Comments</h1>
  114. <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>
  115. </div>
  116. </section>
  117. </div>
  118. <aside class="sidebar">
  119. <section>
  120. <h1>Recent Posts</h1>
  121. <ul id="recent_posts">
  122. <li class="post">
  123. <a href="/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim/">Copying and Pasting between OS X and Vim</a>
  124. </li>
  125. <li class="post">
  126. <a href="/blog/2013/10/20/validating-rest-queries-with-rails/">Validating REST queries with Rails</a>
  127. </li>
  128. <li class="post">
  129. <a href="/blog/2013/06/18/go-learn/">Go Learn</a>
  130. </li>
  131. <li class="post">
  132. <a href="/blog/2013/05/24/setup-for-remote-pairing/">Setup for Remote Pairing</a>
  133. </li>
  134. <li class="post">
  135. <a href="/blog/2013/02/14/a-bit-more-git/">A Bit More Git</a>
  136. </li>
  137. </ul>
  138. </section>
  139. <section>
  140. <h1>Latest Tweets</h1>
  141. <a class="twitter-timeline" href="https://twitter.com/benwoodall" data-widget-id="337940470082703361">Tweets by @benwoodall</a>
  142. <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>
  143. </section>
  144. </aside>
  145. </div>
  146. </div>
  147. <footer role="contentinfo"><p>
  148. Copyright &copy; 2015 - Ben Woodall -
  149. <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
  150. </p>
  151. </footer>
  152. <script type="text/javascript">
  153. var disqus_shortname = 'benwoodall';
  154. // var disqus_developer = 1;
  155. var disqus_identifier = 'http://benwoody.github.com/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim/';
  156. var disqus_url = 'http://benwoody.github.com/blog/2015/03/24/copying-and-pasting-between-os-x-and-vim/';
  157. var disqus_script = 'embed.js';
  158. (function () {
  159. var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
  160. dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
  161. (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  162. }());
  163. </script>
  164. <script type="text/javascript">
  165. (function() {
  166. var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true;
  167. script.src = 'https://apis.google.com/js/plusone.js';
  168. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(script, s);
  169. })();
  170. </script>
  171. <script type="text/javascript">
  172. (function(){
  173. var twitterWidgets = document.createElement('script');
  174. twitterWidgets.type = 'text/javascript';
  175. twitterWidgets.async = true;
  176. twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
  177. document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
  178. })();
  179. </script>
  180. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  181. <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
  182. <script src="/javascripts/aharris.js"></script>
  183. <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>
  184. </body>
  185. </html>