aboutsummaryrefslogtreecommitdiff
path: root/docs/index.html
blob: 766219d1b1e50a5d2cdccbb768f4d99250c68791 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./style.css">
<meta charset="UTF-8">
<title>n</title>

<script>
function showPost(id) {
  let post = document.getElementById(id);
  if (post.style.display == "none") {
    post.style.display = "block";
  } else {
    post.style.display = "none";
  }
}

</script> </head>

<body>
<h1 class="heading">n</h1>


<div class="posts">


    <div class="post">
        <div class="date">31/07 2019</div>
        <a href="#bash_harder_with_vim.md" class="post-link" onClick="showPost('bash_harder_with_vim.md')">Bash Harder With Vim</a>
        <div id="bash_harder_with_vim.md" class="post-text" style="display: block">
            <p>Bash is tricky, dont let your editor get in your way. Here&#8217;s a couple of neat
addtions you could make to your <code>vimrc</code> for a better shell programming
experience.</p>

<p><strong>Man pages inside vim</strong>. 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 = &#39;tab&#39;
</code></pre>

<p><strong>Scratchpad to test your commands</strong>. 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 &quot;$1&quot; | sed -E -e &quot;s/\..+$//g&quot;  -e &quot;s/_(.)/ \u\1/g&quot; -e &quot;s/^(.)/\u\1/g&quot;
</code></pre>

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

<ul>
<li><p>Yank the link 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 &quot;new_post.md&quot; | sed -E -e &quot;s/\..+$//g&quot;  -e &quot;s/_(.)/ \u\1/g&quot; -e &quot;s/^(.)/\u\1/g&quot;
</code></pre></li>
<li><p>Hit enter!</p>

<pre><code>$ vim
New Post         # output
Press ENTER or type command to continue
</code></pre></li>
</ul>
            <a href="#bash_harder_with_vim.md" class="post-end-link" onClick="showPost('bash_harder_with_vim.md')">↑ Collapse</a>
            <div class=separator></div>
        </div>
    </div>
    
    <div class="post">
        <div class="date">30/07 2019</div>
        <a href="#hold_position!.md" class="post-link" onClick="showPost('hold_position!.md')">Hold Position!</a>
        <div id="hold_position!.md" class="post-text" style="display: none">
            <p>Often times, when I run a vim command that makes &#8220;big&#8221; changes to a file (a
macro or a <code>:vimgrep</code> command) I lose my original position and feel disoriented.</p>

<p><em>Save position with <code>winsaveview()</code>!</em></p>

<p>The <code>winsaveview()</code> command returns a <code>Dictionary</code> that contains information
about the view of the current window. This includes the cursor line number,
cursor coloumn, the top most line in the window and a couple of other values,
none of which concern us.</p>

<p>Before running our command (one that jumps around the buffer, a lot), we save
our view, and restore it once its done, with <code>winrestview</code>.</p>

<pre><code>let view = winsaveview()
s/\s\+$//gc              &quot; find and (confirm) replace trailing blanks
winrestview(view)        &quot; restore our original view!
</code></pre>

<p>It might seem a little overkill in the above example, just use &#8220; (double
backticks) instead, but it comes in handy when you run your file through
heavier filtering.</p>
            <a href="#hold_position!.md" class="post-end-link" onClick="showPost('hold_position!.md')">↑ Collapse</a>
            <div class=separator></div>
        </div>
    </div>
    
    <div class="post">
        <div class="date">30/07 2019</div>
        <a href="#get_better_at_yanking_and_putting_in_vim.md" class="post-link" onClick="showPost('get_better_at_yanking_and_putting_in_vim.md')">Get Better At Yanking And Putting In Vim</a>
        <div id="get_better_at_yanking_and_putting_in_vim.md" class="post-text" style="display: none">
            <ol>
<li><p>reselecting previously selected text (i use this to fix botched selections):</p>

<pre><code>gv  &quot; :h gv for more
    &quot; you can use `o` in visual mode to go to the `Other` end of the selection
    &quot; use a motion to fix the selection
</code></pre></li>
<li><p>reselecting previously yanked text:</p>

<pre><code>`[v`]
`[         &quot; marks the beginning of the previously yanked text   :h `[
`]         &quot; marks the end                                       :h `]
 v         &quot; visual select everything in between

nnoremap gb `[v`]    &quot; &quot;a quick map to perform the above
</code></pre></li>
<li><p>pasting and indenting text (in one go):</p>

<pre><code>]p   &quot; put (p) and adjust indent to current line
]P   &quot; put the text before the cursor (P) and adjust indent to current line
</code></pre></li>
</ol>
            <a href="#get_better_at_yanking_and_putting_in_vim.md" class="post-end-link" onClick="showPost('get_better_at_yanking_and_putting_in_vim.md')">↑ Collapse</a>
            <div class=separator></div>
        </div>
    </div>
    
</div>
</body>
</html>