<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: jesús gollonet</title>
    <description>The latest articles on Forem by jesús gollonet (@jesusgollonet).</description>
    <link>https://forem.com/jesusgollonet</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F167807%2F17090813-1df6-4d63-8602-aad52df9fccd.jpeg</url>
      <title>Forem: jesús gollonet</title>
      <link>https://forem.com/jesusgollonet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jesusgollonet"/>
    <language>en</language>
    <item>
      <title>Yank hard wrapped text, or how to paste your vim markdown into dev.to</title>
      <dc:creator>jesús gollonet</dc:creator>
      <pubDate>Mon, 17 Jun 2019 14:51:57 +0000</pubDate>
      <link>https://forem.com/jesusgollonet/yank-hard-wrapped-text-or-how-to-paste-your-vim-markdown-into-dev-to-4j8c</link>
      <guid>https://forem.com/jesusgollonet/yank-hard-wrapped-text-or-how-to-paste-your-vim-markdown-into-dev-to-4j8c</guid>
      <description>&lt;p&gt;This was not supposed to be my first post here. But I was writing that one and ran into a problem.&lt;/p&gt;

&lt;p&gt;I write markdown in vim, and I hard wrap lines at 80 characters. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UkNNByrT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/9nhjie04hssb5l05c9ep.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UkNNByrT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/9nhjie04hssb5l05c9ep.png" alt="" width="800" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my local preview everything was looking fine, but when pasting my post into the dev.to editor, I got greeted by a bunch of broken lines: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qdburOVE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/ppv37qqie5aiafor8sgh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qdburOVE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/ppv37qqie5aiafor8sgh.png" alt="" width="580" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After some googling, I found out that there is an open issue with markdown linebreaks.&lt;/p&gt;


&lt;div class="ltag_github-liquid-tag"&gt;
  &lt;h1&gt;
    &lt;a href="https://github.com/thepracticaldev/dev.to/issues/575"&gt;
      &lt;img class="github-logo" alt="GitHub logo" src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg"&gt;
      &lt;span class="issue-title"&gt;
        Handle linebreaks in markdown
      &lt;/span&gt;
      &lt;span class="issue-number"&gt;#575&lt;/span&gt;
    &lt;/a&gt;
  &lt;/h1&gt;
  &lt;div class="github-thread"&gt;
    &lt;div class="timeline-comment-header"&gt;
      &lt;a href="https://github.com/Defman21"&gt;
        &lt;img class="github-liquid-tag-img" src="https://res.cloudinary.com/practicaldev/image/fetch/s--2xkoN333--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://avatars2.githubusercontent.com/u/7100645%3Fv%3D4" alt="Defman21 avatar"&gt;
      &lt;/a&gt;
      &lt;div class="timeline-comment-header-text"&gt;
        &lt;strong&gt;
          &lt;a href="https://github.com/Defman21"&gt;Defman21&lt;/a&gt;
        &lt;/strong&gt; posted on &lt;a href="https://github.com/thepracticaldev/dev.to/issues/575"&gt;&lt;time&gt;Sep 01, 2018&lt;/time&gt;&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag-github-body"&gt;
      
&lt;h2&gt;
&lt;span class="octicon octicon-link"&gt;&lt;/span&gt;Feature Request or Task&lt;/h2&gt;
&lt;p&gt;Feature request.&lt;/p&gt;
&lt;h3&gt;
&lt;span class="octicon octicon-link"&gt;&lt;/span&gt;User Story / Description&lt;/h3&gt;
&lt;p&gt;I'm writing my articles in a code editor and line-break them manually at 80 chars, so I could read them anywhere without worrying about word-wrap and stuff. Markdown does not count these line-breaks as line-breaks and every markdown parser I saw join them automatically, so&lt;/p&gt;
&lt;div class="highlight highlight-source-lisp js-code-highlight"&gt;
&lt;pre&gt;Hello
world&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;becomes&lt;/p&gt;
&lt;div class="highlight highlight-source-lisp js-code-highlight"&gt;
&lt;pre&gt;Hello world&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Dev.to, however, handle them as line-breaks.&lt;/p&gt;
&lt;h3&gt;
&lt;span class="octicon octicon-link"&gt;&lt;/span&gt;Definition of Done&lt;/h3&gt;
&lt;div class="highlight highlight-source-lisp js-code-highlight"&gt;
&lt;pre&gt;Hello
world&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;in a dev.to article renders as&lt;/p&gt;
&lt;div class="highlight highlight-source-lisp js-code-highlight"&gt;
&lt;pre&gt;Hello world&lt;/pre&gt;

&lt;/div&gt;

    &lt;/div&gt;
    &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/thepracticaldev/dev.to/issues/575"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;What to do? I could switch to soft linebreaks, but navigation gets cumbersome. Maybe I could try to use the dev.to API to post and preprocess the markdown before... sounds like more work than I'd like to do. What's a &lt;del&gt;lazy&lt;/del&gt; good enough approach? &lt;/p&gt;

&lt;p&gt;Have vim do it! &lt;/p&gt;

&lt;p&gt;Can I edit the text with my usual setup but copy it as if it didn't have linebreaks? You can guess that was a yes. Here's the little monster I came up with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;
&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;map&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;r&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; oldtw&lt;span class="p"&gt;=&lt;/span&gt;&amp;amp;&lt;span class="nb"&gt;textwidth&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;cr&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; \&lt;span class="p"&gt;|:&lt;/span&gt;&lt;span class="k"&gt;set&lt;/span&gt; &lt;span class="nb"&gt;textwidth&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;10000&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;cr&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; \&lt;span class="p"&gt;|&lt;/span&gt; ggVGgqgvy \&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &amp;amp;&lt;span class="nb"&gt;textwidth&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;oldtw &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;cr&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; \&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;set&lt;/span&gt; &lt;span class="nb"&gt;textwidth&lt;/span&gt;? &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;cr&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; \&lt;span class="p"&gt;|&lt;/span&gt; gvgq

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break it down (omitting &lt;code&gt;\|&lt;/code&gt; which is a command separator and &lt;code&gt;&amp;lt;cr&amp;gt;&lt;/code&gt; which just means press enter after typing the command):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;:map ,r&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:let oldtw=&amp;amp;textwidth&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:set textwidth=10000&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ggvGgqgvy&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:let &amp;amp;textwidth=oldtw&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:set textwidth?&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;gvgq&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;:map ,r&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;on pressing the ,r shortcut...&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;:let oldtw=&amp;amp;textwidth&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;store whatever your current &lt;code&gt;textwidth&lt;/code&gt; is (in my case 80)&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;:set textwidth=10000&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;set &lt;code&gt;textwidth&lt;/code&gt; to some ridiculously large value so that you get no line breaks on long paragraphs&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;ggvGgqgvy&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;hah &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;gg&lt;/code&gt;: go to the top of the file, &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;v&lt;/code&gt;: enable visual mode,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;G&lt;/code&gt;: go to the bottom of the file (since you're in visual mode this will select everything)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gq&lt;/code&gt;: reformat the paragraph (since &lt;code&gt;textwidth&lt;/code&gt; is now 10000 all your paragraphs will be without newlines)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;:let &amp;amp;textwidth=oldtw&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Restore the &lt;code&gt;textwidth&lt;/code&gt; property to this old values (warning! this is not enough!, see &lt;a href="http://learnvimscriptthehardway.stevelosh.com/chapters/19.html#options-as-variables"&gt;options as values in vimscript&lt;/a&gt;)&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;:set textwidth?&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Value is now fully restored&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;gvgq&lt;/code&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;gv&lt;/code&gt;: start visual mode with the last selection (so whole document)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gq&lt;/code&gt;: reformat the paragraph again with your old &lt;code&gt;textwidth&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that's it! Your post will be on your clipboard with uninterrupted paragraphs, and your editor will still display your nicely wrapped text.&lt;/p&gt;

&lt;p&gt;Admittedly it has a few corner cases and yes, I should turn it into a function but solving problems with this uber pragmatic approach is a lot of fun. And fast. And I wanted to get something posted already!&lt;/p&gt;

</description>
      <category>vim</category>
      <category>markdown</category>
    </item>
  </channel>
</rss>
