diff options
author | NerdyPepper <[email protected]> | 2019-07-31 16:49:46 +0100 |
---|---|---|
committer | NerdyPepper <[email protected]> | 2019-07-31 16:49:46 +0100 |
commit | be70d338e35209c94ce875734fe483b21f98b5b1 (patch) | |
tree | 5e4ede704c62fc9bbf8ee6e485dd4e47d80c60b5 | |
parent | 502f7102495cf7919b3be67d1bec43a7f3591ee1 (diff) |
new post; bash harder with vim
-rw-r--r-- | docs/index.html | 60 | ||||
-rw-r--r-- | posts/bash_harder_with_vim.md | 57 |
2 files changed, 116 insertions, 1 deletions
diff --git a/docs/index.html b/docs/index.html index 70fd4c8..766219d 100644 --- a/docs/index.html +++ b/docs/index.html | |||
@@ -26,9 +26,67 @@ function showPost(id) { | |||
26 | 26 | ||
27 | 27 | ||
28 | <div class="post"> | 28 | <div class="post"> |
29 | <div class="date">31/07 2019</div> | ||
30 | <a href="#bash_harder_with_vim.md" class="post-link" onClick="showPost('bash_harder_with_vim.md')">Bash Harder With Vim</a> | ||
31 | <div id="bash_harder_with_vim.md" class="post-text" style="display: block"> | ||
32 | <p>Bash is tricky, dont let your editor get in your way. Here’s a couple of neat | ||
33 | addtions you could make to your <code>vimrc</code> for a better shell programming | ||
34 | experience.</p> | ||
35 | |||
36 | <p><strong>Man pages inside vim</strong>. Source this script to get started: </p> | ||
37 | |||
38 | <pre><code>runtime ftplugin/man.vim | ||
39 | </code></pre> | ||
40 | |||
41 | <p>Now, you can open manpages inside vim with <code>:Man</code>! It adds nicer syntax highlighting | ||
42 | and the ability to jump around with <code>Ctrl-]</code> and <code>Ctrl-T</code>.</p> | ||
43 | |||
44 | <p>By default, the manpage is opened in a horizontal split, I prefer using a new tab:</p> | ||
45 | |||
46 | <pre><code>let g:ft_man_open_mode = 'tab' | ||
47 | </code></pre> | ||
48 | |||
49 | <p><strong>Scratchpad to test your commands</strong>. I often test my <code>sed</code> substitutions, here is | ||
50 | a sample from the script used to generate this site: </p> | ||
51 | |||
52 | <pre><code># a substitution to convert snake_case to Title Case With Spaces | ||
53 | echo "$1" | sed -E -e "s/\..+$//g" -e "s/_(.)/ \u\1/g" -e "s/^(.)/\u\1/g" | ||
54 | </code></pre> | ||
55 | |||
56 | <p>Instead of dropping into a new shell, just test it out directly from vim!</p> | ||
57 | |||
58 | <ul> | ||
59 | <li><p>Yank the link into a register:</p> | ||
60 | |||
61 | <pre><code>yy | ||
62 | </code></pre></li> | ||
63 | <li><p>Paste it into the command-line window:</p> | ||
64 | |||
65 | <pre><code>q:p | ||
66 | </code></pre></li> | ||
67 | <li><p>Make edits as required:</p> | ||
68 | |||
69 | <pre><code>syntax off # previously run commands | ||
70 | edit index.html # in a buffer! | ||
71 | w | so % | ||
72 | echo "new_post.md" | sed -E -e "s/\..+$//g" -e "s/_(.)/ \u\1/g" -e "s/^(.)/\u\1/g" | ||
73 | </code></pre></li> | ||
74 | <li><p>Hit enter!</p> | ||
75 | |||
76 | <pre><code>$ vim | ||
77 | New Post # output | ||
78 | Press ENTER or type command to continue | ||
79 | </code></pre></li> | ||
80 | </ul> | ||
81 | <a href="#bash_harder_with_vim.md" class="post-end-link" onClick="showPost('bash_harder_with_vim.md')">↑ Collapse</a> | ||
82 | <div class=separator></div> | ||
83 | </div> | ||
84 | </div> | ||
85 | |||
86 | <div class="post"> | ||
29 | <div class="date">30/07 2019</div> | 87 | <div class="date">30/07 2019</div> |
30 | <a href="#hold_position!.md" class="post-link" onClick="showPost('hold_position!.md')">Hold Position!</a> | 88 | <a href="#hold_position!.md" class="post-link" onClick="showPost('hold_position!.md')">Hold Position!</a> |
31 | <div id="hold_position!.md" class="post-text" style="display: block"> | 89 | <div id="hold_position!.md" class="post-text" style="display: none"> |
32 | <p>Often times, when I run a vim command that makes “big” changes to a file (a | 90 | <p>Often times, when I run a vim command that makes “big” changes to a file (a |
33 | macro or a <code>:vimgrep</code> command) I lose my original position and feel disoriented.</p> | 91 | macro or a <code>:vimgrep</code> command) I lose my original position and feel disoriented.</p> |
34 | 92 | ||
diff --git a/posts/bash_harder_with_vim.md b/posts/bash_harder_with_vim.md new file mode 100644 index 0000000..8dc4a50 --- /dev/null +++ b/posts/bash_harder_with_vim.md | |||
@@ -0,0 +1,57 @@ | |||
1 | Bash is tricky, dont let your editor get in your way. Here's a couple of neat | ||
2 | addtions you could make to your `vimrc` for a better shell programming | ||
3 | experience. | ||
4 | |||
5 | **Man pages inside vim**. Source this script to get started: | ||
6 | |||
7 | ``` | ||
8 | runtime ftplugin/man.vim | ||
9 | ``` | ||
10 | Now, you can open manpages inside vim with `:Man`! It adds nicer syntax highlighting | ||
11 | and the ability to jump around with `Ctrl-]` and `Ctrl-T`. | ||
12 | |||
13 | By default, the manpage is opened in a horizontal split, I prefer using a new tab: | ||
14 | |||
15 | ``` | ||
16 | let g:ft_man_open_mode = 'tab' | ||
17 | ``` | ||
18 | |||
19 | |||
20 | **Scratchpad to test your commands**. I often test my `sed` substitutions, here is | ||
21 | a sample from the script used to generate this site: | ||
22 | |||
23 | ``` | ||
24 | # a substitution to convert snake_case to Title Case With Spaces | ||
25 | echo "$1" | sed -E -e "s/\..+$//g" -e "s/_(.)/ \u\1/g" -e "s/^(.)/\u\1/g" | ||
26 | ``` | ||
27 | Instead of dropping into a new shell, just test it out directly from vim! | ||
28 | |||
29 | - Yank the link into a register: | ||
30 | |||
31 | ``` | ||
32 | yy | ||
33 | ``` | ||
34 | |||
35 | - Paste it into the command-line window: | ||
36 | |||
37 | ``` | ||
38 | q:p | ||
39 | ``` | ||
40 | |||
41 | - Make edits as required: | ||
42 | |||
43 | ``` | ||
44 | syntax off # previously run commands | ||
45 | edit index.html # in a buffer! | ||
46 | w | so % | ||
47 | echo "new_post.md" | sed -E -e "s/\..+$//g" -e "s/_(.)/ \u\1/g" -e "s/^(.)/\u\1/g" | ||
48 | ``` | ||
49 | |||
50 | - Hit enter with the cursor on the line containing your command! | ||
51 | |||
52 | ``` | ||
53 | $ vim | ||
54 | New Post # output | ||
55 | Press ENTER or type command to continue | ||
56 | ``` | ||
57 | |||