{"data":{"markdownRemark":{"html":"<h2 id=\"how-can-i-add-the-output-of-a-shell-command-to-my-current-file-open-in-vim\"><a href=\"#how-can-i-add-the-output-of-a-shell-command-to-my-current-file-open-in-vim\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How can I add the output of a shell command to my current file open in Vim?</h2>\n<p>Check it out, you're in Vim, you're working on your file, and then... you need the output of some command... something like this...</p>\n<blockquote>\n<p>and here is the contents of my /tmp folder ...</p>\n</blockquote>\n<p>well, now what? you have to save and exit Vim, and probably most of you will do something like this...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ls -l /tmp &gt;&gt; myfile</code></pre></div>\n<p>right? WELL NOOOO MOOOOREEEE</p>\n<p>here we go... while you are still in Vim, try this...\nenter \"escape mode\" by pressing <code class=\"language-text\">esc</code> key and type:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">:r! ls -l /tmp</code></pre></div>\n<p>and.... the contents of your /tmp directory are automatically entered into your directory. oooooooooh sploosh.</p>\n<p>\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/tmp-d969d456d3fddea1b1ffcdff03b55803-eeccd.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block;  max-width: 710px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 77.85714285714286%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAIAAACZeshMAAAACXBIWXMAAA7DAAAOwwHHb6hkAAACEUlEQVQoz41Ty27TQBSNHTuxJ8GPxJ6x52GPx07Iy22TpkmLQlu1EhJC7LopEoIFv8WSNQ+psEBCfBrXSUphkcBRdC3FOvece+51rciLTIqiUEVRUEo554wyx3EQQq1/odZGyO/02+3ANA1kI9M0NU3XNK32P/B9vDy/O5i9QwhIBsaYYCzTVAhOGeOMKaXgn4hEggtk23+RPZ+dXn6fnrwJg3YQYMZ5FMUwwuDxoN/vDweDyXjc6/VypUbDoUwlDsN6vb4lYzJanN+Nyxe+jwiJGGMEk6LIgZnJrMhz+AEZ2vWqRy+T0jCMLTmm5fLi6+TgpefardYjCCyOYpUpxqhlWY1GwzDNxj3MNR4SCfHw7OrHbP7adRq2hTir0hZC5CoPw1DX9X2BRXF5dvVzevLWdUDBojEF5SRJVJZBSKC2j9ztZsuLb+XRDdjudLoxpYQQWD6MBzlDl8oL46I6gMoRvDV+BxYE/PjJh/Hk2vdazWYT0oZTgajAtoSa5xChbdtwM1BsG3Kw9IeZQz49fT8pn3ku0vU69AYpWAkgTVMlM5DaaTsIIlA+nL1yneaaXPmU94BNxXG8k0yInK8+Hc5uN2QuBPjcKEOFnUVxtJPMk8Xi6WeY2XNbulZPQJlvbQOqzKM9ZHE8X30Zl899D/1hOwNAC6j7ZqbsaL76OBxdbwLj6w8iTdIkgbwkHOMe8i/leE6kPwHDrgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n    >\n      <img\n        class=\"gatsby-resp-image-image\"\n        style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n        alt=\"tmp\"\n        title=\"\"\n        src=\"/static/tmp-d969d456d3fddea1b1ffcdff03b55803-09ff3.png\"\n        srcset=\"/static/tmp-d969d456d3fddea1b1ffcdff03b55803-2279c.png 178w,\n/static/tmp-d969d456d3fddea1b1ffcdff03b55803-dbe09.png 355w,\n/static/tmp-d969d456d3fddea1b1ffcdff03b55803-09ff3.png 710w,\n/static/tmp-d969d456d3fddea1b1ffcdff03b55803-eeccd.png 980w\"\n        sizes=\"(max-width: 710px) 100vw, 710px\"\n      />\n    </span>\n  </span>\n  \n  </a>\n    </p>\n<h3 id=\"dont-give-no-damn-about-contents-of-the-tmp-folder-what-about-something-else\"><a href=\"#dont-give-no-damn-about-contents-of-the-tmp-folder-what-about-something-else\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>dont give no damn about contents of the tmp folder, what about something else...</h3>\n<p>ok ....</p>\n<p>what about this, open a new Vim file and try This</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Press &quot;i&quot; for insert mode\ntype: Todays date is &lt;esc&gt; :r! date\n&lt;i&gt;&lt;enter&gt;\ntype: my username is &lt;esc&gt; :r! whoami\n&lt;i&gt;&lt;enter&gt;\ntype: kernel version is &lt;esc&gt; :r! uname -a</code></pre></div>\n<p>without leaving Vim, the output of the <code class=\"language-text\">:r!</code> shell commands should produce something like this...</p>\n<p>\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/output-b70b9ead3b4f9aca3a0215b052269d3d-b4f0b.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block;  max-width: 710px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 12.256267409470754%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAACCAYAAABYBvyLAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAPUlEQVQI12NQkVP4L8LF/Z+Ple0/JwMjEDNAafIwAwefwH9WNtb/jMzM/5lZWP4zs7LCaQYmpv8MQAtIwQAxoCmX8gXhNgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n    >\n      <img\n        class=\"gatsby-resp-image-image\"\n        style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n        alt=\"output\"\n        title=\"\"\n        src=\"/static/output-b70b9ead3b4f9aca3a0215b052269d3d-09ff3.png\"\n        srcset=\"/static/output-b70b9ead3b4f9aca3a0215b052269d3d-2279c.png 178w,\n/static/output-b70b9ead3b4f9aca3a0215b052269d3d-dbe09.png 355w,\n/static/output-b70b9ead3b4f9aca3a0215b052269d3d-09ff3.png 710w,\n/static/output-b70b9ead3b4f9aca3a0215b052269d3d-393d8.png 1065w,\n/static/output-b70b9ead3b4f9aca3a0215b052269d3d-3667d.png 1420w,\n/static/output-b70b9ead3b4f9aca3a0215b052269d3d-b4f0b.png 1436w\"\n        sizes=\"(max-width: 710px) 100vw, 710px\"\n      />\n    </span>\n  </span>\n  \n  </a>\n    </p>\n<p>and thats it!,</p>\n<blockquote>\n<p>👍  One small tip, you can also forward the output of a shell command directly to a vim session from the command line... lets look how quickly...</p>\n<p>Surely you all know how to pipe the output of a command to a file...</p>\n<p>ls -l ~ | my_file</p>\n<p>Easy,\nbut then you have to open that file in Vim to add anything to it... no longer!</p>\n<p>ls -l ~ | vim -</p>\n<p>a viola! a new vim session open with the output of your command already inserted to the file...\n\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/home-3bf2c3386f36bcc285b6884dfb686c80-6e834.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block;  max-width: 710px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 4.180887372013651%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAABCAYAAADeko4lAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAL0lEQVQI113JQQ4AMAgCQUTt/3+MGttLDxMSFklXEDoBGSC2bD7MPtx9HfvFNa0AGogUVDyMHOMAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n    >\n      <img\n        class=\"gatsby-resp-image-image\"\n        style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n        alt=\"home\"\n        title=\"\"\n        src=\"/static/home-3bf2c3386f36bcc285b6884dfb686c80-09ff3.png\"\n        srcset=\"/static/home-3bf2c3386f36bcc285b6884dfb686c80-2279c.png 178w,\n/static/home-3bf2c3386f36bcc285b6884dfb686c80-dbe09.png 355w,\n/static/home-3bf2c3386f36bcc285b6884dfb686c80-09ff3.png 710w,\n/static/home-3bf2c3386f36bcc285b6884dfb686c80-393d8.png 1065w,\n/static/home-3bf2c3386f36bcc285b6884dfb686c80-6e834.png 1172w\"\n        sizes=\"(max-width: 710px) 100vw, 710px\"\n      />\n    </span>\n  </span>\n  \n  </a>\n    </p>\n<p>\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/homevim-ad9a816a1776d3e73f8ec88fd423a36e-b7c4e.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block;  max-width: 710px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 30.67814854682454%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAIAAABM9SnKAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABEUlEQVQY012OTU7DMBSEbbex4xdHcWJbcewkJF3QBYj+EH4kKlhyBYTKjjtwEBZwC0BC4nq4tFSIT7N40mjmDZp2vUmEEUURcwWJAshjDphsxREKihBimwMH7a0gZCqrjD8eXtp+JQQdRzSTudK6tJYyhjBivKgnj0JOEUF4NEZ/cU1t7eT8+msxrI1KRJI659um7boe+Mg3t6eXr0fzp8rNswykzDnnAMAo3YTLympTD6uP2XJd5MEQta8Dfd8DxOMopVTvP2GMRz8QQnZhpeywepsvH7Zh51ztNwVlaROgIj30B3eMSUJClvyb7W3VLa/eTxb3WiVhVFW5tm1DhdFaSjk7e764+VTKA493D3/5Bh4JHSK3xMDRAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n    >\n      <img\n        class=\"gatsby-resp-image-image\"\n        style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n        alt=\"homevim\"\n        title=\"\"\n        src=\"/static/homevim-ad9a816a1776d3e73f8ec88fd423a36e-09ff3.png\"\n        srcset=\"/static/homevim-ad9a816a1776d3e73f8ec88fd423a36e-2279c.png 178w,\n/static/homevim-ad9a816a1776d3e73f8ec88fd423a36e-dbe09.png 355w,\n/static/homevim-ad9a816a1776d3e73f8ec88fd423a36e-09ff3.png 710w,\n/static/homevim-ad9a816a1776d3e73f8ec88fd423a36e-b7c4e.png 929w\"\n        sizes=\"(max-width: 710px) 100vw, 710px\"\n      />\n    </span>\n  </span>\n  \n  </a>\n    </p>\n</blockquote>\n<p>\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/powers-b89b290f880cf413da238817d513670b-28c2a.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block;  max-width: 500px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 56.199999999999996%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAAsSAAALEgHS3X78AAACqElEQVQoz2P4++fbnx+v//3+0Zyb0JHuu2V6TU+a3745dU3ZUdoyQpa6av3tLd8+P/z//++fP38Wd5TtnV1+8/Ciqb0F9UkBDP/+fPv7+/3////7itN683zWdhcemFpaGOEgwcZkJC2hLSrIz8DQVpnzHwxO7ly9vDXl8anVc7symnIjGX79/Pz75zugxOLuhoJwuzktmfvm15mrSkaa6tT7epV7OAcbqmtICu1ctfTasaOP71xd1Rb9cFPX0QWljSmuDP9BDvoBJPetWZwTaLmgOW1lV56hvKiNspyXjo67pqaDuoqxtLifhraztGxLelpXbviZFc37F1a3FEUy1FcWXb9yGqj57LGDecGW04s917b62qjLBuprRRga+Kpr+OpoGYoIrJ4zp6uszENBJc7FcUZt0pqW1NrcaAYgyMtMBWp++eRhaohzR67vutagVBfTFEsDB1lpC3GxcH2NSFP9/pzcyUXFGbYOyS5uaV4Wk8PtE+OCQJo9XZwg4VGam5QYYDmjItRNW85FRcpNRtpSUNhCVtRcRXb/pjVdhSXhJmapDq4JHvZl0c5u1sYMLExMFsZGr16+/PXr97SJ3RGe5hMq4001lW00lOzVlU3lZAzkJINdbd48u//77791K5Zn+wVn+vlEe9hYG1kyTO7pmDZt2u7du5cuXdrf05WZGFtbUxPs7RMXEpSdlpqWkFCcndXW3FSSmzNt6tRFixa1NDR2tbZ1drSFh0QzHN+5/sCubedPHZ86sbeyrDw7IyvQzy89JTU/LTU3JbmxuiYpNLggJzsmKrq4IL+4qKAoISnT2z/a3SEpIohBS0LI3dLYRE3FzsQsKSYu1C/A3tQyOiQiPjw8MzyoPjczwMXF183T28k1MSoGyPCzsctw9fI10PKxMwIAt8QpwLzVmBQAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n    >\n      <img\n        class=\"gatsby-resp-image-image\"\n        style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n        alt=\"powers\"\n        title=\"\"\n        src=\"/static/powers-b89b290f880cf413da238817d513670b-28c2a.png\"\n        srcset=\"/static/powers-b89b290f880cf413da238817d513670b-938a1.png 178w,\n/static/powers-b89b290f880cf413da238817d513670b-b8a20.png 355w,\n/static/powers-b89b290f880cf413da238817d513670b-28c2a.png 500w\"\n        sizes=\"(max-width: 500px) 100vw, 500px\"\n      />\n    </span>\n  </span>\n  \n  </a>\n    </p>\n<p>Today we learned <strong>two</strong> ways to forward the output of a shell command directly to a vim session without needing to switch between bash and Vim...like a boss!</p>\n<p>If Sean Helped You today, feel free to share this post or connect with us soon, available via <a href=\"mailto:seanwillhelpyou@gmail.com\">gmail</a>, <a href=\"https://app.slack.com/client/TLMMVFQ1X/CLVTNC1MM\">slack</a> or <a href=\"https://github.com/RH-sdavey/sean-will-help-you\">github</a>.\nThanks for reading!</p>","timeToRead":2,"excerpt":"How can I add the output of a shell command to my current file open in Vim? Check it out, you're in Vim, you're working on your file, and…","frontmatter":{"title":"Run shell commands in (or to) Vim directly","cover":"https://picsum.photos/id/1073/2500/1000","date":"2019-01-29","category":"sysadmin","tags":["Sysadmin","Easy","Linux","Vim"],"author":"Endless"},"fields":{"slug":"/run-shell-commands-in-or-to-vim-directly"}},"prev":{"excerpt":"If you regularly need to open the same windows in Google Chrome, follow this tutorial to learn how to automate…","frontmatter":{"title":"Windows: Create a script to open webpages automatically","cover":"https://picsum.photos/id/1048/2500/1000","date":"2019-02-17"},"fields":{"slug":"/windows-create-a-script-to-open-webpages-automatically"}},"next":{"excerpt":"Hello, We are Sean, and We're very happy You're here! TODO(explanation of site here) I want to follow a learning…","frontmatter":{"title":"Welcome! If this is your first time on SWHY, take a look here!","cover":"https://unsplash.it/1280/900/?random","date":"2999-10-19"},"fields":{"slug":"/welcome-if-this-is-your-first-time-on-swhy-take-a-look-here"}},"authors":{"edges":[{"node":{"uid":"Endless","name":"Endless","image":"https://api.adorable.io/avatars/285/pwpwpw.png","url":"https://github.com/RH-sdavey/sean-will-help-you","bio":"Endless Will Help You"}},{"node":{"uid":"Weez","name":"Salloweezy","image":"https://api.adorable.io/avatars/124/weezzzy.png","url":"http://gatsbyjs.org/","bio":"."}},{"node":{"uid":"Sean","name":"Sean","image":"https://api.adorable.io/avatars/124/weez.png","url":"https://github.com/RH-sdavey/sean-will-help-you","bio":"SEAN User created for SWHY"}},{"node":{"uid":"casper","name":"Casper User","image":"https://api.adorable.io/avatars/124/seasz.png","url":"http://gatsbyjs.org/","bio":"Yeah, I like animals better than people sometimes... Especially dogs. Dogs are the best. Every time you come home, they act like they haven't seen you in a year. And the good thing about dogs... is they got different dogs for different people."}},{"node":{"uid":"guinevere","name":"Guinevere Kuiper","image":"https://api.adorable.io/avatars/282/seaszss.png","url":"https://randomuser.me/api/?seed=user1","bio":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam laoreet lorem nec ligula aliquet, porta blandit augue luctus. Vivamus ac quam diam. Sed vestibulum pharetra hendrerit."}}]}},"pageContext":{"slug":"/run-shell-commands-in-or-to-vim-directly","total":12,"prev":"/windows-create-a-script-to-open-webpages-automatically","next":"/welcome-if-this-is-your-first-time-on-swhy-take-a-look-here"}}