aboutsummaryrefslogtreecommitdiff
path: root/docs/posts/bash_harder_with_vim/index.html
blob: 4eb6662507b636720893d3f8c349553d908f2d9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="/style.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="nerdypepper">
    <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>
              &nbsp
              <span class="stats-number">
                1.6
              </span>
              <span class="stats-unit">min</span>
            </div>
          </div>
          <span class="post-title">
            Bash Harder With Vim
          </span>
          <div class="post-text">
            <p>Bash is tricky, don&#39;t let your editor get in your way. Here&#39;s a couple of neat
additions you could make to your <code>vimrc</code> for a better shell programming
experience.</p>

<h3 id="Man%20pages%20inside%20vim">Man pages inside vim</h3>

<p>Source this script to get started:  </p>

<pre><code>runtime ftplugin&#47;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 = &#39;tab&#39;
</code></pre>

<h3 id="Scratchpad%20to%20test%20your%20commands">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 &#34;$1&#34; | sed -E -e &#34;s&#47;\..+$&#47;&#47;g&#34;  -e &#34;s&#47;_(.)&#47; \u\1&#47;g&#34; -e &#34;s&#47;^(.)&#47;\u\1&#47;g&#34;
</code></pre>

<p>Instead of dropping into a new shell, just test it out directly from vim!</p>

<ul>
<li><p>Yank the line into a register:</p>

<pre><code>yy
</code></pre></li>
<li><p>Paste it into the command-line window:</p>

<pre><code>q:p
</code></pre></li>
<li><p>Make edits as required:</p>

<pre><code>syntax off            # previously run commands
edit index.html       # in a buffer!
w | so %
!echo &#34;new_post.md&#34; | sed -E -e &#34;s&#47;\..+$&#47;&#47;g&#34;  --snip--
^--- note the use of &#39;!&#39;
</code></pre></li>
<li><p>Hit enter with the cursor on the line containing your command!</p>

<pre><code>$ vim
New Post         # output
Press ENTER or type command to continue
</code></pre></li>
</ul>

          </div>
          <div class="separator"></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>