From be70d338e35209c94ce875734fe483b21f98b5b1 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Wed, 31 Jul 2019 21:19:46 +0530 Subject: new post; bash harder with vim --- posts/bash_harder_with_vim.md | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 posts/bash_harder_with_vim.md (limited to 'posts') 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 @@ +Bash is tricky, dont let your editor get in your way. Here's a couple of neat +addtions you could make to your `vimrc` for a better shell programming +experience. + +**Man pages inside vim**. Source this script to get started: + +``` +runtime ftplugin/man.vim +``` +Now, you can open manpages inside vim with `:Man`! It adds nicer syntax highlighting +and the ability to jump around with `Ctrl-]` and `Ctrl-T`. + +By default, the manpage is opened in a horizontal split, I prefer using a new tab: + +``` +let g:ft_man_open_mode = 'tab' +``` + + +**Scratchpad to test your commands**. I often test my `sed` substitutions, here is +a sample from the script used to generate this site: + +``` +# 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" +``` +Instead of dropping into a new shell, just test it out directly from vim! + + - Yank the link into a register: + + ``` +yy + ``` + + - Paste it into the command-line window: + + ``` +q:p + ``` + + - Make edits as required: + + ``` +syntax off # previously run commands +edit index.html # in a buffer! +w | so % +echo "new_post.md" | sed -E -e "s/\..+$//g" -e "s/_(.)/ \u\1/g" -e "s/^(.)/\u\1/g" + ``` + + - Hit enter with the cursor on the line containing your command! + + ``` +$ vim +New Post # output +Press ENTER or type command to continue + ``` + -- cgit v1.2.3