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 /posts | |
parent | 502f7102495cf7919b3be67d1bec43a7f3591ee1 (diff) |
new post; bash harder with vim
Diffstat (limited to 'posts')
-rw-r--r-- | posts/bash_harder_with_vim.md | 57 |
1 files changed, 57 insertions, 0 deletions
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 | |||