<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/syntax.css"> <meta charset="UTF-8"> <meta name="viewport" content="initial-scale=1"> <meta content="#ffffff" name="theme-color"> <meta name="HandheldFriendly" content="true"> <meta property="og:title" content="Bash Harder With Vim"> <meta property="og:type" content="website"> <meta property="og:description" content="a static site {for, by, about} me "> <meta property="og:url" content="https://peppe.rs"> <link rel="icon" type="image/x-icon" href="/favicon.png"> <title>Bash Harder With Vim · peppe.rs</title> <body> <div class="posts"> <div class="post"> <a href="/" class="post-end-link">⟵ Back</a> <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/bash_harder_with_vim.md ">View Raw</a> <div class="separator"></div> <div class="date"> 31/07 — 2019 <div class="stats"> <span class="stats-number"> 24.37 </span> <span class="stats-unit">cm</span>   <span class="stats-number"> 1.6 </span> <span class="stats-unit">min</span> </div> </div> <h1> Bash Harder With Vim </h1> <div class="post-text"> <p>Bash is tricky, don’t let your editor get in your way. Here’s a couple of neat additions you could make to your <code>vimrc</code> for a better shell programming experience.</p> <h3 id="man-pages-inside-vim">Man pages inside vim</h3> <p>Source this script to get started:</p> <pre><code>runtime ftplugin/man.vim</code></pre> <p>Now, you can open manpages inside vim with <code>:Man</code>! It adds nicer syntax highlighting and the ability to jump around with <code>Ctrl-]</code> and <code>Ctrl-T</code>.</p> <p>By default, the manpage is opened in a horizontal split, I prefer using a new tab:</p> <pre><code>let g:ft_man_open_mode = 'tab'</code></pre> <h3 id="scratchpad-to-test-your-commands">Scratchpad to test your commands</h3> <p>I often test my <code>sed</code> substitutions, here is a sample from the script used to generate this site:</p> <pre><code># a substitution to convert snake_case to Title Case With Spaces echo "$1" | sed -E -e "s/\..+$//g" -e "s/_(.)/ \u\1/g" -e "s/^(.)/\u\1/g"</code></pre> <p>Instead of dropping into a new shell, just test it out directly from vim!</p> <ul> <li>Yank the line into a register:</li> </ul> <pre><code>yy</code></pre> <ul> <li>Paste it into the command-line window:</li> </ul> <pre><code>q:p</code></pre> <ul> <li>Make edits as required:</li> </ul> <pre><code>syntax off # previously run commands edit index.html # in a buffer! w | so % !echo "new_post.md" | sed -E -e "s/\..+$//g" --snip-- ^--- note the use of '!'</code></pre> <ul> <li>Hit enter with the cursor on the line containing your command!</li> </ul> <pre><code>$ vim New Post # output Press ENTER or type command to continue</code></pre> </div> <div class=intro> Hi. <div class=hot-links> <a href=https://peppe.rs/index.xml class=feed-button>Subscribe</a> <a href=https://liberapay.com/nerdypepper/donate class=donate-button>Donate</a> </div> <p>I'm Akshay, I go by nerd or nerdypepper on the internet.</p> <p> I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie. </p> <p>Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.</p> </div> <a href="/" class="post-end-link">⟵ Back</a> <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/bash_harder_with_vim.md ">View Raw</a> </div> </div> </body> </html>